fix: closing fd's when daemonising closed our sockets, outch
authorChristian Thaeter <ct@pipapo.org>
Wed, 31 Oct 2007 05:00:55 +0000 (06:00 +0100)
committerChristian Thaeter <ct@pipapo.org>
Wed, 31 Oct 2007 05:00:55 +0000 (06:00 +0100)
src/rxpd_base.c

index 65886e6..a352ec3 100644 (file)
@@ -149,19 +149,13 @@ rxpd_enter_personality (struct rxpd_base* self)
 
   if (self->daemonize)
     {
-      struct rlimit lim;
-
-      if (getrlimit (RLIMIT_NOFILE, &lim))
-        rxpd_die ("rlimit error\n");
-
-      for (rlim_t i = 0; i < lim.rlim_max; ++i)
-        close (i);
-
       int n = open("/dev/null",O_RDWR);
       if (n < 0)
         rxpd_fail (self, "Couldn't open /dev/null\n");
-      dup(n);
-      dup(n);
+      dup2(n, 0);
+      dup2(n, 1);
+      dup2(n, 2);
+      close (n);
 
       pid_t pid = fork();
       if (pid < 0)