1 /* Test of pthread_sigmask in a single-threaded program.
2 Copyright (C) 2011-2023 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 (pthread_sigmask
, int, (int, const sigset_t
*, sigset_t
*));
34 #if !(defined _WIN32 && !defined __CYGWIN__)
36 static volatile int sigint_occurred
;
39 sigint_handler (_GL_UNUSED
int sig
)
48 intmax_t pid
= getpid ();
51 signal (SIGINT
, sigint_handler
);
54 sigaddset (&set
, SIGINT
);
56 /* Check error handling. */
57 ASSERT (pthread_sigmask (1729, &set
, NULL
) == EINVAL
);
60 ASSERT (pthread_sigmask (SIG_BLOCK
, &set
, NULL
) == 0);
62 /* Request a SIGINT signal from outside. */
63 sprintf (command
, "sh -c 'sleep 1; kill -INT %"PRIdMAX
"' &", pid
);
64 ASSERT (system (command
) == 0);
69 /* The signal should not have arrived yet, because it is blocked. */
70 ASSERT (sigint_occurred
== 0);
73 ASSERT (pthread_sigmask (SIG_UNBLOCK
, &set
, NULL
) == 0);
75 /* The signal should have arrived now, because POSIX says
76 "If there are any pending unblocked signals after the call to
77 pthread_sigmask(), at least one of those signals shall be delivered
78 before the call to pthread_sigmask() returns." */
79 ASSERT (sigint_occurred
== 1);
86 /* On native Windows, getpid() values and the arguments that are passed to
87 the (Cygwin?) 'kill' program are not necessarily related. */
92 fputs ("Skipping test: native Windows platform\n", stderr
);