This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

sigprocmask issue


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

Attachment: signature.asc
Description: OpenPGP digital signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]