From 452013e2097aa985bf8c3f8296d00d189401eea3 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Mon, 14 Dec 2009 15:30:48 +0100 Subject: more "obviously correct" code for secure opening of /dev/null Old code is not broken, new one merely looks "more obviously correct". Signed-off-by: Denys Vlasenko --- src/Daemon/Daemon.cpp | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'src/Daemon/Daemon.cpp') diff --git a/src/Daemon/Daemon.cpp b/src/Daemon/Daemon.cpp index 6f98966..153363d 100644 --- a/src/Daemon/Daemon.cpp +++ b/src/Daemon/Daemon.cpp @@ -623,14 +623,11 @@ static void run_main_loop(GMainLoop* loop) static void start_syslog_logging() { /* Open stdin to /dev/null */ - close(STDIN_FILENO); - xopen("/dev/null", O_RDWR); + xmove_fd(xopen("/dev/null", O_RDWR), STDIN_FILENO); /* We must not leave fds 0,1,2 closed. * Otherwise fprintf(stderr) dumps messages into random fds, etc. */ - close(STDOUT_FILENO); - close(STDERR_FILENO); - xdup(0); - xdup(0); + xdup2(STDIN_FILENO, STDOUT_FILENO); + xdup2(STDIN_FILENO, STDERR_FILENO); openlog("abrtd", 0, LOG_DAEMON); logmode = LOGMODE_SYSLOG; } -- cgit