On 04/29/13 12:09, Ed Maste wrote:
> If my understanding is correct your replacement test case should still
> pass even with the following change:
> 
> -  sa.sa_flags = SA_RESETHAND | SA_NODEFER;
> +  sa.sa_flags = SA_RESETHAND | SA_NODEFER | SA_SIGINFO;

Not exactly, since in that case one also needs to change
the signature of the handler, and assign to the sa_sigaction
member instead of to the sa_handler member.  Here's the
test case with those fixes.

#include <signal.h>
#include <stdio.h>
#include <unistd.h>

static void
handler (int sig, siginfo_t *info, void *context)
{
  struct sigaction sa;
  if (sigaction (SIGABRT, 0, &sa) != 0)
    perror ("handler sigaction"), _exit (1);
  if (sa.sa_flags & SA_SIGINFO)
    {
      static char const msg[] = "handler sigaction wrongly reports 
SA_SIGINFO\n";
      write (STDERR_FILENO, msg, sizeof msg - 1);
      _exit (1);
    }
  if (sa.sa_handler != SIG_DFL)
    {
      static char const msg[] = "handler sa_handler is not SIG_DFL\n";
      write (STDERR_FILENO, msg, sizeof msg - 1);
      _exit (1);
    }
}

int
main (void)
{
  struct sigaction sa;
  sa.sa_flags = SA_RESETHAND | SA_NODEFER | SA_SIGINFO;
  sa.sa_sigaction = handler;
  if (sigemptyset (&sa.sa_mask) != 0)
    return perror ("sigemptyset"), 1;
  if (sigaction (SIGABRT, &sa, 0) != 0)
    return perror ("sigaction"), 1;
  if (raise (SIGABRT) != 0)
    return perror ("raise"), 1;
  return 0;
}


Reply via email to