Index: daemon_syslog.c =================================================================== --- daemon_syslog.c +++ daemon_syslog.c @@ -45,6 +45,8 @@ #include #include +#include + static void dummy_sighandler(int); static void restrict_process(const char *); @@ -56,14 +58,15 @@ { struct pidfh *ppfh, *pfh; sigset_t mask, oldmask; - int ch, nochdir, noclose, restart, serrno; - const char *pidfile, *ppidfile, *user; + int ch, nochdir, noclose, restart, serrno, syslog; + const char *pidfile, *ppidfile, *user, *tag, *priority; pid_t otherpid, pid; nochdir = noclose = 1; restart = 0; - ppidfile = pidfile = user = NULL; - while ((ch = getopt(argc, argv, "cfp:P:ru:")) != -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; @@ -71,6 +74,9 @@ case 'f': noclose = 0; break; + case 'h': + priority = optarg; + break; case 'p': pidfile = optarg; break; @@ -80,6 +86,12 @@ case 'r': restart = 1; break; + case 's': + syslog = 1; + break; + case 't': + tag = optarg; + break; case 'u': user = optarg; break; @@ -92,6 +104,7 @@ if (argc == 0) usage(); + ppfh = pfh = NULL; /* @@ -196,8 +209,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. @@ -271,7 +318,7 @@ usage(void) { (void)fprintf(stderr, - "usage: daemon [-cfr] [-p child_pidfile] [-P supervisor_pidfile] " + "usage: daemon [-cfrs] [-h facility.priority] [-p child_pidfile] [-P supervisor_pidfile] [-t custom_tag] " "[-u user]\n command arguments ...\n"); exit(1); }