diff --git a/usr.sbin/daemon/daemon.c b/usr.sbin/daemon/daemon.c --- a/usr.sbin/daemon/daemon.c +++ b/usr.sbin/daemon/daemon.c @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -82,6 +83,27 @@ static volatile sig_atomic_t terminate = 0, child_gone = 0, pid = 0, do_log_reopen = 0; +static char shortopts[] = "+cfHSp:P:ru:o:s:l:t:l:m:R:T:"; + +static struct option longopts[] = { + { "change-dir", no_argument, NULL, 'c' }, + { "close-fds", no_argument, NULL, 'f' }, + { "sighup", no_argument, NULL, 'H' }, + { "syslog", no_argument, NULL, 'S' }, + { "output-file", required_argument, NULL, 'o' }, + { "output-mask", required_argument, NULL, 'm' }, + { "child-pidfile", required_argument, NULL, 'p' }, + { "supervisor-pidfile", required_argument, NULL, 'P' }, + { "restart", no_argument, NULL, 'r' }, + { "restart-delay", required_argument, NULL, 'R' }, + { "title", required_argument, NULL, 't' }, + { "user", required_argument, NULL, 'u' }, + { "syslog-priority", required_argument, NULL, 's' }, + { "syslog-facility", required_argument, NULL, 'l' }, + { "syslog-tag", required_argument, NULL, 'T' }, + { NULL, 0, NULL, 0 } +}; + int main(int argc, char *argv[]) { @@ -92,6 +114,7 @@ int pfd[2] = { -1, -1 }, outfd = -1; int stdmask, logpri, logfac, log_reopen; struct pidfh *ppfh, *pfh; + ppfh = pfh = NULL; char *p; memset(&logpar, 0, sizeof(logpar)); @@ -106,7 +129,7 @@ log_reopen = 0; outfn = NULL; title = NULL; - while ((ch = getopt(argc, argv, "cfHSp:P:ru:o:s:l:t:l:m:R:T:")) != -1) { + while ((ch = getopt_long(argc, argv, shortopts, longopts, NULL)) != -1) { switch (ch) { case 'c': nochdir = 0; @@ -182,11 +205,10 @@ if (outfd == -1) err(7, "open"); } - + if (dosyslog) openlog(logtag, LOG_PID | LOG_NDELAY, logfac); - ppfh = pfh = NULL; /* * Try to open the pidfile before calling daemon(3), * to be able to report the error intelligently