|
Packit Service |
a2ae7a |
/* Test of sigprocmask.
|
|
Packit Service |
a2ae7a |
Copyright (C) 2011-2019 Free Software Foundation, Inc.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
This program is free software: you can redistribute it and/or modify
|
|
Packit Service |
a2ae7a |
it under the terms of the GNU General Public License as published by
|
|
Packit Service |
a2ae7a |
the Free Software Foundation; either version 3 of the License, or
|
|
Packit Service |
a2ae7a |
(at your option) any later version.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
This program is distributed in the hope that it will be useful,
|
|
Packit Service |
a2ae7a |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit Service |
a2ae7a |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
Packit Service |
a2ae7a |
GNU General Public License for more details.
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
You should have received a copy of the GNU General Public License
|
|
Packit Service |
a2ae7a |
along with this program. If not, see <https://www.gnu.org/licenses/>. */
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Written by Bruno Haible <bruno@clisp.org>, 2011. */
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <config.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <signal.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include "signature.h"
|
|
Packit Service |
a2ae7a |
SIGNATURE_CHECK (sigprocmask, int, (int, const sigset_t *, sigset_t *));
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include <errno.h>
|
|
Packit Service |
a2ae7a |
#include <stdio.h>
|
|
Packit Service |
a2ae7a |
#include <stdlib.h>
|
|
Packit Service |
a2ae7a |
#include <unistd.h>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#include "macros.h"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#if !(defined _WIN32 && !defined __CYGWIN__)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
static volatile int sigint_occurred;
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
static void
|
|
Packit Service |
a2ae7a |
sigint_handler (int sig)
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
sigint_occurred++;
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
int
|
|
Packit Service |
a2ae7a |
main (int argc, char *argv[])
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
sigset_t set;
|
|
Packit Service |
a2ae7a |
pid_t pid = getpid ();
|
|
Packit Service |
a2ae7a |
char command[80];
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
if (sizeof (int) < sizeof pid && 0x7fffffff < pid)
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
fputs ("Skipping test: pid too large\n", stderr);
|
|
Packit Service |
a2ae7a |
return 77;
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
signal (SIGINT, sigint_handler);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
sigemptyset (&set);
|
|
Packit Service |
a2ae7a |
sigaddset (&set, SIGINT);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Check error handling. */
|
|
Packit Service |
a2ae7a |
ASSERT (sigprocmask (1729, &set, NULL) == -1);
|
|
Packit Service |
a2ae7a |
ASSERT (errno == EINVAL);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Block SIGINT. */
|
|
Packit Service |
a2ae7a |
ASSERT (sigprocmask (SIG_BLOCK, &set, NULL) == 0);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Request a SIGINT signal from outside. */
|
|
Packit Service |
a2ae7a |
sprintf (command, "sh -c 'sleep 1; kill -%d %d' &", SIGINT, (int) pid);
|
|
Packit Service |
a2ae7a |
ASSERT (system (command) == 0);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Wait. */
|
|
Packit Service |
a2ae7a |
sleep (2);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* The signal should not have arrived yet, because it is blocked. */
|
|
Packit Service |
a2ae7a |
ASSERT (sigint_occurred == 0);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* Unblock SIGINT. */
|
|
Packit Service |
a2ae7a |
ASSERT (sigprocmask (SIG_UNBLOCK, &set, NULL) == 0);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* The signal should have arrived now, because POSIX says
|
|
Packit Service |
a2ae7a |
"If there are any pending unblocked signals after the call to
|
|
Packit Service |
a2ae7a |
sigprocmask(), at least one of those signals shall be delivered
|
|
Packit Service |
a2ae7a |
before the call to sigprocmask() returns." */
|
|
Packit Service |
a2ae7a |
ASSERT (sigint_occurred == 1);
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
return 0;
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#else
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
/* On native Windows, getpid() values and the arguments that are passed to
|
|
Packit Service |
a2ae7a |
the (Cygwin?) 'kill' program are not necessarily related. */
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
int
|
|
Packit Service |
a2ae7a |
main ()
|
|
Packit Service |
a2ae7a |
{
|
|
Packit Service |
a2ae7a |
fputs ("Skipping test: native Windows platform\n", stderr);
|
|
Packit Service |
a2ae7a |
return 77;
|
|
Packit Service |
a2ae7a |
}
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
#endif
|