You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by di...@apache.org on 2002/05/14 01:00:09 UTC

cvs commit: apache-1.3/src/main http_main.c

dirkx       02/05/13 16:00:08

  Modified:    src      CHANGES
               src/main http_main.c
  Log:
  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 <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
  
  Revision  Changes    Path
  1.1818    +6 -0      apache-1.3/src/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/CHANGES,v
  retrieving revision 1.1817
  retrieving revision 1.1818
  diff -u -r1.1817 -r1.1818
  --- CHANGES	6 May 2002 08:34:13 -0000	1.1817
  +++ CHANGES	13 May 2002 23:00:07 -0000	1.1818
  @@ -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 <ha...@grendel.net>,
  +     Jos Backus <jo...@catnook.com> [ Dirk-Willem van Gulik ]].
  +
     *) Make apxs.pl more flexible (file extensions like .so or .dll are
        no longer hardcoded). [Stipe Tolj <to...@wapme-systems.de>]
   
  
  
  
  1.581     +29 -14    apache-1.3/src/main/http_main.c
  
  Index: http_main.c
  ===================================================================
  RCS file: /home/cvs/apache-1.3/src/main/http_main.c,v
  retrieving revision 1.580
  retrieving revision 1.581
  diff -u -r1.580 -r1.581
  --- http_main.c	22 Apr 2002 18:23:19 -0000	1.580
  +++ http_main.c	13 May 2002 23:00:07 -0000	1.581
  @@ -341,6 +341,8 @@
   
   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 @@
   #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 @@
       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 @@
   #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 @@
       !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 @@
       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 @@
   	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 @@
           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 @@
                       && 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 @@
        * 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':
  
  
  

Re: cvs commit: apache-1.3/src/main http_main.c

Posted by Justin Erenkrantz <je...@apache.org>.
On Mon, May 13, 2002 at 11:00:09PM -0000, dirkx@apache.org wrote:
>   Index: http_main.c
>   ===================================================================
>   RCS file: /home/cvs/apache-1.3/src/main/http_main.c,v
>   retrieving revision 1.580
>   retrieving revision 1.581
>   diff -u -r1.580 -r1.581
>   --- http_main.c	22 Apr 2002 18:23:19 -0000	1.580
>   +++ http_main.c	13 May 2002 23:00:07 -0000	1.581
<snip>
>   @@ -3374,19 +3377,24 @@
>        !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) {

Without compiling this, I'd guess that you're missing a (.  This
portion should be reverted.  -- justin