diff --git a/apps/backend/backend_main.c b/apps/backend/backend_main.c index 25680a66..2bcc8d21 100644 --- a/apps/backend/backend_main.c +++ b/apps/backend/backend_main.c @@ -1029,13 +1029,13 @@ main(int argc, daemonized errors OK. Before this stage, errors are logged on stderr also */ if (foreground==0){ + clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, + logdst==CLICON_LOG_FILE?CLICON_LOG_FILE:CLICON_LOG_SYSLOG); /* Call plugin callbacks just before fork/daemonization */ if (clixon_plugin_pre_daemon_all(h) < 0) goto done; - clicon_log_init(__PROGRAM__, dbg?LOG_DEBUG:LOG_INFO, - logdst==CLICON_LOG_FILE?CLICON_LOG_FILE:CLICON_LOG_SYSLOG); if (daemon(0, 0) < 0){ - fprintf(stderr, "config: daemon"); + clicon_err(OE_UNIX, errno, "daemon"); exit(-1); } } diff --git a/apps/restconf/restconf_main_native.c b/apps/restconf/restconf_main_native.c index 588c4662..ca6db46b 100644 --- a/apps/restconf/restconf_main_native.c +++ b/apps/restconf/restconf_main_native.c @@ -669,7 +669,7 @@ restconf_clixon_backend(clicon_handle h, while (1){ if (clicon_hello_req(h, "cl:restconf", NULL, &id) < 0){ if (errno == ENOENT){ - fprintf(stderr, "waiting"); + clicon_err(OE_UNIX, errno, "waiting"); sleep(1); continue; } diff --git a/lib/src/clixon_proc.c b/lib/src/clixon_proc.c index 6bceeb11..63b2e1b9 100644 --- a/lib/src/clixon_proc.c +++ b/lib/src/clixon_proc.c @@ -214,18 +214,18 @@ clixon_proc_socket(char **argv, close(sp[0]); close(0); if (dup2(sp[1], STDIN_FILENO) < 0){ - perror("dup2"); + clicon_err(OE_UNIX, errno, "dup2(STDIN)"); return -1; } close(1); if (dup2(sp[1], STDOUT_FILENO) < 0){ - perror("dup2"); + clicon_err(OE_UNIX, errno, "dup2(STDOUT)"); return -1; } close(sp[1]); if (execvp(argv[0], argv) < 0){ - perror("execvp"); + clicon_err(OE_UNIX, errno, "execvp(%s)", argv[0]); return -1; } exit(-1); /* Shouldnt reach here */ @@ -366,7 +366,7 @@ clixon_proc_background(char **argv, goto done; } if (execvp(argv[0], argv) < 0) { - clicon_err(OE_UNIX, errno, "execv(%s)", argv[0]); + clicon_err(OE_UNIX, errno, "execvp(%s)", argv[0]); exit(1); } /* Not reached */ @@ -606,19 +606,19 @@ clixon_process_pid(clicon_handle h, pe = _proc_entry_list; do { - if (strcmp(pe->pe_name, name) == 0) { - isrunning = 0; - if (proc_op_run(pe->pe_pid, &isrunning) < 0) - goto done; + if (strcmp(pe->pe_name, name) == 0) { + isrunning = 0; + if (proc_op_run(pe->pe_pid, &isrunning) < 0) + goto done; - if (!isrunning) - goto done; + if (!isrunning) + goto done; - *pid = pe->pe_pid; - retval = 0; - break; - } - pe = NEXTQ(process_entry_t *, pe); + *pid = pe->pe_pid; + retval = 0; + break; + } + pe = NEXTQ(process_entry_t *, pe); } while (pe != _proc_entry_list); done: @@ -657,45 +657,45 @@ clixon_process_operation(clicon_handle h, goto ok; if ((pe = _proc_entry_list) != NULL) do { - if (strcmp(pe->pe_name, name) == 0){ - /* Call wrapper function that eg changes op1 based on config */ - op = op0; - if (wrapit && pe->pe_callback != NULL) - if (pe->pe_callback(h, pe, &op) < 0) - goto done; - if (op == PROC_OP_START || op == PROC_OP_STOP || op == PROC_OP_RESTART){ - pe->pe_operation = op; - clicon_debug(1, "%s scheduling name: %s pid:%d op: %s", __FUNCTION__, - name, pe->pe_pid, - clicon_int2str(proc_operation_map, pe->pe_operation)); - if (pe->pe_state==PROC_STATE_RUNNING && - (op == PROC_OP_STOP || op == PROC_OP_RESTART)){ - isrunning = 0; - if (proc_op_run(pe->pe_pid, &isrunning) < 0) + if (strcmp(pe->pe_name, name) == 0){ + /* Call wrapper function that eg changes op1 based on config */ + op = op0; + if (wrapit && pe->pe_callback != NULL) + if (pe->pe_callback(h, pe, &op) < 0) goto done; - if (isrunning) { - clicon_log(LOG_NOTICE, "Killing old process %s with pid: %d", - pe->pe_name, pe->pe_pid); /* XXX pid may be 0 */ - kill(pe->pe_pid, SIGTERM); - delay = 1; + if (op == PROC_OP_START || op == PROC_OP_STOP || op == PROC_OP_RESTART){ + pe->pe_operation = op; + clicon_debug(1, "%s scheduling name: %s pid:%d op: %s", __FUNCTION__, + name, pe->pe_pid, + clicon_int2str(proc_operation_map, pe->pe_operation)); + if (pe->pe_state==PROC_STATE_RUNNING && + (op == PROC_OP_STOP || op == PROC_OP_RESTART)){ + isrunning = 0; + if (proc_op_run(pe->pe_pid, &isrunning) < 0) + goto done; + if (isrunning) { + clicon_log(LOG_NOTICE, "Killing old process %s with pid: %d", + pe->pe_name, pe->pe_pid); /* XXX pid may be 0 */ + kill(pe->pe_pid, SIGTERM); + delay = 1; + } + clicon_debug(1, "%s %s(%d) %s --%s--> %s", __FUNCTION__, + pe->pe_name, pe->pe_pid, + clicon_int2str(proc_state_map, pe->pe_state), + clicon_int2str(proc_operation_map, pe->pe_operation), + clicon_int2str(proc_state_map, PROC_STATE_EXITING) + ); + pe->pe_state = PROC_STATE_EXITING; /* Keep operation stop/restart */ } - clicon_debug(1, "%s %s(%d) %s --%s--> %s", __FUNCTION__, - pe->pe_name, pe->pe_pid, - clicon_int2str(proc_state_map, pe->pe_state), - clicon_int2str(proc_operation_map, pe->pe_operation), - clicon_int2str(proc_state_map, PROC_STATE_EXITING) - ); - pe->pe_state = PROC_STATE_EXITING; /* Keep operation stop/restart */ + sched++;/* start: immediate stop/restart: not immediate: wait timeout */ } - sched++;/* start: immediate stop/restart: not immediate: wait timeout */ + else{ + clicon_debug(1, "%s name:%s op %s cancelled by wrap", __FUNCTION__, name, clicon_int2str(proc_operation_map, op0)); + } + break; /* hit break here */ } - else{ - clicon_debug(1, "%s name:%s op %s cancelled by wrap", __FUNCTION__, name, clicon_int2str(proc_operation_map, op0)); - } - break; /* hit break here */ - } - pe = NEXTQ(process_entry_t *, pe); - } while (pe != _proc_entry_list); + pe = NEXTQ(process_entry_t *, pe); + } while (pe != _proc_entry_list); if (sched && clixon_process_sched_register(h, delay) < 0) goto done; ok: diff --git a/lib/src/clixon_uid.c b/lib/src/clixon_uid.c index 7d5a5541..e7869b2f 100644 --- a/lib/src/clixon_uid.c +++ b/lib/src/clixon_uid.c @@ -173,6 +173,8 @@ drop_priv_temp(uid_t new_uid) #ifdef HAVE_GETRESUID int retval = -1; + clicon_debug(CLIXON_DBG_DEFAULT, "%s uid:%u", __FUNCTION__, new_uid); + /* XXX: implicit declaration of function 'setresuid' on travis */ if (setresuid(-1, new_uid, geteuid()) < 0){ clicon_err(OE_UNIX, errno, "setresuid"); @@ -186,7 +188,7 @@ drop_priv_temp(uid_t new_uid) done: return retval; #else - clicon_debug(1, "%s Drop privileges not implemented on this platform since getresuid is not available", __FUNCTION__); + clicon_debug(CLIXON_DBG_DEFAULT, "%s Drop privileges not implemented on this platform since getresuid is not available", __FUNCTION__); return 0; #endif } @@ -203,6 +205,8 @@ drop_priv_perm(uid_t new_uid) uid_t euid; uid_t suid; + clicon_debug(CLIXON_DBG_DEFAULT, "%s uid:%u", __FUNCTION__, new_uid); + if (setresuid(new_uid, new_uid, new_uid) < 0){ clicon_err(OE_UNIX, errno, "setresuid"); goto done; @@ -221,7 +225,7 @@ drop_priv_perm(uid_t new_uid) done: return retval; #else - clicon_debug(1, "%s Drop privileges not implemented on this platform since getresuid is not available", __FUNCTION__); + clicon_debug(CLIXON_DBG_DEFAULT, "%s Drop privileges not implemented on this platform since getresuid is not available", __FUNCTION__); return 0; #endif } @@ -235,7 +239,9 @@ restore_priv(void) uid_t ruid; uid_t euid; uid_t suid; - + + clicon_debug(CLIXON_DBG_DEFAULT, "%s", __FUNCTION__); + if (getresuid(&ruid, &euid, &suid) < 0){ clicon_err(OE_UNIX, errno, "setresuid"); goto done; @@ -252,7 +258,7 @@ restore_priv(void) done: return retval; #else - clicon_debug(1, "%s Drop privileges not implemented on this platform since getresuid is not available", __FUNCTION__); + clicon_debug(CLIXON_DBG_DEFAULT, "%s Drop privileges not implemented on this platform since getresuid is not available", __FUNCTION__); return 0; #endif } diff --git a/util/clixon_util_path.c b/util/clixon_util_path.c index fecf3d6a..d1ca2e0f 100644 --- a/util/clixon_util_path.c +++ b/util/clixon_util_path.c @@ -282,7 +282,7 @@ main(int argc, xc = xvec[i]; fprintf(stdout, "%d: ", i); clixon_xml2file(stdout, xc, 0, 0, NULL, fprintf, 0, 0); - fprintf(stdout, "\n"); + fputc('\n', stdout); fflush(stdout); } retval = 0;