chiark / gitweb /
server subprocesses should log to the same place the server does
authorRichard Kettlewell <rjk@greenend.org.uk>
Mon, 19 Nov 2007 20:47:24 +0000 (20:47 +0000)
committerRichard Kettlewell <rjk@greenend.org.uk>
Mon, 19 Nov 2007 20:47:24 +0000 (20:47 +0000)
server/deadlock.c
server/normalize.c
server/play.c
server/rescan.c
server/speaker.c
server/stats.c
server/trackdb.c

index 82e796d695a99c982a1fd9ed290055956802bf28..cda6d0d51d47142715fe264ee537ba3f7c38f16c 100644 (file)
@@ -48,6 +48,8 @@ static const struct option options[] = {
   { "config", required_argument, 0, 'c' },
   { "debug", no_argument, 0, 'd' },
   { "no-debug", no_argument, 0, 'D' },
+  { "syslog", no_argument, 0, 's' },
+  { "no-syslog", no_argument, 0, 'S' },
   { 0, 0, 0, 0 }
 };
 
@@ -60,6 +62,7 @@ static void help(void) {
          "  --version, -V           Display version number\n"
          "  --config PATH, -c PATH  Set configuration file\n"
          "  --debug, -d             Turn on debugging\n"
+          "  --[no-]syslog           Force logging\n"
           "\n"
           "Deadlock manager for DisOrder.  Not intended to be run\n"
           "directly.\n");
