Re: Another patch to make syslogd work on svr4,4.2,5

From: John Hughes (john@Calva.COM)
Date: Sat Dec 01 2001 - 10:54:23 CET


The reapchild code looked like this:

void reapchild()
{
        int saved_errno = errno;
#if defined(SYSV) && !defined(linux)
        (void) signal(SIGCHLD, reapchild); /* reset signal handler -ASP
*/
        wait ((int *)0);
#else
        union wait status;

        while (wait3(&status, WNOHANG, (struct rusage *) NULL) > 0)
                ;
#endif
#ifdef linux
        (void) signal(SIGCHLD, reapchild); /* reset signal handler -ASP
*/
#endif
        errno = saved_errno;
}

Notice that on non-linux SYSV it resets the signal before
doing the wait - this is a no-no 'cos on return from signal
it'll see that there is a dead child, and a handler for
SIGCHLD so it'll call the handler again, which calls
signal to reset the handler, which will call the handler
again...

Instant infinite recursion & stack blowup.

My patch uses the sigaction syscall instead of signal so we
don't have to worry about the differences between SYSV and
BSD signal semantics and waitpid instead of wait/wait3 so
we can use the same code on SYSV, Linux and BSD.

Also it gets rid of #ifdefs, a good thing IMNSHO.

Questions?



This archive was generated by hypermail 2.1.2 : Sat Dec 01 2001 - 10:56:18 CET