Просмотр исходного кода

Merge trunk revision 2976:
r2976 | beekhof | 2010-06-30 03:20:42 -0700 (Wed, 30 Jun 2010) | 1 line

Safely redirect stderr/in/out to /dev/null to prevent fork() from crashing



git-svn-id: http://svn.fedorahosted.org/svn/corosync/branches/flatiron@2978 fd59a12c-fef9-0310-b244-a6a79926bd2f

Steven Dake 15 лет назад
Родитель
Сommit
2866596e68
1 измененных файлов с 3 добавлено и 21 удалено
  1. 3 21
      exec/main.c

+ 3 - 21
exec/main.c

@@ -394,8 +394,6 @@ static void priv_drop (void)
 
 static void corosync_tty_detach (void)
 {
-	int fd;
-
 	/*
 	 * Disconnect from TTY if this is not a debug run
 	 */
@@ -408,11 +406,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);
@@ -425,20 +418,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)