1 | /* Signal handler and mask set in thread which calls exec.
|
---|
2 | Copyright (C) 2003 Free Software Foundation, Inc.
|
---|
3 | This file is part of the GNU C Library.
|
---|
4 | Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
|
---|
5 |
|
---|
6 | The GNU C Library is free software; you can redistribute it and/or
|
---|
7 | modify it under the terms of the GNU Lesser General Public
|
---|
8 | License as published by the Free Software Foundation; either
|
---|
9 | version 2.1 of the License, or (at your option) any later version.
|
---|
10 |
|
---|
11 | The GNU C Library is distributed in the hope that it will be useful,
|
---|
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
14 | Lesser General Public License for more details.
|
---|
15 |
|
---|
16 | You should have received a copy of the GNU Lesser General Public
|
---|
17 | License along with the GNU C Library; if not, write to the Free
|
---|
18 | Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
---|
19 | 02111-1307 USA. */
|
---|
20 |
|
---|
21 | #include <pthread.h>
|
---|
22 | #include <signal.h>
|
---|
23 | #include <stdio.h>
|
---|
24 | #include <stdlib.h>
|
---|
25 | #include <unistd.h>
|
---|
26 |
|
---|
27 |
|
---|
28 | static void *
|
---|
29 | tf (void *arg)
|
---|
30 | {
|
---|
31 | /* Ignore SIGUSR1 and block SIGUSR2. */
|
---|
32 | if (sigignore (SIGUSR1) != 0)
|
---|
33 | {
|
---|
34 | puts ("sigignore failed");
|
---|
35 | exit (1);
|
---|
36 | }
|
---|
37 |
|
---|
38 | sigset_t ss;
|
---|
39 | sigemptyset (&ss);
|
---|
40 | sigaddset (&ss, SIGUSR2);
|
---|
41 | if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
|
---|
42 | {
|
---|
43 | puts ("1st run: sigmask failed");
|
---|
44 | exit (1);
|
---|
45 | }
|
---|
46 |
|
---|
47 | char **oldargv = (char **) arg;
|
---|
48 | size_t n = 1;
|
---|
49 | while (oldargv[n] != NULL)
|
---|
50 | ++n;
|
---|
51 |
|
---|
52 | char **argv = (char **) alloca ((n + 1) * sizeof (char *));
|
---|
53 | for (n = 0; oldargv[n + 1] != NULL; ++n)
|
---|
54 | argv[n] = oldargv[n + 1];
|
---|
55 | argv[n++] = (char *) "--direct";
|
---|
56 | argv[n] = NULL;
|
---|
57 |
|
---|
58 | execv (argv[0], argv);
|
---|
59 |
|
---|
60 | puts ("execv failed");
|
---|
61 |
|
---|
62 | exit (1);
|
---|
63 | }
|
---|
64 |
|
---|
65 |
|
---|
66 | static int
|
---|
67 | do_test (int argc, char *argv[])
|
---|
68 | {
|
---|
69 | if (argc == 1)
|
---|
70 | {
|
---|
71 | /* This is the second call. Perform the test. */
|
---|
72 | struct sigaction sa;
|
---|
73 |
|
---|
74 | if (sigaction (SIGUSR1, NULL, &sa) != 0)
|
---|
75 | {
|
---|
76 | puts ("2nd run: sigaction failed");
|
---|
77 | return 1;
|
---|
78 | }
|
---|
79 | if (sa.sa_handler != SIG_IGN)
|
---|
80 | {
|
---|
81 | puts ("SIGUSR1 not ignored");
|
---|
82 | return 1;
|
---|
83 | }
|
---|
84 |
|
---|
85 | sigset_t ss;
|
---|
86 | if (pthread_sigmask (SIG_SETMASK, NULL, &ss) != 0)
|
---|
87 | {
|
---|
88 | puts ("2nd run: sigmask failed");
|
---|
89 | return 1;
|
---|
90 | }
|
---|
91 | if (! sigismember (&ss, SIGUSR2))
|
---|
92 | {
|
---|
93 | puts ("SIGUSR2 not blocked");
|
---|
94 | return 1;
|
---|
95 | }
|
---|
96 |
|
---|
97 | return 0;
|
---|
98 | }
|
---|
99 |
|
---|
100 | pthread_t th;
|
---|
101 | if (pthread_create (&th, NULL, tf, argv) != 0)
|
---|
102 | {
|
---|
103 | puts ("create failed");
|
---|
104 | exit (1);
|
---|
105 | }
|
---|
106 |
|
---|
107 | /* This call should never return. */
|
---|
108 | pthread_join (th, NULL);
|
---|
109 |
|
---|
110 | puts ("join returned");
|
---|
111 |
|
---|
112 | return 1;
|
---|
113 | }
|
---|
114 |
|
---|
115 | #define TEST_FUNCTION do_test (argc, argv)
|
---|
116 | #include "../test-skeleton.c"
|
---|