From: Dirk-Willem van Gulik Date: Mon, 13 May 2002 23:00:07 +0000 (+0000) Subject: Adds a '-F' flag to httpd's main() - which causes the mother X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0b6a4deba90b538b4cc29833ba3e4514bb25d5c4;p=thirdparty%2Fapache%2Fhttpd.git Adds a '-F' flag to httpd's main() - which causes the mother or supervisor process to not fork&detach - as to allow integration with deamontools (http://cr.yp.to/daemontools.html). PR: http://nagoya.apache.org/bugzilla/show_bug.cgi?id=7628 Obtained from: http://marc.theaimsgroup.com/?l=apache-httpd-dev&m=101467598720760&w=2 Michael Handler Submitted by: http://www.catnook.com/patches/apache-1.3.24-daemontools.patch Jos Backus Reviewed by: Dirk-Willem van Gulik git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/1.3.x@95074 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/CHANGES b/src/CHANGES index bb74b2f22dd..bc100d5f08f 100644 --- a/src/CHANGES +++ b/src/CHANGES @@ -1,5 +1,11 @@ Changes with Apache 1.3.25 + *) Added a '-F' flag; which causes the mother/supervisor process to + no longer fork down and detach. But instead stays attached to + the tty - thus making live for automatic restart and exit checking + code easier. [ Contributed by Michael Handler , + Jos Backus [ Dirk-Willem van Gulik ]]. + *) Make apxs.pl more flexible (file extensions like .so or .dll are no longer hardcoded). [Stipe Tolj ] diff --git a/src/main/http_main.c b/src/main/http_main.c index c84d2e33351..c18d8935c91 100644 --- a/src/main/http_main.c +++ b/src/main/http_main.c @@ -341,6 +341,8 @@ static pid_t pgrp; static int one_process = 0; +static int do_detach = 1; + /* set if timeouts are to be handled by the children and not by the parent. * i.e. child_timeouts = !standalone || one_process. */ @@ -1349,7 +1351,7 @@ static void usage(char *bin) #ifdef WIN32 fprintf(stderr, "Usage: %s [-D name] [-d directory] [-f file] [-n service]\n", bin); fprintf(stderr, " %s [-C \"directive\"] [-c \"directive\"] [-k signal]\n", pad); - fprintf(stderr, " %s [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T]\n", pad); + fprintf(stderr, " %s [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T] [-F]\n", pad); #else /* !WIN32 */ #ifdef SHARED_CORE fprintf(stderr, "Usage: %s [-R directory] [-D name] [-d directory] [-f file]\n", bin); @@ -1357,7 +1359,7 @@ static void usage(char *bin) fprintf(stderr, "Usage: %s [-D name] [-d directory] [-f file]\n", bin); #endif fprintf(stderr, " %s [-C \"directive\"] [-c \"directive\"]\n", pad); - fprintf(stderr, " %s [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T]\n", pad); + fprintf(stderr, " %s [-v] [-V] [-h] [-l] [-L] [-S] [-t] [-T] [-F]\n", pad); fprintf(stderr, "Options:\n"); #ifdef SHARED_CORE fprintf(stderr, " -R directory : specify an alternate location for shared object files\n"); @@ -1380,6 +1382,7 @@ static void usage(char *bin) #endif fprintf(stderr, " -t : run syntax check for config files (with docroot check)\n"); fprintf(stderr, " -T : run syntax check for config files (without docroot check)\n"); + fprintf(stderr, " -F : run main process in foreground, for process supervisors\n"); #ifdef WIN32 fprintf(stderr, " -n name : name the Apache service for -k options below;\n"); fprintf(stderr, " -k stop|shutdown : tell running Apache to shutdown\n"); @@ -3374,19 +3377,24 @@ static void detach(void) !defined(BONE) /* Don't detach for MPE because child processes can't survive the death of the parent. */ - if ((x = fork()) > 0) - exit(0); - else if (x == -1) { - perror("fork"); - fprintf(stderr, "%s: unable to fork new process\n", ap_server_argv0); - exit(1); + if (do_detach) { + if ((x = fork()) > 0) + exit(0); + else if (x == -1) { + perror("fork"); + fprintf(stderr, "%s: unable to fork new process\n", ap_server_argv0); + exit(1); + } + RAISE_SIGSTOP(DETACH); } - RAISE_SIGSTOP(DETACH); #endif #ifndef NO_SETSID - if ((pgrp = setsid()) == -1) { + if (pgrp = setsid()) == -1) { perror("setsid"); fprintf(stderr, "%s: setsid failed\n", ap_server_argv0); + if (!do_detach) + fprintf(stderr, "setsid() failed probably because you aren't " + "running under a process management tool like daemontools\n"); exit(1); } #elif defined(NEXT) || defined(NEWSOS) @@ -5312,7 +5320,7 @@ int REALMAIN(int argc, char *argv[]) ap_setup_prelinked_modules(); while ((c = getopt(argc, argv, - "D:C:c:xXd:f:vVlLR:StTh" + "D:C:c:xXd:Ff:vVlLR:StTh" #ifdef DEBUG_SIGSTOP "Z:" #endif @@ -5334,6 +5342,9 @@ int REALMAIN(int argc, char *argv[]) case 'd': ap_cpystrn(ap_server_root, optarg, sizeof(ap_server_root)); break; + case 'F': + do_detach = 0; + break; case 'f': ap_cpystrn(ap_server_confname, optarg, sizeof(ap_server_confname)); break; @@ -7215,9 +7226,9 @@ int REALMAIN(int argc, char *argv[]) reparsed = 1; } - while ((c = getopt(argc, argv, "D:C:c:Xd:f:vVlLz:Z:wiuStThk:n:W:")) != -1) { + while ((c = getopt(argc, argv, "D:C:c:Xd:fF:vVlLz:Z:wiuStThk:n:W:")) != -1) { #else /* !WIN32 */ - while ((c = getopt(argc, argv, "D:C:c:Xd:f:vVlLesStTh")) != -1) { + while ((c = getopt(argc, argv, "D:C:c:Xd:fF:vVlLesStTh")) != -1) { #endif char **new; switch (c) { @@ -7339,6 +7350,9 @@ int REALMAIN(int argc, char *argv[]) && ap_server_root[strlen(ap_server_root) - 1] == '/') ap_server_root[strlen(ap_server_root) - 1] = '\0'; break; + case 'F': + do_detach = 0; + break; case 'f': ap_cpystrn(ap_server_confname, ap_os_canonical_filename(pcommands, optarg), @@ -7733,13 +7747,14 @@ int main(int argc, char *argv[], char *envp[]) * but only handle the -L option */ llp_dir = SHARED_CORE_DIR; - while ((c = getopt(argc, argv, "D:C:c:Xd:f:vVlLR:SZ:tTh")) != -1) { + while ((c = getopt(argc, argv, "D:C:c:Xd:Ff:vVlLR:SZ:tTh")) != -1) { switch (c) { case 'D': case 'C': case 'c': case 'X': case 'd': + case 'F': case 'f': case 'v': case 'V':