]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 3826: Add --foreground option to fix -z process behaviour
authorMarcos Mello <marcosfrm@gmail.com>
Wed, 24 Feb 2016 23:55:48 +0000 (12:55 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Wed, 24 Feb 2016 23:55:48 +0000 (12:55 +1300)
src/globals.h
src/main.cc
src/squid.8.in

index 29776474586640bc1c5d0e5944ae94e917f33dfd..2f241045d7fbf81c9f2b76521b612e7adfedd31f 100644 (file)
@@ -48,6 +48,7 @@ extern int config_lineno;   /* 0 */
 extern int opt_reuseaddr;   /* 1 */
 extern int neighbors_do_private_keys;   /* 1 */
 extern int opt_catch_signals;   /* 1 */
+extern int opt_foreground;    /* 0 */
 extern int opt_foreground_rebuild;  /* 0 */
 extern char *opt_forwarded_for; /* NULL */
 extern int opt_reload_hit_only; /* 0 */
index 482ea54b4ac2c23a18e691e73a33e4099d72c7e5..88e83d382e3986381e30b29fb8a3908aacb6a955 100644 (file)
@@ -383,6 +383,8 @@ usage(void)
             "       -D        OBSOLETE. Scheduled for removal.\n"
             "       -F        Don't serve any requests until store is rebuilt.\n"
             "       -N        No daemon mode.\n"
+            "       --foreground\n"
+            "                 Parent process does not exit until its children have finished.\n"
 #if USE_WIN32_SERVICE
             "       -O options\n"
             "                 Set Windows Service Command line options in Registry.\n"
@@ -415,8 +417,9 @@ mainParseOptions(int argc, char *argv[])
 
     // long options
     static struct option squidOptions[] = {
-        {"help",    no_argument, 0, 'h'},
-        {"version", no_argument, 0, 'v'},
+        {"foreground", no_argument, 0,  1 },
+        {"help",       no_argument, 0, 'h'},
+        {"version",    no_argument, 0, 'v'},
         {0, 0, 0, 0}
     };
 
@@ -674,6 +677,12 @@ mainParseOptions(int argc, char *argv[])
             opt_create_swap_dirs = 1;
             break;
 
+        case 1:
+            /** \par --foreground
+             * Set global option opt_foreground */
+            opt_foreground = 1;
+            break;
+
         case 'h':
 
         case '?':
@@ -1446,6 +1455,10 @@ SquidMain(int argc, char **argv)
 
     mainParseOptions(argc, argv);
 
+    if (opt_foreground && opt_no_daemon) {
+        debugs(1, DBG_CRITICAL, "WARNING: --foreground command-line option has no effect with -N.");
+    }
+
     if (opt_parse_cfg_only) {
         Debug::parseOptions("ALL,1");
     }
@@ -1781,7 +1794,7 @@ watch_child(char *argv[])
 {
 #if !_SQUID_WINDOWS_
     char *prog;
-    PidStatus status;
+    PidStatus status_f, status;
     pid_t pid;
 #ifdef TIOCNOTTY
 
@@ -1794,8 +1807,16 @@ watch_child(char *argv[])
 
     if ((pid = fork()) < 0)
         syslog(LOG_ALERT, "fork failed: %s", xstrerror());
-    else if (pid > 0)
+    else if (pid > 0) {
+        // parent
+        if (opt_foreground) {
+            if (WaitForAnyPid(status_f, 0) < 0) {
+                syslog(LOG_ALERT, "WaitForAnyPid failed: %s", xstrerror());
+            }
+        }
+
         exit(0);
+    }
 
     if (setsid() < 0)
         syslog(LOG_ALERT, "setsid failed: %s", xstrerror());
index 3882481741f95976f096d92dc0cd49bf06315c0b..9fdeb2225a75379a0353a7447f308b30e48d71c4 100644 (file)
@@ -118,6 +118,12 @@ Specify Windows Service name to use for service operations, default is:
 No daemon mode.
 .
 .if !'po4a'hide' .TP
+.if !'po4a'hide' .B \--foreground
+Parent process does not exit until its children have finished. It has no effect with
+.B \-N
+which does not fork/exit at startup.
+.
+.if !'po4a'hide' .TP
 .if !'po4a'hide' .B "\-O options"
 Set Windows Service Command line options in Registry.
 .