This gets -DNO_DETACH working for me with Apache's prefork MPM on Linux and FreeBSD. But from Aaron's commit log for revision 1.34 I gather that this will break daemontools-like programs.
How should I get "./httpd -DNO_DETACH" to work? Calling setsid() is bogus. This patch avoids the setsid() logic if we don't daemonize. Index: srclib/apr/threadproc/unix/procsup.c =================================================================== RCS file: /home/cvspublic/apr/threadproc/unix/procsup.c,v retrieving revision 1.35 diff -u -r1.35 procsup.c --- srclib/apr/threadproc/unix/procsup.c 13 Mar 2002 20:39:30 -0000 1.35 +++ srclib/apr/threadproc/unix/procsup.c 1 Apr 2002 21:49:20 -0000 @@ -57,42 +57,34 @@ APR_DECLARE(apr_status_t) apr_proc_detach(int daemonize) { int x; - pid_t pgrp; chdir("/"); #if !defined(MPE) && !defined(OS2) && !defined(TPF) && !defined(BEOS) /* Don't detach for MPE because child processes can't survive the death of * the parent. */ if (daemonize) { - if ((x = fork()) > 0) { - exit(0); + if ((x = fork()) > 0) { + exit(0); } - else if (x == -1) { - perror("fork"); - fprintf(stderr, "unable to fork new process\n"); - exit(1); /* we can't do anything here, so just exit. */ - } - /* RAISE_SIGSTOP(DETACH); */ - } -#endif - + else if (x == -1) { + perror("fork"); + fprintf(stderr, "unable to fork new process\n"); + exit(1); /* we can't do anything here, so just exit. */ + } + /* RAISE_SIGSTOP(DETACH); */ #ifdef HAVE_SETSID - if ((pgrp = setsid()) == -1) { - return errno; - } + if (setsid() == -1) { + return errno; + } #elif defined(NEXT) || defined(NEWSOS) - if (setpgrp(0, getpid()) == -1 || (pgrp = getpgrp(0)) == -1) { - return errno; - } -#elif defined(OS2) || defined(TPF) - /* OS/2 don't support process group IDs */ - pgrp = getpid(); -#elif defined(MPE) - /* MPE uses negative pid for process group */ - pgrp = -getpid(); + if (setpgrp(0, getpid()) == -1) { + return errno; + } #else - if ((pgrp = setpgid(0, 0)) == -1) { - return errno; + if (setpgid(0, 0) == -1) { + return errno; + } +#endif } #endif -- Jeff Trawick | [EMAIL PROTECTED] Born in Roswell... married an alien...