From: Mike Brady Date: Sat, 16 Feb 2019 19:32:13 +0000 (+0000) Subject: Add a new command line option: -u to send logs to STDERR. X-Git-Tag: 3.3RC0~58^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fce6b5137ee81862964aa5b62d52c809ef930291;p=thirdparty%2Fshairport-sync.git Add a new command line option: -u to send logs to STDERR. --- diff --git a/common.c b/common.c index 6bd31524..cf5c0730 100644 --- a/common.c +++ b/common.c @@ -91,6 +91,28 @@ void set_alsa_out_dev(char *); static volatile int requested_connection_state_to_output = 1; +// this stuff is to direct logging to syslog via libdaemon or directly +// alternatively you can direct it to stderr using a command line option + +#ifdef CONFIG_LIBDAEMON +static void (*sps_log)(int prio, const char *t, ...) = daemon_log; +#else +static void (*sps_log)(int prio, const char *t, ...) = syslog; +#endif + +void do_sps_log(__attribute__((unused)) int prio, const char *t, ...) { + char s[1024]; + va_list args; + va_start(args, t); + vsnprintf(s, sizeof(s), t, args); + va_end(args); + fprintf(stderr,"%s\n",s); +} + +void log_to_stderr() { + sps_log = do_sps_log; +} + shairport_cfg config; volatile int debuglev = 0; @@ -146,24 +168,13 @@ void die(const char *format, ...) { va_end(args); if ((debuglev) && (config.debugger_show_elapsed_time) && (config.debugger_show_relative_time)) - - #ifdef CONFIG_LIBDAEMON - daemon_log(LOG_ERR, "|% 20.9f|% 20.9f|*fatal error: %s", tss, tsl, s); - else if ((debuglev) && (config.debugger_show_relative_time)) - daemon_log(LOG_ERR, "% 20.9f|*fatal error: %s", tsl, s); - else if ((debuglev) && (config.debugger_show_elapsed_time)) - daemon_log(LOG_ERR, "% 20.9f|*fatal error: %s", tss, s); - else - daemon_log(LOG_ERR, "fatal error: %s", s); - #else - syslog(LOG_ERR, "|% 20.9f|% 20.9f|*fatal error: %s", tss, tsl, s); + sps_log(LOG_ERR, "|% 20.9f|% 20.9f|*fatal error: %s", tss, tsl, s); else if ((debuglev) && (config.debugger_show_relative_time)) - syslog(LOG_ERR, "% 20.9f|*fatal error: %s", tsl, s); + sps_log(LOG_ERR, "% 20.9f|*fatal error: %s", tsl, s); else if ((debuglev) && (config.debugger_show_elapsed_time)) - syslog(LOG_ERR, "% 20.9f|*fatal error: %s", tss, s); + sps_log(LOG_ERR, "% 20.9f|*fatal error: %s", tss, s); else - syslog(LOG_ERR, "fatal error: %s", s); - #endif + sps_log(LOG_ERR, "fatal error: %s", s); pthread_setcancelstate(oldState, NULL); exit(1); } @@ -184,25 +195,14 @@ void warn(const char *format, ...) { va_start(args, format); vsnprintf(s, sizeof(s), format, args); va_end(args); -#ifdef CONFIG_LIBDAEMON if ((debuglev) && (config.debugger_show_elapsed_time) && (config.debugger_show_relative_time)) - daemon_log(LOG_WARNING, "|% 20.9f|% 20.9f|*warning: %s", tss, tsl, s); + sps_log(LOG_WARNING, "|% 20.9f|% 20.9f|*warning: %s", tss, tsl, s); else if ((debuglev) && (config.debugger_show_relative_time)) - daemon_log(LOG_WARNING, "% 20.9f|*warning: %s", tsl, s); + sps_log(LOG_WARNING, "% 20.9f|*warning: %s", tsl, s); else if ((debuglev) && (config.debugger_show_elapsed_time)) - daemon_log(LOG_WARNING, "% 20.9f|*warning: %s", tss, s); + sps_log(LOG_WARNING, "% 20.9f|*warning: %s", tss, s); else - daemon_log(LOG_WARNING, "%s", s); -#else - if ((debuglev) && (config.debugger_show_elapsed_time) && (config.debugger_show_relative_time)) - syslog(LOG_WARNING, "|% 20.9f|% 20.9f|*warning: %s", tss, tsl, s); - else if ((debuglev) && (config.debugger_show_relative_time)) - syslog(LOG_WARNING, "% 20.9f|*warning: %s", tsl, s); - else if ((debuglev) && (config.debugger_show_elapsed_time)) - syslog(LOG_WARNING, "% 20.9f|*warning: %s", tss, s); - else - syslog(LOG_WARNING, "%s", s); -#endif + sps_log(LOG_WARNING, "%s", s); pthread_setcancelstate(oldState, NULL); } @@ -224,25 +224,14 @@ void debug(int level, const char *format, ...) { va_start(args, format); vsnprintf(s, sizeof(s), format, args); va_end(args); -#ifdef CONFIG_LIBDAEMON - if ((config.debugger_show_elapsed_time) && (config.debugger_show_relative_time)) - daemon_log(LOG_DEBUG, "|% 20.9f|% 20.9f|%s", tss, tsl, s); - else if (config.debugger_show_relative_time) - daemon_log(LOG_DEBUG, "% 20.9f|%s", tsl, s); - else if (config.debugger_show_elapsed_time) - daemon_log(LOG_DEBUG, "% 20.9f|%s", tss, s); - else - daemon_log(LOG_DEBUG, "%s", s); -#else if ((config.debugger_show_elapsed_time) && (config.debugger_show_relative_time)) - syslog(LOG_DEBUG, "|% 20.9f|% 20.9f|%s", tss, tsl, s); + sps_log(LOG_DEBUG, "|% 20.9f|% 20.9f|%s", tss, tsl, s); else if (config.debugger_show_relative_time) - syslog(LOG_DEBUG, "% 20.9f|%s", tsl, s); + sps_log(LOG_DEBUG, "% 20.9f|%s", tsl, s); else if (config.debugger_show_elapsed_time) - syslog(LOG_DEBUG, "% 20.9f|%s", tss, s); + sps_log(LOG_DEBUG, "% 20.9f|%s", tss, s); else - syslog(LOG_DEBUG, "%s", s); -#endif + sps_log(LOG_DEBUG, "%s", s); pthread_setcancelstate(oldState, NULL); } @@ -262,26 +251,14 @@ void inform(const char *format, ...) { va_start(args, format); vsnprintf(s, sizeof(s), format, args); va_end(args); -#ifdef CONFIG_LIBDAEMON if ((debuglev) && (config.debugger_show_elapsed_time) && (config.debugger_show_relative_time)) - daemon_log(LOG_INFO, "|% 20.9f|% 20.9f|%s", tss, tsl, s); + sps_log(LOG_INFO, "|% 20.9f|% 20.9f|%s", tss, tsl, s); else if ((debuglev) && (config.debugger_show_relative_time)) - daemon_log(LOG_INFO, "% 20.9f|%s", tsl, s); + sps_log(LOG_INFO, "% 20.9f|%s", tsl, s); else if ((debuglev) && (config.debugger_show_elapsed_time)) - daemon_log(LOG_INFO, "% 20.9f|%s", tss, s); + sps_log(LOG_INFO, "% 20.9f|%s", tss, s); else - daemon_log(LOG_INFO, "%s", s); -#else - if ((debuglev) && (config.debugger_show_elapsed_time) && (config.debugger_show_relative_time)) - syslog(LOG_INFO, "|% 20.9f|% 20.9f|%s", tss, tsl, s); - else if ((debuglev) && (config.debugger_show_relative_time)) - syslog(LOG_INFO, "% 20.9f|%s", tsl, s); - else if ((debuglev) && (config.debugger_show_elapsed_time)) - syslog(LOG_INFO, "% 20.9f|%s", tss, s); - else - syslog(LOG_INFO, "%s", s); - -#endif + sps_log(LOG_INFO, "%s", s); pthread_setcancelstate(oldState, NULL); } diff --git a/common.h b/common.h index 78c9ddda..9dceabb3 100644 --- a/common.h +++ b/common.h @@ -245,6 +245,8 @@ uint16_t nctohs(const uint8_t *p); // read 2 characters from *p and do ntohs on void memory_barrier(); +void log_to_stderr(); // call this to director logging to stderr; + // true if Shairport Sync is supposed to be sending output to the output device, false otherwise int get_requested_connection_state_to_output(); diff --git a/shairport.c b/shairport.c index 0959e5f2..3fdf780d 100644 --- a/shairport.c +++ b/shairport.c @@ -156,9 +156,9 @@ void usage(char *progname) { #ifdef CONFIG_LIBDAEMON printf(" -d, --daemon daemonise.\n"); printf(" -j, --justDaemoniseNoPIDFile daemonise without a PID file.\n"); + printf(" -k, --kill kill the existing shairport daemon.\n"); #endif printf(" -V, --version show version information.\n"); - printf(" -k, --kill kill the existing shairport daemon.\n"); printf(" -c, --configfile=FILE read configuration settings from FILE. Default is " "/etc/shairport-sync.conf.\n"); @@ -171,7 +171,6 @@ void usage(char *progname) { printf(" -L, --latency=FRAMES [Deprecated] Set the latency for audio sent from an unknown " "device.\n"); printf(" The default is to set it automatically.\n"); - printf(" The default is to set it automatically.\n"); printf(" -S, --stuffing=MODE set how to adjust current latency to match desired latency, " "where \n"); printf(" \"basic\" (default) inserts or deletes audio frames from " @@ -213,6 +212,7 @@ void usage(char *progname) { printf(" The default is /tmp/shairport-sync-metadata.\n"); printf(" --get-coverart send cover art through the metadata pipe.\n"); #endif + printf(" -u, --use-stderr log messages through STDERR rather than syslog.\n"); printf("\n"); mdns_ls_backends(); printf("\n"); @@ -229,15 +229,17 @@ int parse_options(int argc, char **argv) { int fResyncthreshold = (int)(config.resyncthreshold * 44100); int fTolerance = (int)(config.tolerance * 44100); poptContext optCon; /* context for parsing command-line options */ +#if CONFIG_LIBDAEMON int daemonisewith = 0; int daemonisewithout = 0; +#endif struct poptOption optionsTable[] = { {"verbose", 'v', POPT_ARG_NONE, NULL, 'v', NULL, NULL}, - {"disconnectFromOutput", 'D', POPT_ARG_NONE, NULL, 0, NULL, NULL}, - {"reconnectToOutput", 'R', POPT_ARG_NONE, NULL, 0, NULL, NULL}, +#if CONFIG_LIBDAEMON {"kill", 'k', POPT_ARG_NONE, NULL, 0, NULL, NULL}, {"daemon", 'd', POPT_ARG_NONE, &daemonisewith, 0, NULL, NULL}, {"justDaemoniseNoPIDFile", 'j', POPT_ARG_NONE, &daemonisewithout, 0, NULL, NULL}, +#endif {"configfile", 'c', POPT_ARG_STRING, &config.configfile, 0, NULL, NULL}, {"statistics", 0, POPT_ARG_NONE, &config.statistics_requested, 0, NULL, NULL}, {"logOutputLevel", 0, POPT_ARG_NONE, &config.logOutputLevel, 0, NULL, NULL}, @@ -255,6 +257,7 @@ int parse_options(int argc, char **argv) { {"timeout", 't', POPT_ARG_INT, &config.timeout, 't', NULL, NULL}, {"password", 0, POPT_ARG_STRING, &config.password, 0, NULL, NULL}, {"tolerance", 'z', POPT_ARG_INT, &fTolerance, 0, NULL, NULL}, + {"use-stderr", 'u', POPT_ARG_NONE, NULL, 'u', NULL, NULL}, #ifdef CONFIG_METADATA {"metadata-pipename", 'M', POPT_ARG_STRING, &config.metadata_pipename, 'M', NULL, NULL}, {"get-coverart", 'g', POPT_ARG_NONE, &config.get_coverart, 'g', NULL, NULL}, @@ -281,6 +284,9 @@ int parse_options(int argc, char **argv) { case 'v': debuglev++; break; + case 'u': + log_to_stderr(); + break; case 'D': inform("Warning: the option -D or --disconnectFromOutput is deprecated."); break;