[icecast-dev] [PATCH] main.c: use pid_t and cleanup command line opts parsing.

Dale Ghent daleg at elemental.org
Sat Mar 20 12:32:44 PST 2004


Use pid_t instead of int for variable processID

Add error message if fork() fails.

Do not immediately return() after encountering the -c flag - we may still
have additional argv members to find and take care of.

/dale
-------------- next part --------------
Index: main.c
===================================================================
RCS file: /usr/local/cvsroot/icecast/src/main.c,v
retrieving revision 1.40
diff -u -r1.40 main.c
--- a/main.c	9 Mar 2004 23:52:20 -0000	1.40
+++ b/main.c	20 Mar 2004 20:26:56 -0000
@@ -136,17 +136,24 @@
 static int _parse_config_file(int argc, char **argv, char *filename, int size)
 {
     int i = 1;
-    int    processID = 0;
+
+#ifndef WIN32
+    pid_t processID;
+#endif
 
     if (argc < 2) return -1;
 
     while (i < argc) {
         if (strcmp(argv[i], "-b") == 0) {
 #ifndef WIN32
-            fprintf(stdout, "Starting icecast2\nDetaching from the console\n");
-            if ((processID = (int)fork()) > 0) {
+            fprintf(stdout, "Detaching from the console...\n");
+
+            if ((processID = fork()) > 0)
                 /* exit the parent */
-                _exit(0);
+                exit(0);
+            else if (processID == -1) {
+                fprintf(stderr, "FATAL: Unable to fork child!");
+                exit(1);
             }
 #endif
         }
@@ -159,7 +166,6 @@
             if (i + 1 < argc) {
                 strncpy(filename, argv[i + 1], size-1);
                 filename[size-1] = 0;
-                return 1;
             } else {
                 return -1;
             }
𸬵ªÜ†+Þ²m§ÿðÃb¦+ƒö«r¯zÏâqç²Úk¢7œ¶&z– zm§ÿðÃœyƬ¶Šàý:.žË›±Êâmçë¢kaŠÉb²ÛÖ¦zˁëh‰ÇœjË]zúު笷©†Šàr‰íj)âž
'—+a{
+véì¹»®&ÞŠ{ayºÈÚ,¹¸ÞrجçyÕ'²æìr¸›zg¬±¨²Ç§¶Ú-…éb²Ü"–VÞŠ	è­ç~)mz·


More information about the Icecast-dev mailing list