]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
Adds a '-F' flag to httpd's main() - which causes the mother
authorDirk-Willem van Gulik <dirkx@apache.org>
Mon, 13 May 2002 23:00:07 +0000 (23:00 +0000)
committerDirk-Willem van Gulik <dirkx@apache.org>
Mon, 13 May 2002 23:00:07 +0000 (23:00 +0000)
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 <handler-grendel.net>
Submitted by: http://www.catnook.com/patches/apache-1.3.24-daemontools.patch
Jos Backus <jos-catnook.com>
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

src/CHANGES
src/main/http_main.c

index bb74b2f22dd84ea417a686ca7a32c1b476758bc8..bc100d5f08f215498f229928996778d4be45b5ae 100644 (file)
@@ -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 <handler@grendel.net>,
+     Jos Backus <jos@catnook.com> [ Dirk-Willem van Gulik ]].
+
   *) Make apxs.pl more flexible (file extensions like .so or .dll are
      no longer hardcoded). [Stipe Tolj <tolj@wapme-systems.de>]
 
index c84d2e3335124c256da3605e9edc83e5a48dcd0c..c18d8935c9160921c92c4917d98be7e2dc612fbb 100644 (file)
@@ -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':