bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sigaction, SA_SIGINFO, and SIG_IGN


From: Paul Eggert
Subject: Re: sigaction, SA_SIGINFO, and SIG_IGN
Date: Thu, 19 Jun 2008 11:52:36 -0700
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.2 (gnu/linux)

Bruno Haible <address@hidden> writes:

>         if (sigaction (fatal_signals[i], NULL, &action) >= 0
> +           /* POSIX says that SIG_IGN can only occur when action.sa_flags
> +              does not contain SA_SIGINFO.  But in Linux 2.4, for example,
> +              SA_SIGINFO can actually be set and is ignored when sa_handler
> +              is SIG_IGN.  So don't bother testing for SA_SIGINFO.  */
>             && action.sa_handler == SIG_IGN)
>           fatal_signals[i] = -1;

I'd feel a bit safer if we wrote the code to conform to POSIX rather
than assume the typical implementation where sa_handler and
sa_sigaction overlap.  How about something like this instead?

  if (sigaction (fatal_signals[i], NULL, &action) == 0
      && ((action.sa_flags & SA_SIGINFO
           ? (void (*) (int)) action.sa_sigaction
           : action.sa_handler)
          == SIG_IGN))
    fatal_signals[i] = -1;

This avoids undefined behavior from the point of view of C,
while remaining portable to implementations where sa_handler
and sa_sigaction don't overlap.  On typical implementations
with a good optimizing compiler, this code should run just
as fast as what's in there now.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]