[tpop3d-discuss] fork failure failure

Jonathan jonathan at woaf.net
Tue, 26 Aug 2003 10:38:02 +0100


--Boundary-00=_6pyS/9F+2C+Jxlo
Content-Type: text/plain;
  charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

If fork returns -1 in fork_child post_fork is never set to 0. This leads to 
the main process happily calling _exit believing itself to be a child. The 
attached patch should fix it.

-- 
Jonathan Oddy
Woaf Tech Ltd.
--Boundary-00=_6pyS/9F+2C+Jxlo
Content-Type: text/x-diff;
  charset="iso-8859-1";
  name="fix-fork_child-forkerror.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="fix-fork_child-forkerror.diff"

Index: netloop.c
===================================================================
RCS file: /home/chris/vcvs/repos/tpop3d/netloop.c,v
retrieving revision 1.7
diff -u -r1.7 netloop.c
--- netloop.c	1 Aug 2003 12:11:38 -0000	1.7
+++ netloop.c	25 Aug 2003 12:49:23 -0000
@@ -291,8 +291,10 @@
 
         case -1:
             /* Error. */
+	    post_fork = 0;
             log_print(LOG_ERR, "fork_child: fork: %m");
             connection_sendresponse(c, 0, _("Everything was fine until now, but suddenly I realise I just can't go on. Sorry."));
+	    sigprocmask(SIG_UNBLOCK, &chmask, NULL);
             return 0;
 
         default:
@@ -385,7 +387,7 @@
                             if (!fork_child(c))
                                 c->do_shutdown = 1;
                             /* If this is the parent process, c has now been destroyed. */
-                            if (!post_fork)
+			    else if (!post_fork)
                                 c = NULL;
                         }
                         break;

--Boundary-00=_6pyS/9F+2C+Jxlo--