[PATCH] libc: make system() block SIGCHLD

Rich Felker dalias at aerifal.cx
Sat Jan 14 03:09:04 UTC 2012


On Wed, Jan 11, 2012 at 06:37:31PM +0100, Richard Braun wrote:
> When built with an old thread implementation (or for a sparc target),
> the implementation of the system() function doesn't conform to its
> specification. Namely, it resets the SIGCHLD handler to its default
> instead of blocking the signal, which may result in "lost" signals
> if a custom handler was installed. Replace this by appropriate calls
> to sigprocmask().

sigprocmask alone is not sufficient to implement the required behavior
for system. In particular, in a multi-threaded program, another thread
will receive the signal and reap the child, causing system to
malfunction. Really there's no safe way to use system in a
multi-threaded program (or whatsoever, IMO), but to conform to POSIX
it must block SIGCHLD:

    The system() function shall ignore the SIGINT and SIGQUIT signals,
    and shall block the SIGCHLD signal, while waiting for the command
    to terminate. If this might cause the application to miss a signal
    that would have killed it, then the application should examine the
    return value from system() and take whatever action is appropriate
    to the application if the command terminated due to receipt of a
    signal.

Source:
http://pubs.opengroup.org/onlinepubs/9699919799/functions/system.html

Rich


More information about the uClibc mailing list