]> git.ipfire.org Git - thirdparty/strongswan.git/commitdiff
pluto: Do not close all file descriptors on startup, just redirect stdin, stdout...
authorTobias Brunner <tobias@strongswan.org>
Fri, 30 Jul 2010 10:16:24 +0000 (12:16 +0200)
committerTobias Brunner <tobias@strongswan.org>
Thu, 2 Sep 2010 17:04:21 +0000 (19:04 +0200)
Otherwise the pipe used to synchronize pluto->events with the main
thread would be closed.

src/pluto/plutomain.c

index 585cdae47943ca4f6eb722e2f417584ca8c55ea0..c172e8f3a5c9088e6bc4525be881c0a1568a619d 100644 (file)
@@ -626,27 +626,19 @@ int main(int argc, char **argv)
                fflush(stdout);
        }
 
-       /* Close everything but ctl_fd and (if needed) stderr.
-        * There is some danger that a library that we don't know
-        * about is using some fd that we don't know about.
-        * I guess we'll soon find out.
+       /* Redirect stdin, stdout and stderr to /dev/null
         */
        {
-               int i;
-
-               for (i = getdtablesize() - 1; i >= 0; i--)  /* Bad hack */
-               {
-                       if ((!log_to_stderr || i != 2) && i != ctl_fd)
-                               close(i);
-               }
-
-               /* make sure that stdin, stdout, stderr are reserved */
-               if (open("/dev/null", O_RDONLY) != 0)
+               int fd;
+               if ((fd = open("/dev/null", O_RDWR)) == -1)
+                       abort();
+               if (dup2(fd, 0) != 0)
                        abort();
-               if (dup2(0, 1) != 1)
+               if (dup2(fd, 1) != 1)
                        abort();
-               if (!log_to_stderr && dup2(0, 2) != 2)
+               if (!log_to_stderr && dup2(fd, 2) != 2)
                        abort();
+               close(fd);
        }
 
        init_constants();