Use clicon_err() consistently and drop perror()

This commit is contained in:
Philip Prindeville 2023-08-23 13:48:04 -06:00 committed by Olof Hagsand
parent 9d9528d503
commit 959e060995
5 changed files with 65 additions and 59 deletions

View file

@ -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);
}
}

View file

@ -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;
}

View file

@ -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 */

View file

@ -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
}
@ -236,6 +240,8 @@ restore_priv(void)
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
}

View file

@ -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;