gupascal / distcc

distcc: a fast, free distributed C/C++ compiler. Automatically exported from code.google.com/p/distcc
GNU General Public License v2.0
0 stars 0 forks source link

distccd --no-detach outlives its parent process #129

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
trunk r780 on Debian sid

Originally reported at <http://bugs.debian.org/709169>.

NoDetachDaemon_Case leaves the daemon process running.  Maybe specific to 
Debians sh (dash 0.5.7).  I shall patch this in trunk if someone confirms this 
effects other systems.

$ PATH="`pwd`:/usr/local/bin:/bin:/usr/bin" PYTHONPATH="`pwd`/test" python2.7 
Python 2.7.3 (default, Mar  5 2013, 01:19:40) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import testdistcc
>>> obj = testdistcc.NoDetachDaemon_Case()
>>> obj.setup()
>>> print obj.pid # the process reaped by killDaemon
3905
>>> print open(obj.daemon_pidfile, "r").read()
3906

>>> 

[1]+  Stopped                 PATH="`pwd`:/usr/local/bin:/bin:/usr/bin" 
PYTHONPATH="`pwd`/test" python2.7
$ ps xf | grep distccd | grep -v grep
 3905 pts/1    T      0:00  |   \_ /bin/sh -c distccd «ARGS»
 3906 pts/1    SN     0:00  |       \_ distccd «ARGS»
 3907 pts/1    SN     0:00  |           \_ distccd «ARGS»
 3908 pts/1    SN     0:00  |           \_ distccd «ARGS»
 3909 pts/1    SN     0:00  |           \_ distccd «ARGS»
$ fg
PATH="`pwd`:/usr/local/bin:/bin:/usr/bin" PYTHONPATH="`pwd`/test" python2.7

>>> obj.killDaemon()
>>> 
$ ps xf | grep distccd | grep -v grep
 3906 pts/1    SN     0:00 distccd «ARGS»
 3907 pts/1    SN     0:00  \_ distccd «ARGS»
 3908 pts/1    SN     0:00  \_ distccd «ARGS»
 3909 pts/1    SN     0:00  \_ distccd «ARGS»
$ 

The log file confirms “not detaching”.

You can see that ‘killDaemon’ reaps the shell process and the daemon 
process survives.  To me that seems strange and perhaps a bug; is there some 
reason why the daemon should outlive the shell when ‘--no-detach’ is used?

Original issue reported on code.google.com by mand...@gmail.com on 25 May 2013 at 4:51

GoogleCodeExporter commented 9 years ago
> Maybe specific to Debians sh (dash 0.5.7).

Not so.  The daemon creates its own process group, and the signal sent to the 
shell does not reach it.

Creating a process group even with --no-detach was added in 2003 by mbp.  I 
suppose because this is desirable for managing the children.  Without reworking 
the child management, --no-detach can use various non-portable ways to detect 
the death of its parent as suggested in [1].

Original comment by mand...@gmail.com on 27 May 2013 at 5:03

GoogleCodeExporter commented 9 years ago
[1] 
<http://stackoverflow.com/questions/284325/how-to-make-child-process-die-after-p
arent-exits>

The Linux suggestion of course works:
 prctl(PR_SET_PDEATHSIG, SIGHUP);

others could be use depending on the platform in a best effort approach.

Original comment by mand...@gmail.com on 27 May 2013 at 5:17