sigprocmask issue

Eric Blake eblake@redhat.com
Tue Jan 1 00:19:00 GMT 2013


I'm reporting this now because gnulib unit tests found a failure in
stock cygwin 1.7.17, but I'm still investigating whether it is a
regression, and/or whether it has been fixed by snapshots.  This
relatively simple test case asserts that SIGINT is never delivered as
required.

#include <signal.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <assert.h>

static volatile int sigint_occurred;

static void
sigint_handler (int sig)
{
  sigint_occurred++;
}

int
main (int argc, char *argv[])
{
  sigset_t set;
  pid_t pid = getpid ();
  char command[80];

  signal (SIGINT, sigint_handler);

  sigemptyset (&set);
  sigaddset (&set, SIGINT);

  /* Check error handling.  */
  assert (sigprocmask (1729, &set, NULL) == -1);
  assert (errno == EINVAL);

  /* Block SIGINT.  */
  assert (sigprocmask (SIG_BLOCK, &set, NULL) == 0);

  /* Request a SIGINT signal from outside.  */
  printf ("running \"sh -c 'sleep 1; kill -%d %d' &\"\n", SIGINT, (int)
pid);
  sprintf (command, "sh -c 'sleep 1; kill -%d %d' &", SIGINT, (int) pid);
  assert (system (command) == 0);

  /* Wait.  */
  puts ("waiting");
  sleep (2);

  /* The signal should not have arrived yet, because it is blocked.  */
  assert (sigint_occurred == 0);

  /* Unblock SIGINT.  */
  puts ("unblocking");
  assert (sigprocmask (SIG_UNBLOCK, &set, NULL) == 0);

  /* The signal should have arrived now, because POSIX says
       "If there are any pending unblocked signals after the call to
        sigprocmask(), at least one of those signals shall be delivered
        before the call to sigprocmask() returns."  */
  assert (sigint_occurred == 1);

  return 0;
}


-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 619 bytes
Desc: OpenPGP digital signature
URL: <http://cygwin.com/pipermail/cygwin/attachments/20130101/97f188c7/attachment.sig>


More information about the Cygwin mailing list