1 /* Check resulting signal mask from POSIX timer using SIGEV_THREAD.
2 Copyright (C) 2020-2022 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
18
19 #include <stdio.h>
20 #include <time.h>
21 #include <signal.h>
22 #include <stdbool.h>
23
24 #include <support/check.h>
25 #include <support/test-driver.h>
26 #include <support/xthread.h>
27
28 #include <internal-signals.h>
29
30 static pthread_barrier_t barrier;
31
32 static void
thread_handler(union sigval sv)33 thread_handler (union sigval sv)
34 {
35 sigset_t ss;
36 sigprocmask (SIG_BLOCK, NULL, &ss);
37 if (test_verbose > 0)
38 printf ("%s: blocked signal mask = { ", __func__);
39 for (int sig = 1; sig < NSIG; sig++)
40 {
41 /* POSIX timers threads created to handle SIGEV_THREAD block all
42 signals except SIGKILL, SIGSTOP and glibc internals ones. */
43 if (sigismember (&ss, sig))
44 {
45 TEST_VERIFY (sig != SIGKILL && sig != SIGSTOP);
46 TEST_VERIFY (!is_internal_signal (sig));
47 }
48 if (test_verbose && sigismember (&ss, sig))
49 printf ("%d, ", sig);
50 }
51 if (test_verbose > 0)
52 printf ("}\n");
53
54 xpthread_barrier_wait (&barrier);
55 }
56
57 static int
do_test(void)58 do_test (void)
59 {
60 struct sigevent sev = { 0 };
61 sev.sigev_notify = SIGEV_THREAD;
62 sev.sigev_notify_function = &thread_handler;
63
64 timer_t timerid;
65 TEST_COMPARE (timer_create (CLOCK_REALTIME, &sev, &timerid), 0);
66
67 xpthread_barrier_init (&barrier, NULL, 2);
68
69 struct itimerspec trigger = { 0 };
70 trigger.it_value.tv_nsec = 1000000;
71 TEST_COMPARE (timer_settime (timerid, 0, &trigger, NULL), 0);
72
73 xpthread_barrier_wait (&barrier);
74
75 return 0;
76 }
77
78 #include <support/test-driver.c>
79