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
This commit is contained in:
Andrew Beekhof 2010-06-30 10:20:42 +00:00
parent cf0d63aa3f
commit 0883fc877b

View File

@ -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)