aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2010-07-30 12:16:24 +0200
committerTobias Brunner <tobias@strongswan.org>2010-09-02 19:04:21 +0200
commitc3f4d68f0dae9844a80fec65b50670c1a0f53802 (patch)
tree27e3d578db71d3ac7d72f84f1d0e1a9c9df4f439
parent8808edfb4c0d8761ba7db9508823cf7004684707 (diff)
downloadstrongswan-c3f4d68f0dae9844a80fec65b50670c1a0f53802.tar.bz2
strongswan-c3f4d68f0dae9844a80fec65b50670c1a0f53802.tar.xz
pluto: Do not close all file descriptors on startup, just redirect stdin, stdout and stderr to /dev/null.
Otherwise the pipe used to synchronize pluto->events with the main thread would be closed.
-rw-r--r--src/pluto/plutomain.c24
1 files changed, 8 insertions, 16 deletions
diff --git a/src/pluto/plutomain.c b/src/pluto/plutomain.c
index 585cdae47..c172e8f3a 100644
--- a/src/pluto/plutomain.c
+++ b/src/pluto/plutomain.c
@@ -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();