From: wessels <> Date: Sat, 11 Dec 1999 01:11:02 +0000 (+0000) Subject: Added a feature so Squid runs a "squid_start" program just before X-Git-Tag: SQUID_3_0_PRE1~2108 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e18d7fdc1f575e8b60453724c3f08210c39a96f7;p=thirdparty%2Fsquid.git Added a feature so Squid runs a "squid_start" program just before forking the child process in daemon mode. The "squid_start" script must be in the same directory as the squid executable. I'm sure that will change, however, when people complain. --- diff --git a/src/main.cc b/src/main.cc index 8a88f5bfbe..0295ecdab9 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,6 +1,6 @@ /* - * $Id: main.cc,v 1.305 1999/10/04 05:05:17 wessels Exp $ + * $Id: main.cc,v 1.306 1999/12/10 18:11:02 wessels Exp $ * * DEBUG: section 1 Startup and Main Loop * AUTHOR: Harvest Derived @@ -72,6 +72,8 @@ extern void log_trace_init(char *); static EVH SquidShutdown; static void mainSetCwd(void); +static const char *squid_start_script = "squid_start"; + #if TEST_ACCESS #include "test_access.c" #endif @@ -716,6 +718,43 @@ sendSignal(void) exit(0); } +/* + * This function is run when Squid is in daemon mode, just + * before the parent forks and starts up the child process. + * It can be used for admin-specific tasks, such as notifying + * someone that Squid is (re)started. + */ +static void +mainStartScript(const char *prog) +{ + char script[SQUID_MAXPATHLEN]; + char *t; + size_t sl = 0; + pid_t cpid; + pid_t rpid; + xstrncpy(script, prog, MAXPATHLEN); + if ((t = strrchr(script, '/'))) { + *(++t) = '\0'; + sl = strlen(script); + } + xstrncpy(&script[sl], squid_start_script, MAXPATHLEN - sl); + if ((cpid = fork()) == 0) { + /* child */ + execl(script, squid_start_script, 0); + _exit(0); + } else { + do { +#ifdef _SQUID_NEXT_ + union wait status; + rpid = wait3(&status, 0, NULL); +#else + int status; + rpid = waitpid(-1, &status, 0); +#endif + } while (rpid != cpid); + } +} + static void watch_child(char *argv[]) { @@ -751,6 +790,7 @@ watch_child(char *argv[]) umask(0); #endif for (;;) { + mainStartScript(argv[0]); if ((pid = fork()) == 0) { /* child */ prog = xstrdup(argv[0]);