@@ -75,22 +78,23 @@ static void version(void) {
 }
 
 int main(int argc, char **argv) {
-  int n, err, aborted;
+  int n, err, aborted, logsyslog = !isatty(2);
 
   set_progname(argv);
   if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
-  while((n = getopt_long(argc, argv, "hVc:dD", options, 0)) >= 0) {
+  while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) {
     switch(n) {
     case 'h': help();
     case 'V': version();
     case 'c': configfile = optarg; break;
     case 'd': debugging = 1; break;
     case 'D': debugging = 0; break;
+    case 'S': logsyslog = 0; break;
+    case 's': logsyslog = 1; break;
     default: fatal(0, "invalid option");
     }
   }
-  /* if stderr is a TTY then log there, otherwise to syslog */
-  if(!isatty(2)) {
+  if(logsyslog) {
     openlog(progname, LOG_PID, LOG_DAEMON);
     log_default = &log_syslog;
   }
index f8c7df7f800ff4be791921d94d4ccf9c68e7eb7f..085d4dfb126cc3ff06e9b5f61d4f2417b071a44d 100644 (file)
@@ -28,6 +28,7 @@
 #include <config.h>
 #include "types.h"
 
+#include <getopt.h>
 #include <locale.h>
 #include <errno.h>
 #include <unistd.h>
 #include "log.h"
 #include "configuration.h"
 #include "speaker-protocol.h"
+#include "defs.h"
+
+static const struct option options[] = {
+  { "help", no_argument, 0, 'h' },
+  { "version", no_argument, 0, 'V' },
+  { "config", required_argument, 0, 'c' },
+  { "debug", no_argument, 0, 'd' },
+  { "no-debug", no_argument, 0, 'D' },
+  { "syslog", no_argument, 0, 's' },
+  { "no-syslog", no_argument, 0, 'S' },
+  { 0, 0, 0, 0 }
+};
+
+/* display usage message and terminate */
+static void help(void) {
+  xprintf("Usage:\n"
+         "  disorder-normalize [OPTIONS]\n"
+         "Options:\n"
+         "  --help, -h              Display usage message\n"
+         "  --version, -V           Display version number\n"
+         "  --config PATH, -c PATH  Set configuration file\n"
+         "  --debug, -d             Turn on debugging\n"
+          "  --[no-]syslog           Force logging\n"
+          "\n"
+          "Audio format normalizer for DisOrder.  Not intended to be run\n"
+          "directly.\n");
+  xfclose(stdout);
+  exit(0);
+}
+
+/* display version number and terminate */
+static void version(void) {
+  xprintf("disorder-normalize version %s\n", disorder_version_string);
+  xfclose(stdout);
+  exit(0);
+}
 
 /** @brief Copy bytes from one file descriptor to another
  * @param infd File descriptor read from
@@ -111,17 +148,27 @@ static void soxargs(const char ***pp, char **qq,
 
 int main(int argc, char attribute((unused)) **argv) {
   struct stream_header header, latest_format;
-  int n, p[2], outfd = -1;
+  int n, p[2], outfd = -1, logsyslog = !isatty(2);
   pid_t pid = -1;
 
   set_progname(argv);
   if(!setlocale(LC_CTYPE, ""))
     fatal(errno, "error calling setlocale");
-  if(argc > 1)
-    fatal(0, "not intended to be invoked by users");
+  while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) {
+    switch(n) {
+    case 'h': help();
+    case 'V': version();
+    case 'c': configfile = optarg; break;
+    case 'd': debugging = 1; break;
+    case 'D': debugging = 0; break;
+    case 'S': logsyslog = 0; break;
+    case 's': logsyslog = 1; break;
+    default: fatal(0, "invalid option");
+    }
+  }
   if(config_read(1))
     fatal(0, "cannot read configuration");
-  if(!isatty(2)) {
+  if(logsyslog) {
     openlog(progname, LOG_PID, LOG_DAEMON);
     log_default = &log_syslog;
   }
index 04d7d0117d54f2508560fa3ba1fa0b19e2940827..13854f7a81dd7bfd523dc91d14e52921978b93bd 100644 (file)
@@ -151,10 +151,14 @@ void speaker_setup(ev_source *ev) {
     signal(SIGPIPE, SIG_DFL);
 #if 0
     execlp("valgrind", "valgrind", SPEAKER, "--config", configfile,
-          debugging ? "--debug" : "--no-debug", (char *)0);
+          debugging ? "--debug" : "--no-debug",
+          log_default == &log_syslog ? "--syslog" : "--no-syslog",
+          (char *)0);
 #else
     execlp(SPEAKER, SPEAKER, "--config", configfile,
-          debugging ? "--debug" : "--no-debug", (char *)0);
+          debugging ? "--debug" : "--no-debug",
+          log_default == &log_syslog ? "--syslog" : "--no-syslog",
+          (char *)0);
 #endif
     fatal(errno, "error invoking %s", SPEAKER);
   }
index aaa5f93604bedb26fc35f5f0358d6833c9c4f45b..1c3eb58fbd3a156b70052f9b9e48a99477ddc0f7 100644 (file)
@@ -59,6 +59,8 @@ static const struct option options[] = {
   { "config", required_argument, 0, 'c' },
   { "debug", no_argument, 0, 'd' },
   { "no-debug", no_argument, 0, 'D' },
+  { "syslog", no_argument, 0, 's' },
+  { "no-syslog", no_argument, 0, 'S' },
   { 0, 0, 0, 0 }
 };
 
@@ -71,6 +73,7 @@ static void help(void) {
          "  --version, -V           Display version number\n"
          "  --config PATH, -c PATH  Set configuration file\n"
          "  --debug, -d             Turn on debugging\n"
+          "  --[no-]syslog           Force logging\n"
           "\n"
           "Rescanner for DisOrder.  Not intended to be run\n"
           "directly.\n");
@@ -320,24 +323,25 @@ static void expire_noticed(void) {
 }
 
 int main(int argc, char **argv) {
-  int n;
+  int n, logsyslog = !isatty(2);
   struct sigaction sa;
   
   set_progname(argv);
   mem_init();
   if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
-  while((n = getopt_long(argc, argv, "hVc:dD", options, 0)) >= 0) {
+  while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) {
     switch(n) {
     case 'h': help();
     case 'V': version();
     case 'c': configfile = optarg; break;
     case 'd': debugging = 1; break;
     case 'D': debugging = 0; break;
+    case 'S': logsyslog = 0; break;
+    case 's': logsyslog = 1; break;
     default: fatal(0, "invalid option");
     }
   }
-  /* If stderr is a TTY then log there, otherwise to syslog. */
-  if(!isatty(2)) {
+  if(!logsyslog) {
     openlog(progname, LOG_PID, LOG_DAEMON);
     log_default = &log_syslog;
   }
index bdebbbdd464ae504f7adc34ae7c710696a07c508..55dde7ee9bbf2572da6e317bf9e2ecfb378982cb 100644 (file)
@@ -117,6 +117,8 @@ static const struct option options[] = {
   { "config", required_argument, 0, 'c' },
   { "debug", no_argument, 0, 'd' },
   { "no-debug", no_argument, 0, 'D' },
+  { "syslog", no_argument, 0, 's' },
+  { "no-syslog", no_argument, 0, 'S' },
   { 0, 0, 0, 0 }
 };
 
@@ -129,6 +131,7 @@ static void help(void) {
          "  --version, -V           Display version number\n"
          "  --config PATH, -c PATH  Set configuration file\n"
          "  --debug, -d             Turn on debugging\n"
+          "  --[no-]syslog           Force logging\n"
           "\n"
           "Speaker process for DisOrder.  Not intended to be run\n"
           "directly.\n");
@@ -582,7 +585,7 @@ static void mainloop(void) {
 }
 
 int main(int argc, char **argv) {
-  int n;
+  int n, logsyslog = !isatty(2);
   struct sockaddr_un addr;
   static const int one = 1;
   struct speaker_message sm;
@@ -590,19 +593,20 @@ int main(int argc, char **argv) {
 
   set_progname(argv);
   if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
-  while((n = getopt_long(argc, argv, "hVc:dD", options, 0)) >= 0) {
+  while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) {
     switch(n) {
     case 'h': help();
     case 'V': version();
     case 'c': configfile = optarg; break;
     case 'd': debugging = 1; break;
     case 'D': debugging = 0; break;
+    case 'S': logsyslog = 0; break;
+    case 's': logsyslog = 1; break;
     default: fatal(0, "invalid option");
     }
   }
   if((d = getenv("DISORDER_DEBUG_SPEAKER"))) debugging = atoi(d);
-  /* If stderr is a TTY then log there, otherwise to syslog. */
-  if(!isatty(2)) {
+  if(logsyslog) {
     openlog(progname, LOG_PID, LOG_DAEMON);
     log_default = &log_syslog;
   }
index d125caf8e3ca1b9f6110c3970d20515d71561ed8..d34b0e4764404bdb1873f32dae0b30e942e8ae67 100644 (file)
@@ -26,6 +26,7 @@
 #include <errno.h>
 #include <pcre.h>
 #include <getopt.h>
+#include <syslog.h>
 
 #include "defs.h"
 #include "mem.h"
@@ -40,6 +41,8 @@ static const struct option options[] = {
   { "config", required_argument, 0, 'c' },
   { "debug", no_argument, 0, 'd' },
   { "no-debug", no_argument, 0, 'D' },
+  { "syslog", no_argument, 0, 's' },
+  { "no-syslog", no_argument, 0, 'S' },
   { 0, 0, 0, 0 }
 };
 
@@ -52,6 +55,7 @@ static void help(void) {
          "  --version, -V            Display version number\n"
          "  --config PATH, -c PATH   Set configuration file\n"
          "  --[no-]debug, -d         Turn on (off) debugging\n"
+          "  --[no-]syslog            Force logging\n"
          "\n"
          "Generate DisOrder database statistics.\n");
   xfclose(stdout);
@@ -66,22 +70,28 @@ static void version(void) {
 }
 
 int main(int argc, char **argv) {
-  int n;
+  int n, logsyslog = !isatty(2);
   char **stats;
 
   set_progname(argv);
   mem_init();
   if(!setlocale(LC_CTYPE, "")) fatal(errno, "error calling setlocale");
-  while((n = getopt_long(argc, argv, "hVc:dD", options, 0)) >= 0) {
+  while((n = getopt_long(argc, argv, "hVc:dDSs", options, 0)) >= 0) {
     switch(n) {
     case 'h': help();
     case 'V': version();
     case 'c': configfile = optarg; break;
     case 'd': debugging = 1; break;
     case 'D': debugging = 0; break;
+    case 'S': logsyslog = 0; break;
+    case 's': logsyslog = 1; break;
     default: fatal(0, "invalid option");
     }
   }
+  if(logsyslog) {
+    openlog(progname, LOG_PID, LOG_DAEMON);
+    log_default = &log_syslog;
+  }
   if(config_read(0))
     fatal(0, "cannot read configuration");
   trackdb_init(0);
index 34311ebc27e214053cf4402865df9f1cfc8e98ed..b0eb38333f8d3460ba8e5f605ba492231de218f9 100644 (file)
@@ -182,6 +182,7 @@ static pid_t subprogram(ev_source *ev, const char *prog,
     setpriority(PRIO_PROCESS, 0, 0);
     execlp(prog, prog, "--config", configfile,
            debugging ? "--debug" : "--no-debug",
+           log_default == &log_syslog ? "--syslog" : "--no-syslog",
            (char *)0);
     fatal(errno, "error invoking %s", prog);
   }