* intl/dcigettext.c (_nl_find_msg): Reread nconversions after
[glibc.git] / nptl / tst-signal6.c
blob85a8640027f9adbfd229f1efca093c63808ee436
1 /* Copyright (C) 2003 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
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.
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.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
20 #include <pthread.h>
21 #include <signal.h>
22 #include <stdint.h>
23 #include <stdio.h>
24 #include <stdlib.h>
25 #include <unistd.h>
28 #define N 2
29 static pthread_barrier_t bar;
30 static struct
32 void *p;
33 pthread_t s;
34 } ti[N];
35 static int sig1;
38 static void
39 handler (int sig)
41 pthread_t self = pthread_self ();
42 size_t i;
44 for (i = 0; i < N; ++i)
45 if (ti[i].s == self)
47 if ((uintptr_t) ti[i].p <= (uintptr_t) &self
48 && (uintptr_t) ti[i].p + 2 * MINSIGSTKSZ > (uintptr_t) &self)
50 puts ("alt stack not used");
51 exit (1);
54 printf ("thread %zu used alt stack for signal %d\n", i, sig);
56 return;
59 puts ("handler: thread not found");
60 exit (1);
64 static void *
65 tf (void *arg)
67 size_t nr = (uintptr_t) arg;
68 if (nr >= N)
70 puts ("wrong nr parameter");
71 exit (1);
74 sigset_t ss;
75 sigemptyset (&ss);
76 size_t i;
77 for (i = 0; i < N; ++i)
78 if (i != nr)
79 if (sigaddset (&ss, sig1 + i) != 0)
81 puts ("tf: sigaddset failed");
82 exit (1);
84 if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
86 puts ("tf: sigmask failed");
87 exit (1);
90 void *p = malloc (2 * MINSIGSTKSZ);
91 if (p == NULL)
93 puts ("tf: malloc failed");
94 exit (1);
97 stack_t s;
98 s.ss_sp = p;
99 s.ss_size = 2 * MINSIGSTKSZ;
100 s.ss_flags = 0;
101 if (sigaltstack (&s, NULL) != 0)
103 puts ("tf: sigaltstack failed");
104 exit (1);
107 ti[nr].p = p;
108 ti[nr].s = pthread_self ();
110 pthread_barrier_wait (&bar);
112 pthread_barrier_wait (&bar);
114 return NULL;
118 static int
119 do_test (void)
121 sig1 = SIGRTMIN;
122 if (sig1 + N > SIGRTMAX)
124 puts ("too few RT signals");
125 return 0;
128 struct sigaction sa;
129 sa.sa_handler = handler;
130 sa.sa_flags = 0;
131 sigemptyset (&sa.sa_mask);
133 if (sigaction (sig1, &sa, NULL) != 0
134 || sigaction (sig1 + 1, &sa, NULL) != 0
135 || sigaction (sig1 + 2, &sa, NULL) != 0)
137 puts ("sigaction failed");
138 return 1;
141 if (pthread_barrier_init (&bar, NULL, 1 + N) != 0)
143 puts ("barrier_init failed");
144 return 1;
147 pthread_t th[N];
148 size_t i;
149 for (i = 0; i < N; ++i)
150 if (pthread_create (&th[i], NULL, tf, (void *) (long int) i) != 0)
152 puts ("create failed");
153 return 1;
156 /* Block the three signals. */
157 sigset_t ss;
158 sigemptyset (&ss);
159 for (i = 0; i <= N; ++i)
160 sigaddset (&ss, sig1 + i);
161 if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
163 puts ("main: sigmask failed");
164 return 1;
167 pthread_barrier_wait (&bar);
169 /* Send some signals. */
170 pid_t me = getpid ();
171 kill (me, sig1 + N);
172 for (i = 0; i < N; ++i)
173 kill (me, sig1 + i);
174 kill (me, sig1 + N);
176 /* Give the signals a chance to be worked on. */
177 sleep (1);
179 pthread_barrier_wait (&bar);
181 for (i = 0; i < N; ++i)
182 if (pthread_join (th[i], NULL) != 0)
184 puts ("join failed");
185 return 1;
188 return 0;
191 #define TEST_FUNCTION do_test ()
192 #include "../test-skeleton.c"