startup: Check return value of open /dev/null. Don't fclose stdin/stdout/stderr.
Open /dev/null for standard fds earlier, so a failure can be reported. Do not fclose stdin/stdout/stderr but just overwrite the fds with /dev/null.
This commit is contained in:
parent
0391874cc7
commit
b45b2daef9
1 changed files with 17 additions and 6 deletions
23
src/ircd.c
23
src/ircd.c
|
@ -155,6 +155,19 @@ ircd_shutdown(const char *reason)
|
|||
static void
|
||||
print_startup(int pid)
|
||||
{
|
||||
int fd;
|
||||
|
||||
close(1);
|
||||
fd = open("/dev/null", O_RDWR);
|
||||
if (fd == -1) {
|
||||
perror("open /dev/null");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
if (fd == 0)
|
||||
fd = dup(fd);
|
||||
if (fd != 1)
|
||||
abort();
|
||||
|
||||
inotice("now running in %s mode from %s as pid %d ...",
|
||||
!server_state_foreground ? "background" : "foreground",
|
||||
ConfigFileEntry.dpath, pid);
|
||||
|
@ -163,12 +176,10 @@ print_startup(int pid)
|
|||
* -- jilles */
|
||||
if (!server_state_foreground)
|
||||
write(0, ".", 1);
|
||||
fclose(stdin);
|
||||
fclose(stdout);
|
||||
fclose(stderr);
|
||||
open("/dev/null", O_RDWR);
|
||||
dup2(0, 1);
|
||||
dup2(0, 2);
|
||||
if (dup2(1, 0) == -1)
|
||||
abort();
|
||||
if (dup2(1, 2) == -1)
|
||||
abort();
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue