From 0ca6d097e900ff5d46ffc4968a468fefecb345af Mon Sep 17 00:00:00 2001 Message-Id: <0ca6d097e900ff5d46ffc4968a468fefecb345af.1714974840.git.mdw@distorted.org.uk> From: Mark Wooding Date: Mon, 19 Nov 2007 20:47:24 +0000 Subject: [PATCH] server subprocesses should log to the same place the server does Organization: Straylight/Edgeware From: Richard Kettlewell --- server/deadlock.c | 12 ++++++---- server/normalize.c | 55 ++++++++++++++++++++++++++++++++++++++++++---- server/play.c | 8 +++++-- server/rescan.c | 12 ++++++---- server/speaker.c | 12 ++++++---- server/stats.c | 14 ++++++++++-- server/trackdb.c | 1 + 7 files changed, 94 insertions(+), 20 deletions(-) diff --git a/server/deadlock.c b/server/deadlock.c index 82e796d..cda6d0d 100644 --- a/server/deadlock.c +++ b/server/deadlock.c @@ -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; } diff --git a/server/normalize.c b/server/normalize.c index f8c7df7..085d4df 100644 --- a/server/normalize.c +++ b/server/normalize.c @@ -28,6 +28,7 @@ #include #include "types.h" +#include #include #include #include @@ -40,6 +41,42 @@ #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; } diff --git a/server/play.c b/server/play.c index 04d7d01..13854f7 100644 --- a/server/play.c +++ b/server/play.c @@ -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); } diff --git a/server/rescan.c b/server/rescan.c index aaa5f93..1c3eb58 100644 --- a/server/rescan.c +++ b/server/rescan.c @@ -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; } diff --git a/server/speaker.c b/server/speaker.c index bdebbbd..55dde7e 100644 --- a/server/speaker.c +++ b/server/speaker.c @@ -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; } diff --git a/server/stats.c b/server/stats.c index d125caf..d34b0e4 100644 --- a/server/stats.c +++ b/server/stats.c @@ -26,6 +26,7 @@ #include #include #include +#include #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); diff --git a/server/trackdb.c b/server/trackdb.c index 34311eb..b0eb383 100644 --- a/server/trackdb.c +++ b/server/trackdb.c @@ -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); } -- [mdw]