1/* Copyright (C) 2003-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library 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 GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18#include <errno.h>
19#include <pthread.h>
20#include <signal.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <unistd.h>
25#include <sys/mman.h>
26#include <sys/wait.h>
27
28
29static sigset_t ss;
30
31
32static void *
33tf (void *arg)
34{
35 sigset_t ss2;
36 if (pthread_sigmask (SIG_SETMASK, NULL, oldmask: &ss2) != 0)
37 {
38 puts (s: "child: sigmask failed");
39 exit (1);
40 }
41
42 int i;
43 for (i = 1; i < 32; ++i)
44 if (sigismember (&ss, i) && ! sigismember (&ss2, i))
45 {
46 printf (format: "signal %d set in parent mask, but not in child\n", i);
47 exit (1);
48 }
49 else if (! sigismember (&ss, i) && sigismember (&ss2, i))
50 {
51 printf (format: "signal %d set in child mask, but not in parent\n", i);
52 exit (1);
53 }
54
55 return NULL;
56}
57
58
59static int
60do_test (void)
61{
62 sigemptyset (&ss);
63 sigaddset (&ss, SIGUSR1);
64 if (pthread_sigmask (SIG_SETMASK, newmask: &ss, NULL) != 0)
65 {
66 puts (s: "1st sigmask failed");
67 exit (1);
68 }
69
70 pthread_t th;
71 if (pthread_create (newthread: &th, NULL, start_routine: tf, NULL) != 0)
72 {
73 puts (s: "1st create failed");
74 exit (1);
75 }
76
77 void *r;
78 if (pthread_join (th: th, thread_return: &r) != 0)
79 {
80 puts (s: "1st join failed");
81 exit (1);
82 }
83
84 sigemptyset (&ss);
85 sigaddset (&ss, SIGUSR2);
86 sigaddset (&ss, SIGFPE);
87 if (pthread_sigmask (SIG_SETMASK, newmask: &ss, NULL) != 0)
88 {
89 puts (s: "2nd sigmask failed");
90 exit (1);
91 }
92
93 if (pthread_create (newthread: &th, NULL, start_routine: tf, NULL) != 0)
94 {
95 puts (s: "2nd create failed");
96 exit (1);
97 }
98
99 if (pthread_join (th: th, thread_return: &r) != 0)
100 {
101 puts (s: "2nd join failed");
102 exit (1);
103 }
104
105 return 0;
106}
107
108#define TEST_FUNCTION do_test ()
109#include "../test-skeleton.c"
110

source code of glibc/sysdeps/pthread/tst-signal5.c