]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Improve the displayConfig output and route it through the standard logging system...
authorMike Brady <4265913+mikebrady@users.noreply.github.com>
Wed, 12 Oct 2022 12:52:05 +0000 (13:52 +0100)
committerMike Brady <4265913+mikebrady@users.noreply.github.com>
Wed, 12 Oct 2022 12:52:05 +0000 (13:52 +0100)
man/Makefile [new file with mode: 0644]
man/shairport-sync.7
man/shairport-sync.7.xml
shairport.c

diff --git a/man/Makefile b/man/Makefile
new file mode 100644 (file)
index 0000000..0c30fe4
--- /dev/null
@@ -0,0 +1,11 @@
+shairport-sync.7: shairport-sync.7.xml
+       xmltoman shairport-sync.7.xml > shairport-sync.7
+
+shairport-sync.html: shairport-sync.7.xml
+       xsltproc xmltoman.xsl shairport-sync.7.xml > shairport-sync.html
+
+all: shairport-sync.7 shairport-sync.html
+
+clean:
+       rm shairport-sync.7
+       rm shairport-sync.html
index 1dc2dd42aecfaaa7ed0d14081747657a8c53d736..8bbb915b2a37d64280125bc8dc339e43adc32a82 100644 (file)
@@ -74,11 +74,9 @@ Read configuration settings from \fIfilename\f1. The default is to read them fro
 Instruct shairport-sync to demonise itself. It will write its Process ID (PID) to a file, usually at \fI/var/run/shairport-sync/shairport-sync.pid\f1, which is used by the \fB-k\f1, \fB-D\f1 and \fB-R\f1 options to locate the daemon at a later time. See also the \fB-j\f1 option. Only available if shairport-sync has been compiled with libdaemon support. 
 .TP
 \fB--displayConfig\f1
-This will display information relating to the configuration of Shairport Sync. It can be very useful for debugging. The information displayed is the version string (which indicates the build options used when \fBshairport-sync\f1 was built), the contents of the command line that invoked Shairport Sync, the name of the configuration file and the active settings therein.
+This logs information relating to the configuration of Shairport Sync. It can be very useful for debugging. The information logged is some host OS information, the Shairport Sync version string (which indicates the build options used when \fBshairport-sync\f1 was built), the contents of the command line that invoked Shairport Sync, the name of the configuration file and the active settings therein.
 
 If this is the only option on the command line, \fBshairport-sync\f1 will terminate after displaying the information.
-
-Due to a limitation, \fB--displayConfig\f1 always outputs to \fISTDERR\f1, irrespective of the setting of \fB--log-to-syslog\f1.
 .TP
 \fB-E \f1\fIprogram\f1\fB | --on-stop=\f1\fIprogram\f1
 Execute \fIprogram\f1 when playback has ended. Specify the full path to the program, e.g. \fI/usr/bin/logger\f1. Executable scripts can be used, but they must have the appropriate shebang (\fI#!/bin/sh\f1) in the headline.
index 76e991119a30ed67da6fb57c5bc60edf44ae7797..c9a197dec5f38ae1186ca62591aa7d3b12e8cbcb 100644 (file)
          <option>
                <p><opt>--displayConfig</opt></p>
                <optdesc><p>
-               This will display information relating to the configuration of Shairport Sync.
-               It can be very useful for debugging. The information displayed is the version string
+               This logs information relating to the configuration of Shairport Sync.
+               It can be very useful for debugging. The information logged is 
+               some host OS information, the Shairport Sync version string
                (which indicates the build options used when <opt>shairport-sync</opt> was built),
                the contents of the command line that invoked Shairport Sync,
                the name of the configuration file and the active settings therein.</p>
                <p>If this is the only option on the command line, <opt>shairport-sync</opt> will
                terminate after displaying the information.</p>
-               <p>Due to a limitation, <opt>--displayConfig</opt> always outputs to <file>STDERR</file>,
-               irrespective of the setting of <opt>--log-to-syslog</opt>.</p>
                </optdesc>
          </option>
 
index 03023a0c0a9b5499e62d57fb8b46156f2cb8aab6..439e5b6abf11be61dee3de7795fe157a3261d1c4 100644 (file)
@@ -280,7 +280,7 @@ void usage(char *progname) {
     printf("Options:\n");
     printf("    -h, --help              Show this help.\n");
     printf("    -V, --version           Show version information -- the version string.\n");
-    printf("    --displayConfig         Output version string, command line, configuration file and active settings to stderr.\n");
+    printf("    --displayConfig         Output OS information, version string, command line, configuration file and active settings to the log.\n");
     printf("    --statistics            Print some interesting statistics. More will be printed if -v / -vv / -vvv are also chosen.\n");
     printf("    -v, --verbose           Print debug information; -v some; -vv more; -vvv lots -- generally too much.\n");
     printf("    -c, --configfile=FILE   Read configuration settings from FILE. Default is %s.\n", configuration_file_path);
@@ -570,7 +570,7 @@ int parse_options(int argc, char **argv) {
                               1); // allow autoconversion from int/float to int/float
       // make config.cfg point to it
       config.cfg = &config_file_stuff;
-    
+
       /* Get the Service Name. */
       if (config_lookup_string(config.cfg, "general.name", &str)) {
         raw_service_name = (char *)str;
@@ -1674,37 +1674,117 @@ void termHandler(__attribute__((unused)) int k) {
   exit(EXIT_SUCCESS);
 }
 
-void display_config(int argc, char **argv) {
-  if (log_to_syslog_selected != 0) {
-   warn("The \"--display-config\" option has a limitation: it can only output to STDERR. To route its output to the system log, please redirect STDERR to the system log.");
-   fprintf(stderr, "NOTE: the \"--display-config\" option has a limitation: it can only output to STDERR. To route its output to the system log, please redirect STDERR to the system log.\n\n");
+void _display_config(const char *filename, const int linenumber, int argc, char **argv) {
+  _inform(filename, linenumber, ">> Display Config Start.");
+
+  // see the man entry on popen
+  FILE *fp;
+  int status;
+  char result[1024];
+
+  fp = popen("uname -a 2>/dev/null", "r");
+  if (fp != NULL) {
+    if (fgets(result, 1024, fp) != NULL) {
+      _inform(filename, linenumber, "");
+      _inform(filename, linenumber, "From \"uname -a\":");
+      if (result[strlen(result) - 1] <= ' ')
+        result[strlen(result) - 1] = '\0'; // remove the last character if it's not printable
+      _inform(filename, linenumber, " %s", result);
+    }
+    status = pclose(fp);
+    if (status == -1) {
+      debug(1, "Error on pclose");
+    }
+  }
+
+  fp = popen("(cat /etc/os-release | grep PRETTY_NAME | sed 's/PRETTY_NAME=//' | sed 's/\"//g') "
+             "2>/dev/null",
+             "r");
+  if (fp != NULL) {
+    if (fgets(result, 1024, fp) != NULL) {
+      _inform(filename, linenumber, "");
+      _inform(filename, linenumber, "From /etc/os-release:");
+      if (result[strlen(result) - 1] <= ' ')
+        result[strlen(result) - 1] = '\0'; // remove the last character if it's not printable
+      _inform(filename, linenumber, " %s", result);
+    }
+    status = pclose(fp);
+    if (status == -1) {
+      debug(1, "Error on pclose");
+    }
   }
-  fprintf(stderr, ">> Display Config Start.\n");
+
+  fp = popen("cat /sys/firmware/devicetree/base/model 2>/dev/null", "r");
+  if (fp != NULL) {
+    if (fgets(result, 1024, fp) != NULL) {
+      _inform(filename, linenumber, "");
+      _inform(filename, linenumber, "From /sys/firmware/devicetree/base/model:");
+      _inform(filename, linenumber, " %s", result);
+    }
+    status = pclose(fp);
+    if (status == -1) {
+      debug(1, "Error on pclose");
+    }
+  }
+
   char *version_string = get_version_string();
   if (version_string) {
-    fprintf(stderr, "\nVersion String:\n%s\n", version_string);
+    _inform(filename, linenumber, "");
+    _inform(filename, linenumber, "Shairport Sync Version String:");
+    _inform(filename, linenumber, " %s", version_string);
     free(version_string);
   } else {
-    fprintf(stderr, "Can't print version string!\n");
+    debug(1, "Can't print version string!\n");
   }
   if (argc != 0) {
-    fprintf(stderr, "\nCommand Line:\n");
+    char *obfp = result;
     int i;
     for (i = 0; i < argc - 1; i++) {
-      fprintf(stderr, "%s ", argv[i]);
+      snprintf(obfp, strlen(argv[i]) + 2, "%s ", argv[i]);
+      obfp += strlen(argv[i]) + 1;
     }
-    fprintf(stderr, "%s\n", argv[argc]);
+    snprintf(obfp, strlen(argv[i]) + 1, "%s", argv[i]);
+    obfp += strlen(argv[i]);
+    *obfp = 0;
+
+    _inform(filename, linenumber, "");
+    _inform(filename, linenumber, "Command Line:");
+    _inform(filename, linenumber, " %s", result);
   }
-  
+
   if (config.cfg == NULL)
-    fprintf(stderr, "\nNo configuration file.\n");
+    _inform(filename, linenumber, "No configuration file.");
   else {
-    fprintf(stderr, "\nConfiguration File:\n%s\n\nConfiguration File Settings:\n",config_file_real_path);
-    config_write(config.cfg,stderr); 
+    int configpipe[2];
+    if (pipe(configpipe) == 0) {
+      FILE *cw;
+      cw = fdopen(configpipe[1], "w");
+      _inform(filename, linenumber, "");
+      _inform(filename, linenumber, "Configuration File:");
+      _inform(filename, linenumber, " %s", config_file_real_path);
+      _inform(filename, linenumber, "");
+      _inform(filename, linenumber, "Configuration File Settings:");
+      config_write(config.cfg, cw);
+      fclose(cw);
+      FILE *cr;
+      cr = fdopen(configpipe[0], "r");
+      while (fgets(result, 1024, cr) != NULL) {
+        // replace funny character at the end, if it's there
+        if (result[strlen(result) - 1] <= ' ')
+          result[strlen(result) - 1] = '\0'; // remove the last character if it's not printable
+        _inform(filename, linenumber, " %s", result);
+      }
+      fclose(cr);
+    } else {
+      debug(1, "Error making pipe.\n");
+    }
   }
-  fprintf(stderr, "\n>> Display Config End.\n");
+  _inform(filename, linenumber, "");
+  _inform(filename, linenumber, ">> Display Config End.");
 }
 
+#define display_config(argc, argv) _display_config(__FILE__, __LINE__, argc, argv)
+
 int main(int argc, char **argv) {
   memset(&config, 0, sizeof(config)); // also clears all strings, BTW
   /* Check if we are called with -V or --version parameter */
@@ -1712,7 +1792,7 @@ int main(int argc, char **argv) {
     print_version();
     exit(EXIT_SUCCESS);
   }
-  
+
   // this is a bit weird, but necessary -- basename() may modify the argument passed in
   char *basec = strdup(argv[0]);
   char *bname = basename(basec);
@@ -1884,7 +1964,7 @@ int main(int argc, char **argv) {
          config.service_name);
     config.service_name[50] = '\0'; // truncate it and carry on...
   }
-  
+
   if (display_config_selected != 0) {
     display_config(argc, argv);
     if (argc == 2) {