0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-06-28 14:58:20 +02:00

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:
Jilles Tjoelker 2014-02-23 21:51:19 +01:00
parent 0391874cc7
commit b45b2daef9

View file

@ -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();
}
/*