From 0883fc877b618247a6702a6c0ac4a11ba1b43f1b Mon Sep 17 00:00:00 2001 From: Andrew Beekhof Date: Wed, 30 Jun 2010 10:20:42 +0000 Subject: [PATCH] Safely redirect stderr/in/out to /dev/null to prevent fork() from crashing git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2976 fd59a12c-fef9-0310-b244-a6a79926bd2f --- exec/main.c | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) diff --git a/exec/main.c b/exec/main.c index 49a92f69..4ddb5f2b 100644 --- a/exec/main.c +++ b/exec/main.c @@ -471,8 +471,6 @@ static void priv_drop (void) static void corosync_tty_detach (void) { - int fd; - /* * Disconnect from TTY if this is not a debug run */ @@ -485,11 +483,6 @@ static void corosync_tty_detach (void) /* * child which is disconnected, run this process */ -/* setset(); - close (0); - close (1); - close (2); -*/ break; default: exit (0); @@ -502,20 +495,9 @@ static void corosync_tty_detach (void) /* * Map stdin/out/err to /dev/null. */ - fd = open("/dev/null", O_RDWR); - if (fd >= 0) { - /* dup2 to 0 / 1 / 2 (stdin / stdout / stderr) */ - close (STDIN_FILENO); - close (STDOUT_FILENO); - close (STDERR_FILENO); - dup2(fd, STDIN_FILENO); /* 0 */ - dup2(fd, STDOUT_FILENO); /* 1 */ - dup2(fd, STDERR_FILENO); /* 2 */ - - /* Should be 0, but just in case it isn't... */ - if (fd > 2) - close(fd); - } + freopen("/dev/null", "r", stdin); + freopen("/dev/null", "a", stderr); + freopen("/dev/null", "a", stdout); } static void corosync_mlockall (void)