From 8bf95cab31d382f84f111bac7d9573c2d9a7c27d Mon Sep 17 00:00:00 2001 From: Olof Hagsand Date: Mon, 18 Jul 2016 16:14:16 +0200 Subject: [PATCH] log debug --- apps/backend/backend_client.c | 19 ++++++++---- apps/cli/cli_common.c | 55 ++++++++++++++++++++++++++++++++--- apps/cli/clixon_cli_api.h | 3 +- lib/src/clixon_log.c | 11 +++++-- lib/src/clixon_proto_client.c | 13 ++++++--- 5 files changed, 84 insertions(+), 17 deletions(-) diff --git a/apps/backend/backend_client.c b/apps/backend/backend_client.c index 7965caa6..a59e3e46 100644 --- a/apps/backend/backend_client.c +++ b/apps/backend/backend_client.c @@ -646,9 +646,9 @@ from_client_call(clicon_handle h, struct clicon_msg *msg, const char *label) { - int retval = -1; - void *reply_data = NULL; - uint16_t reply_data_len = 0; + int retval = -1; + void *reply_data = NULL; + uint16_t reply_data_len = 0; struct clicon_msg_call_req *req; if (clicon_msg_call_decode(msg, &req, label) < 0) { @@ -667,10 +667,17 @@ from_client_call(clicon_handle h, goto done; } - retval = send_msg_reply(s,CLICON_MSG_OK, (char *)reply_data, reply_data_len); - free(reply_data); - + if ((retval = send_msg_reply(s, CLICON_MSG_OK, (char *)reply_data, reply_data_len)) < 0){ + if (errno == ECONNRESET){ /* If cli/netconf dies during plugin downcall */ + clicon_log(LOG_WARNING, "client downcall reset"); + retval = 0; + } + else + goto done; + } done: + if (reply_data) + free(reply_data); return retval; } diff --git a/apps/cli/cli_common.c b/apps/cli/cli_common.c index c4107803..f815b42b 100644 --- a/apps/cli/cli_common.c +++ b/apps/cli/cli_common.c @@ -92,14 +92,16 @@ exit_candidate_db(clicon_handle h) return 0; } -/* - * cli_debug - * set debug level on stderr (not syslog). +#if 1 /* OBSOLETE */ +/*! Set debug level * The level is either what is specified in arg as int argument. * _or_ if a 'level' variable is present in vars use that value instead. + * OBSOLETE */ int -cli_debug(clicon_handle h, cvec *vars, cg_var *arg) +cli_debug(clicon_handle h, + cvec *vars, + cg_var *arg) { cg_var *cv; int level; @@ -115,7 +117,52 @@ cli_debug(clicon_handle h, cvec *vars, cg_var *arg) done: return 0; } +#endif +/*! Set debug level on CLI client (not backend daemon) + * @param[in] h Clicon handle + * @param[in] vars If variable "level" exists, its integer value is used + * @param[in] arg Else use the integer value of argument + * @note The level is either what is specified in arg as int argument. + * _or_ if a 'level' variable is present in vars use that value instead. + */ +int +cli_debug_cli(clicon_handle h, + cvec *vars, + cg_var *arg) +{ + cg_var *cv; + int level; + + if ((cv = cvec_find_var(vars, "level")) == NULL) + cv = arg; + level = cv_int32_get(cv); + /* cli */ + clicon_debug_init(level, NULL); /* 0: dont debug, 1:debug */ + return 0; +} + +/*! Set debug level on backend daemon (not CLI) + * @param[in] h Clicon handle + * @param[in] vars If variable "level" exists, its integer value is used + * @param[in] arg Else use the integer value of argument + * @note The level is either what is specified in arg as int argument. + * _or_ if a 'level' variable is present in vars use that value instead. + */ +int +cli_debug_backend(clicon_handle h, + cvec *vars, + cg_var *arg) +{ + cg_var *cv; + int level; + + if ((cv = cvec_find_var(vars, "level")) == NULL) + cv = arg; + level = cv_int32_get(cv); + /* config daemon */ + return clicon_rpc_debug(h, level); +} void cli_signal_block(clicon_handle h) diff --git a/apps/cli/clixon_cli_api.h b/apps/cli/clixon_cli_api.h index 50ca7919..5042cfbd 100644 --- a/apps/cli/clixon_cli_api.h +++ b/apps/cli/clixon_cli_api.h @@ -61,7 +61,8 @@ int exit_candidate_db(clicon_handle h); int cli_set (clicon_handle h, cvec *vars, cg_var *arg); int cli_merge (clicon_handle h, cvec *vars, cg_var *arg); int cli_del(clicon_handle h, cvec *vars, cg_var *argv); -int cli_debug(clicon_handle h, cvec *vars, cg_var *argv); +int cli_debug_cli(clicon_handle h, cvec *vars, cg_var *argv); +int cli_debug_backend(clicon_handle h, cvec *vars, cg_var *argv); int cli_record(clicon_handle h, cvec *vars, cg_var *argv); int isrecording(void); int record_command(char *str); diff --git a/lib/src/clixon_log.c b/lib/src/clixon_log.c index 09eb9ecb..03bfcf85 100644 --- a/lib/src/clixon_log.c +++ b/lib/src/clixon_log.c @@ -138,10 +138,11 @@ slogtime(void) } -/*! Make a logging call to syslog. +/*! Make a logging call to syslog (or stderr). * * This is the _only_ place the actual syslog (or stderr) logging is made in clicon,.. - * See also clicon_log() + * @note yslog makes itw own filtering, but if log to stderr we do it here + * @see clicon_debug() * * @param[in] level log level, eg LOG_DEBUG,LOG_INFO,...,LOG_EMERG. Thisis OR:d with facility == LOG_USER * @param[in] msg Message to print as argv. @@ -152,6 +153,11 @@ clicon_log_str(int level, { if (_logflags & CLICON_LOG_SYSLOG) syslog(LOG_MAKEPRI(LOG_USER, level), "%s", msg); + /* syslog makes own filtering, we do it here: + * if normal (not debug) then filter loglevels >= debug + */ + if (debug == 0 && level >= LOG_DEBUG) + goto done; if (_logflags & CLICON_LOG_STDERR){ flogtime(stderr); fprintf(stderr, "%s\n", msg); @@ -184,6 +190,7 @@ clicon_log_str(int level, } cb--; } + done: return 0; } diff --git a/lib/src/clixon_proto_client.c b/lib/src/clixon_proto_client.c index 964396a4..e9a38684 100644 --- a/lib/src/clixon_proto_client.c +++ b/lib/src/clixon_proto_client.c @@ -388,10 +388,15 @@ downcall(clicon_handle h, uint16_t op, uint16_t len, void *arg, * unchunk_group(label) to deallocate */ int -clicon_rpc_call(clicon_handle h, uint16_t op, char *plugin, char *func, - void *param, uint16_t paramlen, - char **ret, uint16_t *retlen, - const void *label) +clicon_rpc_call(clicon_handle h, + uint16_t op, + char *plugin, + char *func, + void *param, + uint16_t paramlen, + char **ret, + uint16_t *retlen, + const void *label) { int retval = -1; struct clicon_msg *msg;