Index: usr.sbin/daemon/daemon.c =================================================================== --- usr.sbin/daemon/daemon.c +++ usr.sbin/daemon/daemon.c @@ -45,6 +45,8 @@ #include #include +#include + static void dummy_sighandler(int); static void restrict_process(const char *); static int wait_child(pid_t pid, sigset_t *mask); @@ -55,14 +57,15 @@ { struct pidfh *ppfh, *pfh; sigset_t mask, oldmask; - int ch, nochdir, noclose, restart, serrno; - const char *pidfile, *ppidfile, *title, *user; + int ch, nochdir, noclose, restart, serrno, syslog; + const char *pidfile, *ppidfile, *title, *user, *tag, *priority; pid_t otherpid, pid; nochdir = noclose = 1; restart = 0; - ppidfile = pidfile = title = user = NULL; - while ((ch = getopt(argc, argv, "cfp:P:rt:u:")) != -1) { + syslog = 0; + ppidfile = pidfile = user = tag = priority = NULL; + while ((ch = getopt(argc, argv, "cfp:P:ru:t:sh:")) != -1) { switch (ch) { case 'c': nochdir = 0; @@ -70,6 +73,9 @@ case 'f': noclose = 0; break; + case 'h': + priority = optarg; + break; case 'p': pidfile = optarg; break; @@ -79,9 +85,15 @@ case 'r': restart = 1; break; + case 's': + syslog = 1; + break; case 't': title = optarg; break; + case 'T': + tag = optarg; + break; case 'u': user = optarg; break; @@ -94,6 +106,7 @@ if (argc == 0) usage(); + ppfh = pfh = NULL; /* @@ -198,8 +211,42 @@ if (user != NULL) restrict_process(user); + /* Grell's code */ + if(syslog) + { + FILE *fl; + char logger_cmd[200] = "logger"; + char tagstring[200]; + char prioritystring[200]; + + if(tag != NULL){ + snprintf(tagstring, sizeof tagstring, " -t %s", tag); + strncat(logger_cmd, tagstring, 199); + } + + if(priority != NULL){ /* user specifies the facility and priority */ + snprintf(prioritystring, sizeof prioritystring, " -p %s", priority); + strncat(logger_cmd, prioritystring, 199); + } + + fl = popen(logger_cmd,"w"); + if(fl == NULL){ + goto exit; + } + + int nf; + nf = fileno(fl); + dup2(nf,STDOUT_FILENO); + dup2(nf,STDERR_FILENO); + + execvp(argv[0], argv); + } + + /* end Grell's code */ + execvp(argv[0], argv); + /* * execvp() failed -- report the error. The child is * now running, so the exit status doesn't matter. @@ -276,7 +323,7 @@ usage(void) { (void)fprintf(stderr, "%s\n\t%s\n", - "usage: daemon [-cfr] [-p child_pidfile] [-P supervisor_pidfile]", + "usage: daemon [-cfrs] [-h facility.priority] [-p child_pidfile] [-P supervisor_pidfile] [-T custom_tag] ", "[-t title] [-u user] command arguments ..."); exit(1); }