1 | /* Derived from the test case in |
---|---|
2 | https://sourceware.org/bugzilla/show_bug.cgi?id=838. */ |
3 | #include <assert.h> |
4 | #include <errno.h> |
5 | #include <stdio.h> |
6 | #include <stdlib.h> |
7 | #include <unistd.h> |
8 | #include <sys/types.h> |
9 | #include <sys/wait.h> |
10 | #include <libc-diag.h> |
11 | |
12 | static void |
13 | sig_handler (int signum) |
14 | { |
15 | pid_t child = fork (); |
16 | if (child == 0) |
17 | exit (0); |
18 | TEMP_FAILURE_RETRY (waitpid (child, NULL, 0)); |
19 | } |
20 | |
21 | static int |
22 | do_test (void) |
23 | { |
24 | pid_t parent = getpid (); |
25 | |
26 | struct sigaction action = { .sa_handler = sig_handler }; |
27 | sigemptyset (&action.sa_mask); |
28 | |
29 | DIAG_PUSH_NEEDS_COMMENT; |
30 | DIAG_IGNORE_NEEDS_COMMENT (10, "-Wunused-result"); |
31 | /* The result of malloc is deliberately ignored, so do not warn |
32 | about that. */ |
33 | malloc (size: sizeof (int)); |
34 | DIAG_POP_NEEDS_COMMENT; |
35 | |
36 | if (sigaction (SIGALRM, act: &action, NULL) != 0) |
37 | { |
38 | puts (s: "sigaction failed"); |
39 | return 1; |
40 | } |
41 | |
42 | /* Create a child that sends the signal to be caught. */ |
43 | pid_t child = fork (); |
44 | if (child == 0) |
45 | { |
46 | if (kill (pid: parent, SIGALRM) == -1) |
47 | perror ("kill"); |
48 | exit (0); |
49 | } |
50 | |
51 | TEMP_FAILURE_RETRY (waitpid (child, NULL, 0)); |
52 | |
53 | return 0; |
54 | } |
55 | |
56 | #define TEST_FUNCTION do_test () |
57 | #include "../test-skeleton.c" |
58 |