elf: Ignore LD_PROFILE for setuid binaries
[glibc.git] / signal / tst-sigwait-eintr.c
bloba322125deb4edd204139797edb036907ce0c6772
1 /* Check that sigwait does not fail with EINTR (bug 22478).
2 Copyright (C) 2017-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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, see
17 <https://www.gnu.org/licenses/>. */
19 #include <errno.h>
20 #include <signal.h>
21 #include <stdio.h>
22 #include <support/check.h>
23 #include <support/xunistd.h>
24 #include <time.h>
25 #include <unistd.h>
27 /* Handler for SIGUSR1. */
28 static void
29 sigusr1_handler (int signo)
31 TEST_VERIFY (signo == SIGUSR1);
34 /* Spawn a subprocess to send two signals: First SIGUSR1, then
35 SIGUSR2. Return the PID of the process. */
36 static pid_t
37 signal_sender (void)
39 pid_t pid = xfork ();
40 if (pid == 0)
42 static const struct timespec delay = { 1, };
43 if (nanosleep (&delay, NULL) != 0)
44 FAIL_EXIT1 ("nanosleep: %m");
45 if (kill (getppid (), SIGUSR1) != 0)
46 FAIL_EXIT1 ("kill (SIGUSR1): %m");
47 if (nanosleep (&delay, NULL) != 0)
48 FAIL_EXIT1 ("nanosleep: %m");
49 if (kill (getppid (), SIGUSR2) != 0)
50 FAIL_EXIT1 ("kill (SIGUSR2): %m");
51 _exit (0);
53 return pid;
56 static int
57 do_test (void)
59 if (signal (SIGUSR1, sigusr1_handler) == SIG_ERR)
60 FAIL_EXIT1 ("signal (SIGUSR1): %m\n");
62 sigset_t sigs;
63 sigemptyset (&sigs);
64 sigaddset (&sigs, SIGUSR2);
65 if (sigprocmask (SIG_BLOCK, &sigs, NULL) != 0)
66 FAIL_EXIT1 ("sigprocmask (SIGBLOCK, SIGUSR2): %m");
67 pid_t pid = signal_sender ();
68 int signo = 0;
69 int ret = sigwait (&sigs, &signo);
70 if (ret != 0)
72 support_record_failure ();
73 errno = ret;
74 printf ("error: sigwait failed: %m (%d)\n", ret);
76 TEST_VERIFY (signo == SIGUSR2);
78 int status;
79 xwaitpid (pid, &status, 0);
80 TEST_VERIFY (status == 0);
82 return 0;
85 #include <support/test-driver.c>