daemon: style changes

This is not a functional change.
- Clean up whitespace (spaces where there should be tabs)
- Break up lines that are longer than 80

Reviewed by:	kevans
Pull Request:	https://github.com/freebsd/freebsd-src/pull/672
This commit is contained in:
Ihor Antonov 2023-03-02 23:17:01 -06:00 committed by Kyle Evans
parent dda4d97289
commit 39ea4280e4

View File

@ -138,7 +138,7 @@ usage(int exitcode)
" --syslog-tag -T <tag> Set syslog tag\n"
" --help -h Show this help\n");
exit(exitcode);
exit(exitcode);
}
int
@ -165,7 +165,7 @@ main(int argc, char *argv[])
.keep_fds_open = 1,
.output_fd = -1,
.output_filename = NULL
};
};
struct pidfh *parent_pidfh = NULL;
struct pidfh *child_pidfh = NULL;
sigset_t mask_orig;
@ -190,17 +190,18 @@ main(int argc, char *argv[])
log_reopen = true;
break;
case 'l':
logparams.syslog_facility = get_log_mapping(optarg, facilitynames);
logparams.syslog_facility = get_log_mapping(optarg,
facilitynames);
if (logparams.syslog_facility == -1) {
errx(5, "unrecognized syslog facility");
}
}
logparams.syslog_enabled = true;
break;
case 'm':
stdmask = strtol(optarg, &p, 10);
if (p == optarg || stdmask < 0 || stdmask > 3) {
errx(6, "unrecognized listening mask");
}
}
break;
case 'o':
logparams.output_filename = optarg;
@ -218,13 +219,14 @@ main(int argc, char *argv[])
restart = strtol(optarg, &p, 0);
if (p == optarg || restart < 1) {
errx(6, "invalid restart delay");
}
}
break;
case 's':
logparams.syslog_priority = get_log_mapping(optarg, prioritynames);
logparams.syslog_priority = get_log_mapping(optarg,
prioritynames);
if (logparams.syslog_priority == -1) {
errx(4, "unrecognized syslog priority");
}
}
logparams.syslog_enabled = true;
break;
case 'S':
@ -240,9 +242,9 @@ main(int argc, char *argv[])
case 'u':
user = optarg;
break;
case 'h':
case 'h':
usage(0);
__builtin_unreachable();
__builtin_unreachable();
default:
usage(1);
}
@ -252,22 +254,23 @@ main(int argc, char *argv[])
if (argc == 0) {
usage(1);
}
}
if (!title) {
title = argv[0];
}
}
if (logparams.output_filename) {
logparams.output_fd = open_log(logparams.output_filename);
if (logparams.output_fd == -1) {
err(7, "open");
}
}
}
if (logparams.syslog_enabled) {
openlog(logparams.syslog_tag, LOG_PID | LOG_NDELAY, logparams.syslog_facility);
}
openlog(logparams.syslog_tag, LOG_PID | LOG_NDELAY,
logparams.syslog_facility);
}
/*
* Try to open the pidfile before calling daemon(3),
@ -359,7 +362,7 @@ main(int argc, char *argv[])
restart:
if (pipe(pfd)) {
err(1, "pipe");
}
}
/*
* Spawn a child to exec the command.
*/
@ -387,7 +390,7 @@ main(int argc, char *argv[])
if (user != NULL) {
restrict_process(user);
}
}
/*
* When forking, the child gets the original sigmask,
* and dup'd pipes.
@ -396,21 +399,21 @@ main(int argc, char *argv[])
close(pfd[0]);
if (sigprocmask(SIG_SETMASK, &mask_orig, NULL)) {
err(1, "sigprogmask");
}
}
if (stdmask & STDERR_FILENO) {
if (dup2(pfd[1], STDERR_FILENO) == -1) {
err(1, "dup2");
}
}
}
if (stdmask & STDOUT_FILENO) {
if (dup2(pfd[1], STDOUT_FILENO) == -1) {
err(1, "dup2");
}
}
}
if (pfd[1] != STDERR_FILENO &&
pfd[1] != STDOUT_FILENO) {
close(pfd[1]);
}
}
}
execvp(argv[0], argv);
/*
@ -471,7 +474,7 @@ main(int argc, char *argv[])
}
if (restart && !terminate) {
daemon_sleep(restart, 0);
}
}
if (sigprocmask(SIG_BLOCK, &mask_term, NULL)) {
warn("sigprocmask");
goto exit;
@ -487,7 +490,7 @@ main(int argc, char *argv[])
close(pfd[1]);
if (logparams.syslog_enabled) {
closelog();
}
}
pidfile_remove(child_pidfh);
pidfile_remove(parent_pidfh);
exit(1); /* If daemon(3) succeeded exit status does not matter. */
@ -501,7 +504,7 @@ daemon_sleep(time_t secs, long nsecs)
while (!terminate && nanosleep(&ts, &ts) == -1) {
if (errno != EINTR) {
err(1, "nanosleep");
}
}
}
}
@ -545,7 +548,7 @@ get_log_mapping(const char *str, const CODE *c)
for (cp = c; cp->c_name; cp++)
if (strcmp(cp->c_name, str) == 0) {
return cp->c_val;
}
}
return -1;
}
@ -557,11 +560,11 @@ restrict_process(const char *user)
pw = getpwnam(user);
if (pw == NULL) {
errx(1, "unknown user: %s", user);
}
}
if (setusercontext(NULL, pw, pw->pw_uid, LOGIN_SETALL) != 0) {
errx(1, "failed to set user environment");
}
}
setenv("USER", pw->pw_name, 1);
setenv("HOME", pw->pw_dir, 1);
@ -587,7 +590,7 @@ listen_child(int fd, struct log_params *logpar)
if (do_log_reopen) {
reopen_log(logpar);
}
}
rv = read(fd, buf + bytes_read, LBUF_SIZE - bytes_read - 1);
if (rv > 0) {
unsigned char *cp;
@ -610,7 +613,7 @@ listen_child(int fd, struct log_params *logpar)
/* Wait until the buffer is full. */
if (bytes_read < LBUF_SIZE - 1) {
return 1;
}
}
do_output(buf, bytes_read, logpar);
bytes_read = 0;
return 1;
@ -644,17 +647,19 @@ do_output(const unsigned char *buf, size_t len, struct log_params *logpar)
if (len < 1) {
return;
}
}
if (logpar->syslog_enabled) {
syslog(logpar->syslog_priority, "%.*s", (int)len, buf);
}
}
if (logpar->output_fd != -1) {
if (write(logpar->output_fd, buf, len) == -1)
warn("write");
}
if (logpar->keep_fds_open && !logpar->syslog_enabled && logpar->output_fd == -1) {
if (logpar->keep_fds_open &&
!logpar->syslog_enabled &&
logpar->output_fd == -1) {
printf("%.*s", (int)len, buf);
}
}
}
/*
@ -666,7 +671,7 @@ handle_term(int signo)
{
if (pid > 0 && !child_gone) {
kill(pid, signo);
}
}
terminate = 1;
}
@ -709,7 +714,7 @@ reopen_log(struct log_params *logparams)
outfd = open_log(logparams->output_filename);
if (logparams->output_fd >= 0) {
close(logparams->output_fd);
}
}
logparams->output_fd = outfd;
}