Restructured error,debug anf log API
Renamed functions clicon->clixon, replaced global variables w access functions Unified clicon_netconf_error with clixon_err()
This commit is contained in:
parent
261469be16
commit
24a4991ec8
199 changed files with 4668 additions and 4158 deletions
|
|
@ -71,7 +71,7 @@
|
|||
/* cligen */
|
||||
#include <cligen/cligen.h>
|
||||
|
||||
/* clicon */
|
||||
/* clixon */
|
||||
#include <clixon/clixon.h>
|
||||
|
||||
#include <fcgiapp.h> /* Need to be after clixon_xml.h due to attribute format */
|
||||
|
|
@ -99,7 +99,7 @@
|
|||
* @see https://nginx.org/en/docs/http/ngx_http_core_module.html#var_https
|
||||
*/
|
||||
static int
|
||||
fcgi_params_set(clicon_handle h,
|
||||
fcgi_params_set(clixon_handle h,
|
||||
char **envp)
|
||||
{
|
||||
int retval = -1;
|
||||
|
|
@ -131,7 +131,7 @@ fcgi_params_set(clicon_handle h,
|
|||
/*! Try to get config: inline, config-file or query backend
|
||||
*/
|
||||
static int
|
||||
restconf_main_config(clicon_handle h,
|
||||
restconf_main_config(clixon_handle h,
|
||||
yang_stmt *yspec,
|
||||
const char *inline_config)
|
||||
{
|
||||
|
|
@ -151,7 +151,12 @@ restconf_main_config(clicon_handle h,
|
|||
if ((ret = clixon_xml_parse_string(inline_config, YB_MODULE, yspec, &xrestconf, &xerr)) < 0)
|
||||
goto done;
|
||||
if (ret == 0){
|
||||
#if 1
|
||||
if (clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Inline restconf config") < 0)
|
||||
goto done;
|
||||
#else
|
||||
clixon_netconf_error(h, xerr, "Inline restconf config", NULL);
|
||||
#endif
|
||||
goto done;
|
||||
}
|
||||
/* Replace parent w first child */
|
||||
|
|
@ -172,7 +177,7 @@ restconf_main_config(clicon_handle h,
|
|||
sleep(1);
|
||||
continue;
|
||||
}
|
||||
clicon_err(OE_UNIX, errno, "clicon_session_id_get");
|
||||
clixon_err(OE_UNIX, errno, "clicon_session_id_get");
|
||||
goto done;
|
||||
}
|
||||
clicon_session_id_set(h, id);
|
||||
|
|
@ -181,13 +186,13 @@ restconf_main_config(clicon_handle h,
|
|||
if ((nsc = xml_nsctx_init(NULL, CLIXON_RESTCONF_NS)) == NULL)
|
||||
goto done;
|
||||
if ((pw = getpwuid(getuid())) == NULL){
|
||||
clicon_err(OE_UNIX, errno, "getpwuid");
|
||||
clixon_err(OE_UNIX, errno, "getpwuid");
|
||||
goto done;
|
||||
}
|
||||
if (clicon_rpc_get_config(h, pw->pw_name, "running", "/restconf", nsc, NULL, &xconfig) < 0)
|
||||
goto done;
|
||||
if ((xerr = xpath_first(xconfig, NULL, "/rpc-error")) != NULL){
|
||||
clixon_netconf_error(h, xerr, "Get backend restconf config", NULL);
|
||||
clixon_err_netconf(h, OE_NETCONF, 0, xerr, "Get backend restconf config");
|
||||
goto done;
|
||||
}
|
||||
/* Extract restconf configuration */
|
||||
|
|
@ -198,7 +203,7 @@ restconf_main_config(clicon_handle h,
|
|||
(configure_done = restconf_config_init(h, xrestconf)) < 0)
|
||||
goto done;
|
||||
if (!configure_done){ /* Query backend of config. */
|
||||
clicon_err(OE_DAEMON, EFAULT, "Restconf daemon config not found or disabled");
|
||||
clixon_err(OE_DAEMON, EFAULT, "Restconf daemon config not found or disabled");
|
||||
goto done;
|
||||
}
|
||||
retval = 0;
|
||||
|
|
@ -214,7 +219,7 @@ restconf_main_config(clicon_handle h,
|
|||
|
||||
/* XXX Need global variable to for SIGCHLD signal handler
|
||||
*/
|
||||
static clicon_handle _CLICON_HANDLE = NULL;
|
||||
static clixon_handle _CLIXON_HANDLE = NULL;
|
||||
|
||||
/* XXX Need global variable to break FCGI accept loop from signal handler see FCGX_Accept_r(req)
|
||||
*/
|
||||
|
|
@ -229,7 +234,7 @@ restconf_sig_term(int arg)
|
|||
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__);
|
||||
if (i++ == 0)
|
||||
clicon_log(LOG_NOTICE, "%s: %s: pid: %u Signal %d",
|
||||
clixon_log(NULL, LOG_NOTICE, "%s: %s: pid: %u Signal %d",
|
||||
__PROGRAM__, __FUNCTION__, getpid(), arg);
|
||||
else{
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "%s done", __FUNCTION__);
|
||||
|
|
@ -255,7 +260,7 @@ restconf_sig_child(int arg)
|
|||
int pid;
|
||||
|
||||
if ((pid = waitpid(-1, &status, 0)) != -1 && WIFEXITED(status))
|
||||
stream_child_free(_CLICON_HANDLE, pid);
|
||||
stream_child_free(_CLIXON_HANDLE, pid);
|
||||
}
|
||||
|
||||
/*! Usage help routine
|
||||
|
|
@ -264,7 +269,7 @@ restconf_sig_child(int arg)
|
|||
* @param[in] argv0 command line
|
||||
*/
|
||||
static void
|
||||
usage(clicon_handle h,
|
||||
usage(clixon_handle h,
|
||||
char *argv0)
|
||||
{
|
||||
fprintf(stderr, "usage:%s [options]\n"
|
||||
|
|
@ -303,9 +308,9 @@ main(int argc,
|
|||
int c;
|
||||
char *sockpath = NULL;
|
||||
char *path;
|
||||
clicon_handle h;
|
||||
clixon_handle h;
|
||||
char *dir;
|
||||
int logdst = CLICON_LOG_SYSLOG;
|
||||
int logdst = CLIXON_LOG_SYSLOG;
|
||||
yang_stmt *yspec = NULL;
|
||||
char *query;
|
||||
cvec *qvec;
|
||||
|
|
@ -324,14 +329,16 @@ main(int argc,
|
|||
enum format_enum config_dump_format = FORMAT_XML;
|
||||
int print_version = 0;
|
||||
|
||||
/* In the startup, logs to stderr & debug flag set later */
|
||||
clicon_log_init(__PROGRAM__, LOG_INFO, logdst);
|
||||
|
||||
/* Create handle */
|
||||
if ((h = restconf_handle_init()) == NULL)
|
||||
goto done;
|
||||
/* In the startup, logs to stderr & debug flag set later */
|
||||
if (clixon_log_init(h, __PROGRAM__, LOG_INFO, logdst) < 0)
|
||||
goto done;
|
||||
if (clixon_err_init(h) < 0)
|
||||
goto done;
|
||||
|
||||
_CLICON_HANDLE = h; /* for termination handling */
|
||||
_CLIXON_HANDLE = h; /* for termination handling */
|
||||
|
||||
while ((c = getopt(argc, argv, RESTCONF_OPTS)) != -1)
|
||||
switch (c) {
|
||||
|
|
@ -357,11 +364,11 @@ main(int argc,
|
|||
clicon_option_str_set(h, "CLICON_CONFIGDIR", optarg);
|
||||
break;
|
||||
case 'l': /* Log destination: s|e|o */
|
||||
if ((logdst = clicon_log_opt(optarg[0])) < 0)
|
||||
if ((logdst = clixon_log_opt(optarg[0])) < 0)
|
||||
usage(h, argv[0]);
|
||||
if (logdst == CLICON_LOG_FILE &&
|
||||
if (logdst == CLIXON_LOG_FILE &&
|
||||
strlen(optarg)>1 &&
|
||||
clicon_log_file(optarg+1) < 0)
|
||||
clixon_log_file(optarg+1) < 0)
|
||||
goto done;
|
||||
break;
|
||||
} /* switch getopt */
|
||||
|
|
@ -369,20 +376,20 @@ main(int argc,
|
|||
/*
|
||||
* Logs, error and debug to stderr or syslog, set debug level
|
||||
*/
|
||||
clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
|
||||
clixon_log_init(h, __PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, logdst);
|
||||
|
||||
clixon_debug_init(dbg, NULL);
|
||||
clicon_log(LOG_NOTICE, "%s fcgi: %u Started", __PROGRAM__, getpid());
|
||||
clixon_debug_init(h, dbg);
|
||||
clixon_log(h, LOG_NOTICE, "%s fcgi: %u Started", __PROGRAM__, getpid());
|
||||
if (set_signal(SIGTERM, restconf_sig_term, NULL) < 0){
|
||||
clicon_err(OE_DAEMON, errno, "Setting signal");
|
||||
clixon_err(OE_DAEMON, errno, "Setting signal");
|
||||
goto done;
|
||||
}
|
||||
if (set_signal(SIGINT, restconf_sig_term, NULL) < 0){
|
||||
clicon_err(OE_DAEMON, errno, "Setting signal");
|
||||
clixon_err(OE_DAEMON, errno, "Setting signal");
|
||||
goto done;
|
||||
}
|
||||
if (set_signal(SIGCHLD, restconf_sig_child, NULL) < 0){
|
||||
clicon_err(OE_DAEMON, errno, "Setting signal");
|
||||
clixon_err(OE_DAEMON, errno, "Setting signal");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -460,8 +467,8 @@ main(int argc,
|
|||
cligen_bufthreshold = clicon_option_int(h, "CLICON_CLI_BUF_THRESHOLD");
|
||||
cbuf_alloc_set(cligen_buflen, cligen_bufthreshold);
|
||||
|
||||
if ((sz = clicon_option_int(h, "CLICON_LOG_STRING_LIMIT")) != 0)
|
||||
clicon_log_string_limit_set(sz);
|
||||
if ((sz = clicon_option_int(h, "CLIXON_LOG_STRING_LIMIT")) != 0)
|
||||
clixon_log_string_limit_set(sz);
|
||||
|
||||
/* Set default namespace according to CLICON_NAMESPACE_NETCONF_DEFAULT */
|
||||
xml_nsctx_namespace_netconf_default(h);
|
||||
|
|
@ -572,16 +579,16 @@ main(int argc,
|
|||
if (restconf_main_config(h, yspec, inline_config) < 0)
|
||||
goto done;
|
||||
if ((sockpath = restconf_fcgi_socket_get(h)) == NULL){
|
||||
clicon_err(OE_CFG, 0, "No restconf fcgi-socket (have you set FEATURE fcgi in config?)");
|
||||
clixon_err(OE_CFG, 0, "No restconf fcgi-socket (have you set FEATURE fcgi in config?)");
|
||||
goto done;
|
||||
}
|
||||
if (FCGX_Init() != 0){ /* How to cleanup memory after this? */
|
||||
clicon_err(OE_CFG, errno, "FCGX_Init");
|
||||
clixon_err(OE_CFG, errno, "FCGX_Init");
|
||||
goto done;
|
||||
}
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "restconf_main: Opening FCGX socket: %s", sockpath);
|
||||
if ((sock = FCGX_OpenSocket(sockpath, 10)) < 0){
|
||||
clicon_err(OE_CFG, errno, "FCGX_OpenSocket");
|
||||
clixon_err(OE_CFG, errno, "FCGX_OpenSocket");
|
||||
goto done;
|
||||
}
|
||||
_MYSOCK = sock;
|
||||
|
|
@ -590,18 +597,18 @@ main(int argc,
|
|||
gid_t wgid = -1;
|
||||
wwwuser = clicon_option_str(h, "CLICON_RESTCONF_USER");
|
||||
if (group_name2gid(wwwuser, &wgid) < 0){
|
||||
clicon_log(LOG_ERR, "'%s' does not seem to be a valid user group.", wwwuser);
|
||||
clixon_log(h, LOG_ERR, "'%s' does not seem to be a valid user group.", wwwuser);
|
||||
goto done;
|
||||
}
|
||||
if (chown(sockpath, -1, wgid) < 0){
|
||||
clicon_err(OE_CFG, errno, "chown");
|
||||
clixon_err(OE_CFG, errno, "chown");
|
||||
goto done;
|
||||
}
|
||||
if (clicon_socket_set(h, sock) < 0)
|
||||
goto done;
|
||||
/* umask settings may interfer: we want group to write: this is 774 */
|
||||
if (chmod(sockpath, S_IRWXU|S_IRWXG|S_IROTH) < 0){
|
||||
clicon_err(OE_UNIX, errno, "chmod");
|
||||
clixon_err(OE_UNIX, errno, "chmod");
|
||||
goto done;
|
||||
}
|
||||
|
||||
|
|
@ -616,14 +623,14 @@ main(int argc,
|
|||
clicon_data_set(h, "session-transport", "cl:restconf");
|
||||
|
||||
if (FCGX_InitRequest(req, sock, 0) != 0){
|
||||
clicon_err(OE_CFG, errno, "FCGX_InitRequest");
|
||||
clixon_err(OE_CFG, errno, "FCGX_InitRequest");
|
||||
goto done;
|
||||
}
|
||||
while (1) {
|
||||
finish = 1; /* If zero, dont finish request, initiate new */
|
||||
|
||||
if (FCGX_Accept_r(req) < 0) {
|
||||
clicon_err(OE_CFG, errno, "FCGX_Accept_r");
|
||||
clixon_err(OE_CFG, errno, "FCGX_Accept_r");
|
||||
goto done;
|
||||
}
|
||||
clixon_debug(CLIXON_DBG_DEFAULT, "------------");
|
||||
|
|
@ -692,7 +699,7 @@ main(int argc,
|
|||
else{ /* A handler is forked so we initiate a new request after instead
|
||||
of finishing the old */
|
||||
if (FCGX_InitRequest(req, sock, 0) != 0){
|
||||
clicon_err(OE_CFG, errno, "FCGX_InitRequest");
|
||||
clixon_err(OE_CFG, errno, "FCGX_InitRequest");
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue