[xiph-commits] r18945 - icecast/trunk/icecast/src

dm8tbr at svn.xiph.org dm8tbr at svn.xiph.org
Wed May 15 09:45:55 PDT 2013


Author: dm8tbr
Date: 2013-05-15 09:45:55 -0700 (Wed, 15 May 2013)
New Revision: 18945

Modified:
   icecast/trunk/icecast/src/main.c
Log:
This patch closes ticket #1886.

I've rethought the approach and found a much cleaner way. 
We now split handling of command line arguments into two parts.
Only the critical part of getting the config file is done first (and -v as it prevents startup).
The rest (currently only -b) is deferred.

This achieves the important bit why #1886 was created. 
It allows us to log error messages to stderr even if the -b argument is passed.
This is mainly for the case where the logfile or TCP port can't be opened.


Modified: icecast/trunk/icecast/src/main.c
===================================================================
--- icecast/trunk/icecast/src/main.c	2013-05-14 01:30:25 UTC (rev 18944)
+++ icecast/trunk/icecast/src/main.c	2013-05-15 16:45:55 UTC (rev 18945)
@@ -3,10 +3,11 @@
  * This program is distributed under the GNU General Public License, version 2.
  * A copy of this license is included with this source.
  *
- * Copyright 2000-2004, Jack Moffitt <jack at xiph.org, 
+ * Copyright 2000-2013, Jack Moffitt <jack at xiph.org, 
  *                      Michael Smith <msmith at xiph.org>,
  *                      oddsock <oddsock at xiph.org>,
- *                      Karl Heyes <karl at xiph.org>
+ *                      Karl Heyes <karl at xiph.org>,
+ *                      Thomas B. Ruecker <thomas.ruecker at tieto.com>
  *                      and others (see AUTHORS for details).
  * Copyright 2011-2012, Philipp "ph3-der-loewe" Schafft <lion at lion.leolix.org>,
  */
@@ -151,31 +152,12 @@
 
 static int _parse_config_opts(int argc, char **argv, char *filename, int size)
 {
-    int i = 1;
+    int i;
     int config_ok = 0;
 
-    background = 0;
     if (argc < 2) return -1;
 
-    while (i < argc) {
-        if (strcmp(argv[i], "-b") == 0) {
-#ifndef WIN32
-            pid_t pid;
-            fprintf(stdout, "Starting icecast2\nDetaching from the console\n");
-
-            pid = fork();
-
-            if (pid > 0) {
-                /* exit the parent */
-                exit(0);
-            }
-            else if(pid < 0) {
-                fprintf(stderr, "FATAL: Unable to fork child!");
-                exit(1);
-            }
-            background = 1;
-#endif
-        }
+    for (i = 1; i < argc; i++) {
         if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) {
             fprintf(stdout, "%s\n", ICECAST_VERSION_STRING);
             exit(0);
@@ -190,7 +172,6 @@
                 return -1;
             }
         }
-        i++;
     }
 
     if(config_ok)
@@ -199,6 +180,34 @@
         return -1;
 }
 
+static int _parse_config_opts_remaining(int argc, char **argv, char *filename, int size)
+{
+    int i;
+    background = 0;
+
+    for (i = 1; i < argc; i++) {
+        if (strcmp(argv[i], "-b") == 0) {
+#ifndef WIN32
+            pid_t pid;
+            fprintf(stdout, "Starting icecast2\nDetaching from the console\n");
+
+            pid = fork();
+
+            if (pid > 0) {
+                /* exit the parent */
+                exit(0);
+            }
+            else if(pid < 0) {
+                fprintf(stderr, "FATAL: Unable to fork child!");
+                exit(1);
+            }
+            background = 1;
+#endif
+        }
+    }
+    return 0;
+}
+
 static int _start_logging(void)
 {
     char fn_error[FILENAME_MAX];
@@ -501,6 +510,9 @@
         return 1;
     }
 
+    /* Delayed command line argument parsing, e.g. background */
+    _parse_config_opts_remaining(argc, argv, filename, 512);
+
     INFO1 ("%s server started", ICECAST_VERSION_STRING);
 
     /* REM 3D Graphics */



More information about the commits mailing list