On Fri, Dec 28, 2001 at 05:35:13PM -0800, Aaron Bannert wrote: > On Fri, Dec 28, 2001 at 05:03:06PM -0800, Jos Backus wrote: > > Interestingly in the Samba code the setsid() call comes _after_ the fork() > > (see my previous e-mail) and that seems to work just fine. So it looks like > > the order suggested is not an absolute requirement; any thoughts on this? > > Let me clarify a little: > > setsid() MUST be called by a proces that is NOT a process group leader, > else it will fail with -1. Yes.
> Apache is normally started in two ways: > 1) bin/apachectl > 2) bin/httpd > > Normally when starting a program from the shell, that program becomes the > process group leader of a new process group. In case #1 the apachectl > script becomes the process leader and httpd becomes it's child (which > will inherit the PGID). This means httpd is NOT a process group leader. In > case #2, httpd IS the process group leader, and hence setsid() will fail. Yes. In the daemontools case, the supervise program forks and its child runs the ``run'' script, which in turn execs the daemon. So I'm assuming that the daemon is _not_ the pgrp leader. Consider this evidence: on my FreeBSD -current system I see the following: % ps -ax -o pid,ppid,pgid,command 246 1 46 svscan /service 273 246 46 supervise nmbd 282 246 46 supervise smbd 22124 273 22124 /usr/local/sbin/nmbd -F 22127 22124 22124 /usr/local/sbin/nmbd -F 22125 282 22125 /usr/local/sbin/smbd -F The ``run'' script (for nmbd) is simply #!/bin/sh exec /usr/local/sbin/nmbd -F The above output clearly shows {n,s}mbd running in their own pgrps, which is what we want; when I down those services using ``svc -d /service/?mbd'' they go away, without killing the members of pgrp 46. Without the -F flag/patch all the members of pgrp 46 do get killed, which is obviously undesirable. So I am really hoping that the Samba people will adopt my patch :-) > Therefore the only way to ensure that the calling process is NOT the > process group leader is to call fork() before calling setsid(). I understand. Surely there is a way to make this work with httpd also? And thank you for the clarification. -- Jos Backus _/ _/_/_/ Santa Clara, CA _/ _/ _/ _/ _/_/_/ _/ _/ _/ _/ [EMAIL PROTECTED] _/_/ _/_/_/ use Std::Disclaimer;