Fix closing all file descriptors and logging errors
This commit is contained in:
parent
4f17e0b6d2
commit
9c3a85f824
|
@ -87,6 +87,8 @@ void daemonise(void)
|
||||||
fd = open("/dev/console", O_WRONLY | O_NOCTTY);
|
fd = open("/dev/console", O_WRONLY | O_NOCTTY);
|
||||||
if(fd == -1) {
|
if(fd == -1) {
|
||||||
LOG(LOG_WARNING, "Could not open `/dev/console' for stderr (%m).");
|
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);
|
fd = open("/dev/null", O_WRONLY);
|
||||||
}
|
}
|
||||||
switch(fd) {
|
switch(fd) {
|
||||||
|
|
|
@ -109,7 +109,8 @@ int main(int argc, char* argv[])
|
||||||
} else if(!strcmp(log_argument, "STDOUT")) {
|
} else if(!strcmp(log_argument, "STDOUT")) {
|
||||||
log_destination_set(log_destination_stdout);
|
log_destination_set(log_destination_stdout);
|
||||||
} else if(!strncmp(log_argument, "SYSLOG:", 7)) {
|
} 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);
|
log_destination_set(log_destination_syslog);
|
||||||
} else {
|
} else {
|
||||||
if(log_destination_set_file(log_argument)) {
|
if(log_destination_set_file(log_argument)) {
|
||||||
|
|
Loading…
Reference in New Issue