From fcf27783176389af0ee1ca89d2a2495d4e1bfe62 Mon Sep 17 00:00:00 2001 From: Roy Marples Date: Thu, 28 Feb 2008 21:47:45 +0000 Subject: Don't leak fd's. --- src/rc/rc-logger.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/rc/rc-logger.c b/src/rc/rc-logger.c index 7344608..3e02a1a 100644 --- a/src/rc/rc-logger.c +++ b/src/rc/rc-logger.c @@ -169,6 +169,12 @@ void rc_logger_open (const char *level) if (openpty (&rc_logger_tty, &slave_tty, NULL, &tt, &ws)) return; + if ((s = fcntl (rc_logger_tty, F_GETFD, 0)) == 0) + fcntl (rc_logger_tty, F_SETFD, s | FD_CLOEXEC); + + if ((s = fcntl (slave_tty, F_GETFD, 0)) == 0) + fcntl (slave_tty, F_SETFD, s | FD_CLOEXEC); + rc_logger_pid = fork (); switch (rc_logger_pid) { case -1: @@ -249,6 +255,11 @@ void rc_logger_open (const char *level) setpgid (rc_logger_pid, 0); fd_stdout = dup (STDOUT_FILENO); fd_stderr = dup (STDERR_FILENO); + if ((s = fcntl (fd_stdout, F_GETFD, 0)) == 0) + fcntl (fd_stdout, F_SETFD, s | FD_CLOEXEC); + + if ((s = fcntl (fd_stderr, F_GETFD, 0)) == 0) + fcntl (fd_stderr, F_SETFD, s | FD_CLOEXEC); dup2 (slave_tty, STDOUT_FILENO); dup2 (slave_tty, STDERR_FILENO); if (slave_tty != STDIN_FILENO && -- cgit v1.2.3