]> jfr.im git - irc/unrealircd/unrealircd.git/commitdiff
Properly report failure of fork(). Reported by mbw (#5087).
authorBram Matthys <redacted>
Sat, 21 Apr 2018 18:27:53 +0000 (20:27 +0200)
committerBram Matthys <redacted>
Sat, 21 Apr 2018 18:27:53 +0000 (20:27 +0200)
src/ircd.c

index 3658a6875ecc9de116d0f03bbb081cacc66219a5..830c10a1c255cd5a44be178f861ace0ba85182c3 100644 (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;
        }