1
0
mirror of https://github.com/unrealircd/unrealircd.git synced 2026-07-08 07:43:14 +02:00

Properly report failure of fork(). Reported by mbw (#5087).

This commit is contained in:
Bram Matthys
2018-04-21 20:27:53 +02:00
parent 74009b88ba
commit f0092fef4e
+14 -2
View File
@@ -1408,9 +1408,21 @@ int InitUnrealIRCd(int argc, char *argv[])
#if !defined(_AMIGA) && !defined(_WIN32) && !defined(NO_FORKING)
if (!(bootopt & BOOT_NOFORK))
{
close_std_descriptors();
if (fork())
pid_t p;
p = fork();
if (p < 0)
{
fprintf(stderr, "Could not create background job. Call to fork() failed: %s\n",
strerror(errno));
exit(-1);
}
if (p > 0)
{
/* Background job created and we are the parent. We can terminate. */
exit(0);
}
/* Background process (child) continues below... */
close_std_descriptors();
fd_fork();
loop.ircd_forked = 1;
}