Re: [exim-dev] can waitpid() fail?

Top Page
Delete this message
Reply to this message
Author: Michael Haardt
Date:  
To: exim-dev
Subject: Re: [exim-dev] can waitpid() fail?
> pid = fork();
>    if (pid == 0)
>      { 3 lines of code }
>    while (waitpid(pid, &status, 0) != pid);

>
> Er wait, I *can* see how it can go wrong. If fork() fails ...


Don't forget EINTR, either.

I don't know how Exim deals with SIGCHLD, but from the Linux manual:

       POSIX.1-2001  specifies  that  if  the disposition of SIGCHLD is set to
       SIG_IGN or the SA_NOCLDWAIT flag is set for SIGCHLD (see sigaction(2)),
       then children that terminate do not become zombies and a call to wait()
       or waitpid() will block until all children have  terminated,  and  then
       fail  with  errno set to ECHILD.  (The original POSIX standard left the
       behaviour of setting SIGCHLD to SIG_IGN unspecified.)  Linux  2.6  con-
       forms  to  this  specification.   However, Linux 2.4 (and earlier) does
       not: if a wait() or waitpid() call  is  made  while  SIGCHLD  is  being
       ignored,  the  call  behaves  just  as  though  SIGCHLD  were not being
       ingored, that is, the call blocks until the next child  terminates  and
       then returns the process ID and status of that child.


I can check a bunch other systems RSN, but to be safe, I suggest to just
deal with waitpid() returning -1, ignoring the condition for anything
but EINTR.

Michael