[distcc] Problem with zeroconf daemonization

Benjamin R. Haskell distcc at benizi.com
Sun Jan 17 23:10:05 MST 2010

'paludis' is a package manager for Gentoo Linux (and Exherbo).  I sent 
an email to the 'paludis' users list about a problem with waiting for 
the distcc zeroconf daemon to stop.

link: http://lists.pioto.org/pipermail/paludis-user/2010-January/001250.html

I use 'distcc -j' to set up my MAKEOPTS variable.  The problem is with a 
wrapper used to prefix output for paludis with a tag indicating its 
origin.  When using '+zeroconf' in DISTCC_HOSTS, paludis waits 20 
seconds for distcc unconditionally, because distcc doesn't close the 
extra file descriptors that are open due to this output munging.  (So, 
'paludis' waits on the grandchild daemon process that holds those fd's 

I stated in that message that I feel like this is a problem with the way 
distcc daemonizes (and not with the way paludis wraps output).  I'm not 
as certain of that as I felt a couple hours ago, but it still feels 
accurate (that the daemonizing process has the responsibility to close 
any open fd's it's not going to use).

If so, it seems like a pretty easy fix (to just close more fd's than 0, 
1, and 2).  I can commit the attached patch if 1024 doesn't seem too 
magic-number-y (and I'm not spouting nonsense).

-------------- next part --------------
Index: src/zeroconf.c
--- src/zeroconf.c	(revision 711)
+++ src/zeroconf.c	(working copy)
@@ -583,10 +583,11 @@
             int fd;
             /* Child */
-            /* Close file descriptors and replace them by /dev/null */
-            close(0);
-            close(1);
-            close(2);
+            /* Close file descriptors */
+            for (fd = 0; fd < 1024; fd++) {
+                close(fd);
+            }
+            /* Replace std{in/out/err} by /dev/null */
             fd = open("/dev/null", O_RDWR);
             assert(fd == 0);
             fd = dup(0);

More information about the distcc mailing list