1 /* Test of sigprocmask.
2 Copyright (C) 2011-2020 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2011. */
23 #include "signature.h"
24 SIGNATURE_CHECK (sigprocmask
, int, (int, const sigset_t
*, sigset_t
*));
33 #if !(defined _WIN32 && !defined __CYGWIN__)
35 static volatile int sigint_occurred
;
38 sigint_handler (int sig
)
44 main (int argc
, char *argv
[])
47 pid_t pid
= getpid ();
50 if (sizeof (int) < sizeof pid
&& 0x7fffffff < pid
)
52 fputs ("Skipping test: pid too large\n", stderr
);
56 signal (SIGINT
, sigint_handler
);
59 sigaddset (&set
, SIGINT
);
61 /* Check error handling. */
62 ASSERT (sigprocmask (1729, &set
, NULL
) == -1);
63 ASSERT (errno
== EINVAL
);
66 ASSERT (sigprocmask (SIG_BLOCK
, &set
, NULL
) == 0);
68 /* Request a SIGINT signal from outside. */
69 sprintf (command
, "sh -c 'sleep 1; kill -%d %d' &", SIGINT
, (int) pid
);
70 ASSERT (system (command
) == 0);
75 /* The signal should not have arrived yet, because it is blocked. */
76 ASSERT (sigint_occurred
== 0);
79 ASSERT (sigprocmask (SIG_UNBLOCK
, &set
, NULL
) == 0);
81 /* The signal should have arrived now, because POSIX says
82 "If there are any pending unblocked signals after the call to
83 sigprocmask(), at least one of those signals shall be delivered
84 before the call to sigprocmask() returns." */
85 ASSERT (sigint_occurred
== 1);
92 /* On native Windows, getpid() values and the arguments that are passed to
93 the (Cygwin?) 'kill' program are not necessarily related. */
98 fputs ("Skipping test: native Windows platform\n", stderr
);