From 850d250442aaae413c054cf8136506e8d90f2fbe Mon Sep 17 00:00:00 2001 From: Stephen Gallagher Date: Mon, 14 Dec 2009 12:00:32 -0500 Subject: Properly close STDERR when daemonizing This is necessary so that any process managing our startup and shutdown (e.g. authconfig) does not block and stall waiting for stderr to terminate. Fixes bug https://fedorahosted.org/sssd/ticket/324 --- server/util/server.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/server/util/server.c b/server/util/server.c index 977deaeb2..e8d26dcf0 100644 --- a/server/util/server.c +++ b/server/util/server.c @@ -39,7 +39,7 @@ /******************************************************************* Close the low 3 fd's and open dev/null in their place. ********************************************************************/ -static void close_low_fds(bool stderr_too) +static void close_low_fds() { #ifndef VALGRIND int fd; @@ -47,16 +47,11 @@ static void close_low_fds(bool stderr_too) close(0); close(1); - - if (stderr_too) - close(2); + close(2); /* try and use up these file descriptors, so silly library routines writing to stdout etc won't cause havoc */ for (i=0;i<3;i++) { - if (i == 2 && !stderr_too) - continue; - fd = open("/dev/null",O_RDWR,0); if (fd < 0) fd = open("/dev/null",O_WRONLY,0); @@ -99,8 +94,7 @@ void become_daemon(bool Fork) } /* Close fd's 0,1,2. Needed if started by rsh */ - close_low_fds(false); /* Don't close stderr, let the debug system - attach it to the logfile */ + close_low_fds(); } int pidfile(const char *path, const char *name) -- cgit