]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/uclibc/lib/contrib/uclibc/test/nptl/tst-exec4.c
update
[l4.git] / l4 / pkg / uclibc / lib / contrib / uclibc / test / nptl / tst-exec4.c
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, see
18    <http://www.gnu.org/licenses/>.  */
19
20 #include <pthread.h>
21 #include <signal.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25
26
27 static void *
28 tf (void *arg)
29 {
30   /* Ignore SIGUSR1 and block SIGUSR2.  */
31   if (sigignore (SIGUSR1) != 0)
32     {
33       puts ("sigignore failed");
34       exit (1);
35     }
36
37   sigset_t ss;
38   sigemptyset (&ss);
39   sigaddset (&ss, SIGUSR2);
40   if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
41     {
42       puts ("1st run: sigmask failed");
43       exit (1);
44     }
45
46   char **oldargv = (char **) arg;
47   size_t n = 1;
48   while (oldargv[n] != NULL)
49     ++n;
50
51   char **argv = (char **) alloca ((n + 1) * sizeof (char *));
52   for (n = 0; oldargv[n + 1] != NULL; ++n)
53     argv[n] = oldargv[n + 1];
54   argv[n++] = (char *) "--direct";
55   argv[n] = NULL;
56
57   execv (argv[0], argv);
58
59   puts ("execv failed");
60
61   exit (1);
62 }
63
64
65 static int
66 do_test (int argc, char *argv[])
67 {
68   if (argc == 1)
69     {
70       /* This is the second call.  Perform the test.  */
71       struct sigaction sa;
72
73       if (sigaction (SIGUSR1, NULL, &sa) != 0)
74         {
75           puts ("2nd run: sigaction failed");
76           return 1;
77         }
78       if (sa.sa_handler != SIG_IGN)
79         {
80           puts ("SIGUSR1 not ignored");
81           return 1;
82         }
83
84       sigset_t ss;
85       if (pthread_sigmask (SIG_SETMASK, NULL, &ss) != 0)
86         {
87           puts ("2nd run: sigmask failed");
88           return 1;
89         }
90       if (! sigismember (&ss, SIGUSR2))
91         {
92           puts ("SIGUSR2 not blocked");
93           return 1;
94         }
95
96       return 0;
97     }
98
99   pthread_t th;
100   if (pthread_create (&th, NULL, tf, argv) != 0)
101     {
102       puts ("create failed");
103       exit (1);
104     }
105
106   /* This call should never return.  */
107   pthread_join (th, NULL);
108
109   puts ("join returned");
110
111   return 1;
112 }
113
114 #define TEST_FUNCTION do_test (argc, argv)
115 #include "../test-skeleton.c"