nis: Fix leak on realloc failure in nis_getnames [BZ #28150]
[glibc.git] / nptl / tst-exec4.c
blobd0113ccc4096b3afcc94b13f7b22e51af1598e6b
1 /* Signal handler and mask set in thread which calls exec.
2 Copyright (C) 2003-2021 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4 Contributed by Ulrich Drepper <drepper@redhat.com>, 2003.
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.
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.
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 <https://www.gnu.org/licenses/>. */
20 #include <pthread.h>
21 #include <signal.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <unistd.h>
25 #include <support/xsignal.h>
27 static void *
28 tf (void *arg)
30 /* Ignore SIGUSR1 and block SIGUSR2. */
31 xsignal (SIGUSR1, SIG_IGN);
33 sigset_t ss;
34 sigemptyset (&ss);
35 sigaddset (&ss, SIGUSR2);
36 if (pthread_sigmask (SIG_BLOCK, &ss, NULL) != 0)
38 puts ("1st run: sigmask failed");
39 exit (1);
42 char **oldargv = (char **) arg;
43 size_t n = 1;
44 while (oldargv[n] != NULL)
45 ++n;
47 char **argv = (char **) alloca ((n + 1) * sizeof (char *));
48 for (n = 0; oldargv[n + 1] != NULL; ++n)
49 argv[n] = oldargv[n + 1];
50 argv[n++] = (char *) "--direct";
51 argv[n] = NULL;
53 execv (argv[0], argv);
55 puts ("execv failed");
57 exit (1);
61 static int
62 do_test (int argc, char *argv[])
64 if (argc == 1)
66 /* This is the second call. Perform the test. */
67 struct sigaction sa;
69 if (sigaction (SIGUSR1, NULL, &sa) != 0)
71 puts ("2nd run: sigaction failed");
72 return 1;
74 if (sa.sa_handler != SIG_IGN)
76 puts ("SIGUSR1 not ignored");
77 return 1;
80 sigset_t ss;
81 if (pthread_sigmask (SIG_SETMASK, NULL, &ss) != 0)
83 puts ("2nd run: sigmask failed");
84 return 1;
86 if (! sigismember (&ss, SIGUSR2))
88 puts ("SIGUSR2 not blocked");
89 return 1;
92 return 0;
95 pthread_t th;
96 if (pthread_create (&th, NULL, tf, argv) != 0)
98 puts ("create failed");
99 exit (1);
102 /* This call should never return. */
103 pthread_join (th, NULL);
105 puts ("join returned");
107 return 1;
110 #define TEST_FUNCTION do_test (argc, argv)
111 #include "../test-skeleton.c"