From: Marcos Mello Date: Wed, 24 Feb 2016 23:55:48 +0000 (+1300) Subject: Bug 3826: Add --foreground option to fix -z process behaviour X-Git-Tag: SQUID_4_0_8~63 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=effda67efc1d2675bc289ac816f2b8eee78c63f6;p=thirdparty%2Fsquid.git Bug 3826: Add --foreground option to fix -z process behaviour --- diff --git a/src/globals.h b/src/globals.h index 2977647458..2f241045d7 100644 --- a/src/globals.h +++ b/src/globals.h @@ -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 */ diff --git a/src/main.cc b/src/main.cc index 482ea54b4a..88e83d382e 100644 --- a/src/main.cc +++ b/src/main.cc @@ -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()); diff --git a/src/squid.8.in b/src/squid.8.in index 3882481741..9fdeb2225a 100644 --- a/src/squid.8.in +++ b/src/squid.8.in @@ -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. .