daemon: make dosyslog variable a bool and give it a better name

Following style(9) and C99 recommendation use bool instead of
int for boolean operations. Also give the variable a more descriptive
name that follows boolean naming convention.

Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/669
This commit is contained in:
Ihor Antonov 2023-03-01 21:00:42 -06:00 committed by Kyle Evans
parent 203df05b69
commit f2f9d31d9f

View File

@ -60,11 +60,11 @@ __FBSDID("$FreeBSD$");
#define LBUF_SIZE 4096 #define LBUF_SIZE 4096
struct log_params { struct log_params {
int dosyslog;
int logpri; int logpri;
int noclose; int noclose;
int outfd; int outfd;
const char *outfn; const char *outfn;
bool syslog_enabled;
}; };
static void restrict_process(const char *); static void restrict_process(const char *);
@ -143,6 +143,7 @@ int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
bool supervision_enabled = false; bool supervision_enabled = false;
bool syslog_enabled = false;
char *p = NULL; char *p = NULL;
const char *pidfile = NULL; const char *pidfile = NULL;
const char *logtag = "daemon"; const char *logtag = "daemon";
@ -152,7 +153,6 @@ main(int argc, char *argv[])
const char *user = NULL; const char *user = NULL;
int ch = 0; int ch = 0;
int child_eof = 0; int child_eof = 0;
int dosyslog = 0;
int log_reopen = 0; int log_reopen = 0;
int logfac = LOG_DAEMON; int logfac = LOG_DAEMON;
int logpri = LOG_NOTICE; int logpri = LOG_NOTICE;
@ -191,7 +191,7 @@ main(int argc, char *argv[])
if (logfac == -1) { if (logfac == -1) {
errx(5, "unrecognized syslog facility"); errx(5, "unrecognized syslog facility");
} }
dosyslog = 1; syslog_enabled = true;
break; break;
case 'm': case 'm':
stdmask = strtol(optarg, &p, 10); stdmask = strtol(optarg, &p, 10);
@ -222,17 +222,17 @@ main(int argc, char *argv[])
if (logpri == -1) { if (logpri == -1) {
errx(4, "unrecognized syslog priority"); errx(4, "unrecognized syslog priority");
} }
dosyslog = 1; syslog_enabled = true;
break; break;
case 'S': case 'S':
dosyslog = 1; syslog_enabled = true;
break; break;
case 't': case 't':
title = optarg; title = optarg;
break; break;
case 'T': case 'T':
logtag = optarg; logtag = optarg;
dosyslog = 1; syslog_enabled = true;
break; break;
case 'u': case 'u':
user = optarg; user = optarg;
@ -262,7 +262,7 @@ main(int argc, char *argv[])
} }
} }
if (dosyslog) { if (syslog_enabled) {
openlog(logtag, LOG_PID | LOG_NDELAY, logfac); openlog(logtag, LOG_PID | LOG_NDELAY, logfac);
} }
@ -299,7 +299,7 @@ main(int argc, char *argv[])
ppidfile != NULL || ppidfile != NULL ||
restart != 0 || restart != 0 ||
outfd != -1 || outfd != -1 ||
dosyslog != 0; syslog_enabled == true;
if (supervision_enabled) { if (supervision_enabled) {
struct sigaction act_term = { 0 }; struct sigaction act_term = { 0 };
@ -349,7 +349,7 @@ main(int argc, char *argv[])
*/ */
(void)madvise(NULL, 0, MADV_PROTECT); (void)madvise(NULL, 0, MADV_PROTECT);
logpar.outfd = outfd; logpar.outfd = outfd;
logpar.dosyslog = dosyslog; logpar.syslog_enabled = syslog_enabled;
logpar.logpri = logpri; logpar.logpri = logpri;
logpar.noclose = noclose; logpar.noclose = noclose;
logpar.outfn = outfn; logpar.outfn = outfn;
@ -487,7 +487,7 @@ main(int argc, char *argv[])
close(outfd); close(outfd);
close(pfd[0]); close(pfd[0]);
close(pfd[1]); close(pfd[1]);
if (dosyslog) { if (syslog_enabled) {
closelog(); closelog();
} }
pidfile_remove(pfh); pidfile_remove(pfh);
@ -647,14 +647,14 @@ do_output(const unsigned char *buf, size_t len, struct log_params *logpar)
if (len < 1) { if (len < 1) {
return; return;
} }
if (logpar->dosyslog) { if (logpar->syslog_enabled) {
syslog(logpar->logpri, "%.*s", (int)len, buf); syslog(logpar->logpri, "%.*s", (int)len, buf);
} }
if (logpar->outfd != -1) { if (logpar->outfd != -1) {
if (write(logpar->outfd, buf, len) == -1) if (write(logpar->outfd, buf, len) == -1)
warn("write"); warn("write");
} }
if (logpar->noclose && !logpar->dosyslog && logpar->outfd == -1) { if (logpar->noclose && !logpar->syslog_enabled && logpar->outfd == -1) {
printf("%.*s", (int)len, buf); printf("%.*s", (int)len, buf);
} }
} }