From 9c3a85f82465cc17788fe5d5d8d054def32f7bb2 Mon Sep 17 00:00:00 2001 From: Laurence Withers Date: Sat, 26 Jul 2008 17:38:04 +0000 Subject: [PATCH] Fix closing all file descriptors and logging errors --- src/daemonitor/400_daemon.c | 2 ++ src/daemonitor/999_main.c | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/daemonitor/400_daemon.c b/src/daemonitor/400_daemon.c index 6a9d57f..7d9540d 100644 --- a/src/daemonitor/400_daemon.c +++ b/src/daemonitor/400_daemon.c @@ -87,6 +87,8 @@ void daemonise(void) fd = open("/dev/console", O_WRONLY | O_NOCTTY); if(fd == -1) { LOG(LOG_WARNING, "Could not open `/dev/console' for stderr (%m)."); + /* force fd closed again, in case glibc kindly connected it to syslog for us */ + TEMP_FAILURE_RETRY( close(STDERR_FILENO) ); fd = open("/dev/null", O_WRONLY); } switch(fd) { diff --git a/src/daemonitor/999_main.c b/src/daemonitor/999_main.c index a920102..320ff7a 100644 --- a/src/daemonitor/999_main.c +++ b/src/daemonitor/999_main.c @@ -109,7 +109,8 @@ int main(int argc, char* argv[]) } else if(!strcmp(log_argument, "STDOUT")) { log_destination_set(log_destination_stdout); } else if(!strncmp(log_argument, "SYSLOG:", 7)) { - openlog(log_argument + 7, 0, LOG_DAEMON); + /* force syslog to be opened now, so it doesn't get opened halfway through daemonise() */ + openlog(log_argument + 7, LOG_NDELAY, LOG_DAEMON); log_destination_set(log_destination_syslog); } else { if(log_destination_set_file(log_argument)) {