log UPDATE add server init check
diff --git a/src/log_p.h b/src/log_p.h
index c4f6c9e..47fa7fe 100644
--- a/src/log_p.h
+++ b/src/log_p.h
@@ -49,10 +49,11 @@
#define DBL(session, ...) if(ATOMIC_LOAD_RELAXED(verbose_level)>=NC_VERB_DEBUG_LOWLVL){prv_printf(session, NC_VERB_DEBUG_LOWLVL, __VA_ARGS__);}
#define ERRMEM ERR(NULL, "%s: memory reallocation failed (%s:%d).", __func__, __FILE__, __LINE__)
-#define ERRINIT ERR(NULL, "%s: libnetconf2 not initialized.", __func__)
+#define ERRINITSRV ERR(NULL, "%s: server not initialized.", __func__)
#define ERRINT ERR(NULL, "%s: internal error (%s:%d).", __func__, __FILE__, __LINE__)
#define ERRARG(session, ARG) ERR(session, "Invalid argument %s (%s()).", #ARG, __func__)
+#define NC_CHECK_SRV_INIT_RET(RET) if (!ATOMIC_LOAD_RELAXED(server_opts.new_session_id)) {ERRINITSRV; return (RET);}
#define NC_CHECK_ERRMEM_RET(COND, RET) if ((COND)) {ERRMEM; return (RET);}
#define NC_CHECK_ERRMEM_GOTO(COND, RET, GOTO) if ((COND)) {ERRMEM; RET; goto GOTO;}
diff --git a/src/session_client.c b/src/session_client.c
index f195c54..1f1a7a4 100644
--- a/src/session_client.c
+++ b/src/session_client.c
@@ -1825,7 +1825,7 @@
NC_CHECK_ARG_RET(NULL, session, -1);
if (!client_opts.ch_binds) {
- ERRINIT;
+ ERR(NULL, "Call-Home binds not set.");
return -1;
}
diff --git a/src/session_client_tls.c b/src/session_client_tls.c
index bf5dcdb..d33778f 100644
--- a/src/session_client_tls.c
+++ b/src/session_client_tls.c
@@ -528,8 +528,11 @@
struct timespec ts_timeout;
char *ip_host = NULL;
- if (!tls_opts.cert_path || (!tls_opts.ca_file && !tls_opts.ca_dir)) {
- ERRINIT;
+ if (!tls_opts.cert_path) {
+ ERR(NULL, "Client certificate not set.");
+ return NULL;
+ } else if (!tls_opts.ca_file && !tls_opts.ca_dir) {
+ ERR(NULL, "Certificate authority certificates not set.");
return NULL;
}
diff --git a/src/session_server.c b/src/session_server.c
index 7eb38a8..e2b6f48 100644
--- a/src/session_server.c
+++ b/src/session_server.c
@@ -790,8 +790,8 @@
pthread_rwlockattr_t attr, *attr_p = NULL;
int r;
- server_opts.new_session_id = 1;
- server_opts.new_client_id = 1;
+ ATOMIC_STORE_RELAXED(server_opts.new_session_id, 1);
+ ATOMIC_STORE_RELAXED(server_opts.new_client_id, 1);
#ifdef HAVE_PTHREAD_RWLOCKATTR_SETKIND_NP
if ((r = pthread_rwlockattr_init(&attr))) {
@@ -950,15 +950,9 @@
NC_MSG_TYPE msgtype;
struct timespec ts_cur;
- NC_CHECK_ARG_RET(NULL, ctx, username, session, NC_MSG_ERROR);
+ NC_CHECK_ARG_RET(NULL, ctx, username, fdin >= 0, fdout >= 0, session, NC_MSG_ERROR);
- if (fdin < 0) {
- ERRARG(NULL, "fdin");
- return NC_MSG_ERROR;
- } else if (fdout < 0) {
- ERRARG(NULL, "fdout");
- return NC_MSG_ERROR;
- }
+ NC_CHECK_SRV_INIT_RET(NC_MSG_ERROR);
/* init ctx as needed */
nc_server_init_cb_ctx(ctx);
@@ -2256,6 +2250,10 @@
NC_CHECK_ARG_RET(NULL, ctx, session, NC_MSG_ERROR);
+ NC_CHECK_SRV_INIT_RET(NC_MSG_ERROR);
+
+ *session = NULL;
+
/* init ctx as needed */
nc_server_init_cb_ctx(ctx);
@@ -2917,6 +2915,8 @@
NC_CHECK_ARG_RET(NULL, client_name, acquire_ctx_cb, release_ctx_cb, new_session_cb, -1);
+ NC_CHECK_SRV_INIT_RET(-1);
+
/* LOCK */
ch_client = nc_server_ch_client_lock(client_name);
if (!ch_client) {