Fix closing all file descriptors and logging errors

This commit is contained in:
Laurence Withers 2008-07-26 17:38:04 +00:00
parent 4f17e0b6d2
commit 9c3a85f824
2 changed files with 4 additions and 1 deletions

View File

@ -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) {

View File

@ -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)) {