]> git.proxmox.com Git - mirror_corosync.git/commitdiff
Safely redirect stderr/in/out to /dev/null to prevent fork() from crashing
authorAndrew Beekhof <abeekhof@redhat.com>
Wed, 30 Jun 2010 10:20:42 +0000 (10:20 +0000)
committerAndrew Beekhof <abeekhof@redhat.com>
Wed, 30 Jun 2010 10:20:42 +0000 (10:20 +0000)
git-svn-id: http://svn.fedorahosted.org/svn/corosync/trunk@2976 fd59a12c-fef9-0310-b244-a6a79926bd2f

exec/main.c

index 49a92f69f5170bf18b41fc75565839e67bf13779..4ddb5f2b8a050ec92a96afe03ae5fdf9a08c7b16 100644 (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)