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
|
static void
|
||||||
print_startup(int pid)
|
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 ...",
|
inotice("now running in %s mode from %s as pid %d ...",
|
||||||
!server_state_foreground ? "background" : "foreground",
|
!server_state_foreground ? "background" : "foreground",
|
||||||
ConfigFileEntry.dpath, pid);
|
ConfigFileEntry.dpath, pid);
|
||||||
|
@ -163,12 +176,10 @@ print_startup(int pid)
|
||||||
* -- jilles */
|
* -- jilles */
|
||||||
if (!server_state_foreground)
|
if (!server_state_foreground)
|
||||||
write(0, ".", 1);
|
write(0, ".", 1);
|
||||||
fclose(stdin);
|
if (dup2(1, 0) == -1)
|
||||||
fclose(stdout);
|
abort();
|
||||||
fclose(stderr);
|
if (dup2(1, 2) == -1)
|
||||||
open("/dev/null", O_RDWR);
|
abort();
|
||||||
dup2(0, 1);
|
|
||||||
dup2(0, 2);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue