[patch] detach from controlling tty in non-debug mode

Florian Lohoff flo at rfc822.org
Wed Jun 20 09:25:42 CEST 2007


Hi,
bird needs something like this because in case it daemonizes it still
keeps the fds open of the controlling tty which is bad in case you'd
like to log out which then will hang.

I already opened a Debian Bug - See:

	http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=427772

Flo

diff -Nur bird-1.0.11/sysdep/unix/main.c bird-1.0.11.flo/sysdep/unix/main.c
--- bird-1.0.11/sysdep/unix/main.c	2007-06-20 09:13:21.000000000 +0200
+++ bird-1.0.11.flo/sysdep/unix/main.c	2007-06-20 09:21:00.000000000 +0200
@@ -434,7 +434,18 @@
 	die("fork: %m");
       if (pid)
 	return 0;
+
       setsid();
+
+      /* Close all FDs and thus detach from controlling tty */
+      for (i=getdtablesize();i>=0;--i)
+        close(i);
+
+      /* create harmless stdin/out/err */
+      i=open("/dev/null",O_RDWR);
+      dup(i);
+      dup(i);
+
     }
 
   signal_init();
-- 
Florian Lohoff                  flo at rfc822.org             +49-171-2280134
	Those who would give up a little freedom to get a little 
          security shall soon have neither - Benjamin Franklin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://trubka.network.cz/pipermail/bird-users/attachments/20070620/1acbdbfb/attachment.asc>


More information about the Bird-users mailing list