Fixed again: [backend start resconf failed due to path string truncated #192](https://github.com/clicon/clixon/issues/192)
This commit is contained in:
parent
709459304f
commit
477059f33d
13 changed files with 144 additions and 19 deletions
|
|
@ -59,6 +59,8 @@ Developers may need to change their code
|
||||||
|
|
||||||
### Minor features
|
### Minor features
|
||||||
|
|
||||||
|
* Application specialized error handling for specific error categories
|
||||||
|
* See: https://clixon-docs.readthedocs.io/en/latest/misc.html#specialized-error-handling
|
||||||
* Added several fields to process-control status operation: active, description, command, status, starttime, pid
|
* Added several fields to process-control status operation: active, description, command, status, starttime, pid
|
||||||
* Changed signal handling
|
* Changed signal handling
|
||||||
* Moved clixon-proc sigchild handling from handler to clixon_events
|
* Moved clixon-proc sigchild handling from handler to clixon_events
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,6 @@ See [CHANGELOG.md](CHANGELOG.md) release history.
|
||||||
|
|
||||||
Clixon interaction is best done posting issues, pull requests, or joining the
|
Clixon interaction is best done posting issues, pull requests, or joining the
|
||||||
[slack channel](https://clixondev.slack.com).
|
[slack channel](https://clixondev.slack.com).
|
||||||
[Slack invite](https://join.slack.com/t/clixondev/shared_invite/zt-l36yx3fp-Lmi3qJGQyu5PEC~Zxi2Z5Q) (updated 5/2 2021)
|
[Slack invite](https://join.slack.com/t/clixondev/shared_invite/zt-o8lv7ysk-vcLb7yY9S7XMEklqqVBziQ) (updated 24/3 2021)
|
||||||
|
|
||||||
Clixon is sponsored by [Rubicon Communications LLC(Netgate)](https://www.netgate.com/)
|
Clixon is sponsored by [Rubicon Communications LLC(Netgate)](https://www.netgate.com/)
|
||||||
|
|
|
||||||
|
|
@ -142,6 +142,7 @@ backend_terminate(clicon_handle h)
|
||||||
backend_handle_exit(h); /* Also deletes streams. Cannot use h after this. */
|
backend_handle_exit(h); /* Also deletes streams. Cannot use h after this. */
|
||||||
clixon_event_exit();
|
clixon_event_exit();
|
||||||
clicon_debug(1, "%s done", __FUNCTION__);
|
clicon_debug(1, "%s done", __FUNCTION__);
|
||||||
|
clixon_err_exit();
|
||||||
clicon_log_exit();
|
clicon_log_exit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,6 +112,7 @@ restconf_pseudo_process_control(clicon_handle h)
|
||||||
int i;
|
int i;
|
||||||
int nr;
|
int nr;
|
||||||
cbuf *cb = NULL;
|
cbuf *cb = NULL;
|
||||||
|
cbuf *cbdbg = NULL;
|
||||||
|
|
||||||
nr = 4;
|
nr = 4;
|
||||||
if (clicon_debug_get() != 0)
|
if (clicon_debug_get() != 0)
|
||||||
|
|
@ -134,9 +135,12 @@ restconf_pseudo_process_control(clicon_handle h)
|
||||||
*/
|
*/
|
||||||
if (clicon_debug_get() != 0){
|
if (clicon_debug_get() != 0){
|
||||||
argv[i++] = "-D";
|
argv[i++] = "-D";
|
||||||
cbuf_reset(cb);
|
if ((cbdbg = cbuf_new()) == NULL){ /* Cant use cb since it would overwrite it */
|
||||||
cprintf(cb, "%d", clicon_debug_get());
|
clicon_err(OE_UNIX, errno, "cbuf_new");
|
||||||
argv[i++] = cbuf_get(cb);
|
goto done;
|
||||||
|
}
|
||||||
|
cprintf(cbdbg, "%d", clicon_debug_get());
|
||||||
|
argv[i++] = cbuf_get(cbdbg);
|
||||||
}
|
}
|
||||||
argv[i++] = NULL;
|
argv[i++] = NULL;
|
||||||
assert(i==nr);
|
assert(i==nr);
|
||||||
|
|
@ -152,6 +156,8 @@ restconf_pseudo_process_control(clicon_handle h)
|
||||||
done:
|
done:
|
||||||
if (cb)
|
if (cb)
|
||||||
cbuf_free(cb);
|
cbuf_free(cb);
|
||||||
|
if (cbdbg)
|
||||||
|
cbuf_free(cbdbg);
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,7 @@ cli_terminate(clicon_handle h)
|
||||||
cli_plugin_finish(h);
|
cli_plugin_finish(h);
|
||||||
cli_history_save(h);
|
cli_history_save(h);
|
||||||
cli_handle_exit(h);
|
cli_handle_exit(h);
|
||||||
|
clixon_err_exit();
|
||||||
clicon_log_exit();
|
clicon_log_exit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -598,6 +598,7 @@ netconf_terminate(clicon_handle h)
|
||||||
xpath_optimize_exit();
|
xpath_optimize_exit();
|
||||||
clixon_event_exit();
|
clixon_event_exit();
|
||||||
clicon_handle_exit(h);
|
clicon_handle_exit(h);
|
||||||
|
clixon_err_exit();
|
||||||
clicon_log_exit();
|
clicon_log_exit();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -255,6 +255,7 @@ restconf_terminate(clicon_handle h)
|
||||||
xml_free(x);
|
xml_free(x);
|
||||||
xpath_optimize_exit();
|
xpath_optimize_exit();
|
||||||
restconf_handle_exit(h);
|
restconf_handle_exit(h);
|
||||||
|
clixon_err_exit();
|
||||||
clicon_log_exit();
|
clicon_log_exit();
|
||||||
clicon_debug(1, "%s done", __FUNCTION__);
|
clicon_debug(1, "%s done", __FUNCTION__);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
|
|
@ -70,12 +70,19 @@ enum clicon_err{
|
||||||
OE_SYSLOG, /* syslog error */
|
OE_SYSLOG, /* syslog error */
|
||||||
OE_ROUTING, /* routing daemon error (eg quagga) */
|
OE_ROUTING, /* routing daemon error (eg quagga) */
|
||||||
OE_XML, /* xml parsing etc */
|
OE_XML, /* xml parsing etc */
|
||||||
|
OE_SSL, /* Openssl errors, see eg ssl_get_error */
|
||||||
OE_PLUGIN, /* plugin loading, etc */
|
OE_PLUGIN, /* plugin loading, etc */
|
||||||
OE_YANG , /* Yang error */
|
OE_YANG , /* Yang error */
|
||||||
OE_FATAL, /* Fatal error */
|
OE_FATAL, /* Fatal error */
|
||||||
OE_UNDEF,
|
OE_UNDEF,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Clixon error category log callback
|
||||||
|
* @param[in] handle Application-specific handle
|
||||||
|
* @param[out] cb Read log/error string into this buffer
|
||||||
|
*/
|
||||||
|
typedef int (clixon_cat_log_cb)(void *handle, cbuf *cb);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Variables
|
* Variables
|
||||||
* XXX: should not be global
|
* XXX: should not be global
|
||||||
|
|
@ -101,5 +108,7 @@ int clicon_err_fn(const char *fn, const int line, int category, int err, const
|
||||||
char *clicon_strerror(int err);
|
char *clicon_strerror(int err);
|
||||||
void *clicon_err_save(void);
|
void *clicon_err_save(void);
|
||||||
int clicon_err_restore(void *handle);
|
int clicon_err_restore(void *handle);
|
||||||
|
int clixon_err_cat_reg(enum clicon_err category, void *handle, clixon_cat_log_cb logfn);
|
||||||
|
int clixon_err_exit(void);
|
||||||
|
|
||||||
#endif /* _CLIXON_ERR_H_ */
|
#endif /* _CLIXON_ERR_H_ */
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,10 @@
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
|
/* cligen */
|
||||||
|
#include <cligen/cligen.h>
|
||||||
|
|
||||||
|
/* clixon */
|
||||||
#include "clixon_log.h"
|
#include "clixon_log.h"
|
||||||
#include "clixon_queue.h"
|
#include "clixon_queue.h"
|
||||||
#include "clixon_err.h"
|
#include "clixon_err.h"
|
||||||
|
|
@ -75,11 +79,26 @@ struct err_state{
|
||||||
char es_reason[ERR_STRLEN];
|
char es_reason[ERR_STRLEN];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/* Clixon error category callbacks provides a way to specialize
|
||||||
|
* error handling to something that clixon is not aware of
|
||||||
|
* An example is Openssl BIO I/O abstraction objects, see man BIO_new()
|
||||||
|
*/
|
||||||
|
struct clixon_err_cats {
|
||||||
|
qelem_t cec_qelem; /* List header */
|
||||||
|
enum clicon_err cec_category;
|
||||||
|
void *cec_handle;
|
||||||
|
clixon_cat_log_cb *cec_logfn;
|
||||||
|
};
|
||||||
|
typedef struct clixon_err_cats clixon_err_cats;
|
||||||
|
|
||||||
|
/* Internal global list of category callbacks */
|
||||||
|
static clixon_err_cats *_err_cat_list = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Variables
|
* Variables
|
||||||
*/
|
*/
|
||||||
int clicon_errno = 0; /* See enum clicon_err XXX: hide this and change to err_category */
|
int clicon_errno = 0; /* See enum clicon_err XXX: hide this and change to err_category */
|
||||||
int clicon_suberrno = 0; /* Corresponds to errno.h XXX: change to errno */
|
int clicon_suberrno = 0; /* Corresponds to errno.h XXX: change to errno */
|
||||||
char clicon_err_reason[ERR_STRLEN] = {0, };
|
char clicon_err_reason[ERR_STRLEN] = {0, };
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -97,6 +116,7 @@ static struct errvec EV[] = {
|
||||||
{"Syslog error", OE_SYSLOG},
|
{"Syslog error", OE_SYSLOG},
|
||||||
{"Routing demon error", OE_ROUTING},
|
{"Routing demon error", OE_ROUTING},
|
||||||
{"XML error", OE_XML},
|
{"XML error", OE_XML},
|
||||||
|
{"OpenSSL error", OE_SSL},
|
||||||
{"Plugins", OE_PLUGIN},
|
{"Plugins", OE_PLUGIN},
|
||||||
{"Yang error", OE_YANG},
|
{"Yang error", OE_YANG},
|
||||||
{"FATAL", OE_FATAL},
|
{"FATAL", OE_FATAL},
|
||||||
|
|
@ -129,6 +149,21 @@ clicon_err_reset(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static struct clixon_err_cats *
|
||||||
|
find_category(int category)
|
||||||
|
{
|
||||||
|
clixon_err_cats *cec = NULL;
|
||||||
|
|
||||||
|
if ((cec = _err_cat_list) != NULL){
|
||||||
|
do {
|
||||||
|
if (cec->cec_category == category)
|
||||||
|
break;
|
||||||
|
cec = NEXTQ(clixon_err_cats *, cec);
|
||||||
|
} while (cec && cec != _err_cat_list);
|
||||||
|
}
|
||||||
|
return cec;
|
||||||
|
}
|
||||||
|
|
||||||
/*! Report an error.
|
/*! Report an error.
|
||||||
*
|
*
|
||||||
* Library routines should call this function when an error occurs.
|
* Library routines should call this function when an error occurs.
|
||||||
|
|
@ -142,20 +177,22 @@ clicon_err_reset(void)
|
||||||
* @param[in] line Inline file line number (when called from clicon_err() macro)
|
* @param[in] line Inline file line number (when called from clicon_err() macro)
|
||||||
* @param[in] category Clixon error category, See enum clicon_err
|
* @param[in] category Clixon error category, See enum clicon_err
|
||||||
* @param[in] suberr Error number, typically errno
|
* @param[in] suberr Error number, typically errno
|
||||||
* @param[in] reason Error string, format with argv
|
* @param[in] format Error string, format with argv
|
||||||
* @see clicon_err_reset Reset the global error variables.
|
* @see clicon_err_reset Reset the global error variables.
|
||||||
*/
|
*/
|
||||||
int clicon_err_fn(const char *fn,
|
int
|
||||||
const int line,
|
clicon_err_fn(const char *fn,
|
||||||
int category,
|
const int line,
|
||||||
int suberr,
|
int category,
|
||||||
const char *format, ...)
|
int suberr,
|
||||||
|
const char *format, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
int len;
|
int len;
|
||||||
char *msg = NULL;
|
char *msg = NULL;
|
||||||
int retval = -1;
|
int retval = -1;
|
||||||
|
struct clixon_err_cats *cec;
|
||||||
|
|
||||||
/* Set the global variables */
|
/* Set the global variables */
|
||||||
clicon_errno = category;
|
clicon_errno = category;
|
||||||
clicon_suberrno = suberr;
|
clicon_suberrno = suberr;
|
||||||
|
|
@ -181,8 +218,27 @@ int clicon_err_fn(const char *fn,
|
||||||
va_end(args);
|
va_end(args);
|
||||||
strncpy(clicon_err_reason, msg, ERR_STRLEN-1);
|
strncpy(clicon_err_reason, msg, ERR_STRLEN-1);
|
||||||
|
|
||||||
/* Actually log it */
|
/* Check category callbacks */
|
||||||
if (suberr){
|
if ((cec = find_category(category)) != NULL &&
|
||||||
|
cec->cec_logfn){
|
||||||
|
cbuf *cb = NULL;
|
||||||
|
if ((cb = cbuf_new()) == NULL){
|
||||||
|
fprintf(stderr, "cbuf_new: %s\n", strerror(errno)); /* dont use clicon_err here due to recursion */
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
if (cec->cec_logfn(cec->cec_handle, cb) < 0)
|
||||||
|
goto done;
|
||||||
|
/* Here we could take care of specific errno, like application-defined errors */
|
||||||
|
clicon_log(LOG_ERR, "%s: %d: %s: %s: %s",
|
||||||
|
fn,
|
||||||
|
line,
|
||||||
|
clicon_strerror(category),
|
||||||
|
cbuf_get(cb),
|
||||||
|
msg);
|
||||||
|
if (cb)
|
||||||
|
cbuf_free(cb);
|
||||||
|
}
|
||||||
|
else if (suberr){ /* Actually log it */
|
||||||
/* Here we could take care of specific errno, like application-defined errors */
|
/* Here we could take care of specific errno, like application-defined errors */
|
||||||
clicon_log(LOG_ERR, "%s: %d: %s: %s: %s",
|
clicon_log(LOG_ERR, "%s: %d: %s: %s: %s",
|
||||||
fn,
|
fn,
|
||||||
|
|
@ -197,7 +253,6 @@ int clicon_err_fn(const char *fn,
|
||||||
line,
|
line,
|
||||||
clicon_strerror(category),
|
clicon_strerror(category),
|
||||||
msg);
|
msg);
|
||||||
|
|
||||||
retval = 0;
|
retval = 0;
|
||||||
done:
|
done:
|
||||||
if (msg)
|
if (msg)
|
||||||
|
|
@ -243,3 +298,39 @@ clicon_err_restore(void* handle)
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Register error categories for application-based error handling
|
||||||
|
*
|
||||||
|
* @param[in] category Applies for this category (first arg to clicon_err())
|
||||||
|
* @param[in] logfn Call att error for generating application-defined errstring
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
clixon_err_cat_reg(enum clicon_err category,
|
||||||
|
void *handle,
|
||||||
|
clixon_cat_log_cb logfn)
|
||||||
|
{
|
||||||
|
clixon_err_cats *cec;
|
||||||
|
|
||||||
|
if ((cec = malloc(sizeof *cec)) == NULL){
|
||||||
|
clicon_err(OE_UNIX, errno, "malloc");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
memset(cec, 0, sizeof *cec);
|
||||||
|
cec->cec_category = category;
|
||||||
|
cec->cec_handle = handle;
|
||||||
|
cec->cec_logfn = logfn;
|
||||||
|
INSQ(cec, _err_cat_list);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
clixon_err_exit(void)
|
||||||
|
{
|
||||||
|
clixon_err_cats *cec = NULL;
|
||||||
|
|
||||||
|
while ((cec = _err_cat_list) != NULL){
|
||||||
|
DELQ(cec, _err_cat_list, clixon_err_cats *);
|
||||||
|
free(cec);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,10 @@
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
/* clicon */
|
/* cligen */
|
||||||
|
#include <cligen/cligen.h>
|
||||||
|
|
||||||
|
/* clixon */
|
||||||
#include "clixon_queue.h"
|
#include "clixon_queue.h"
|
||||||
#include "clixon_err.h"
|
#include "clixon_err.h"
|
||||||
#include "clixon_hash.h"
|
#include "clixon_hash.h"
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,10 @@
|
||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
|
|
||||||
|
/* cligen */
|
||||||
|
#include <cligen/cligen.h>
|
||||||
|
|
||||||
|
/* clixon */
|
||||||
#include "clixon_err.h"
|
#include "clixon_err.h"
|
||||||
#include "clixon_log.h"
|
#include "clixon_log.h"
|
||||||
#include "clixon_netns.h"
|
#include "clixon_netns.h"
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,10 @@
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
|
||||||
/* clicon */
|
/* cligen */
|
||||||
|
#include <cligen/cligen.h>
|
||||||
|
|
||||||
|
/* clixon */
|
||||||
#include "clixon_err.h"
|
#include "clixon_err.h"
|
||||||
#include "clixon_log.h"
|
#include "clixon_log.h"
|
||||||
#include "clixon_sig.h"
|
#include "clixon_sig.h"
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,10 @@
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
|
|
||||||
/* clicon */
|
/* cligen */
|
||||||
|
#include <cligen/cligen.h>
|
||||||
|
|
||||||
|
/* clixon */
|
||||||
#include "clixon_err.h"
|
#include "clixon_err.h"
|
||||||
#include "clixon_log.h"
|
#include "clixon_log.h"
|
||||||
#include "clixon_uid.h"
|
#include "clixon_uid.h"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue