1 /*
2
3 * Copyright (c) 2002-2003, Intel Corporation. All rights reserved.
4 * Created by: rusty.lynch REMOVE-THIS AT intel DOT com
5 * This file is licensed under the GPL license. For the full content
6 * of this license, see the COPYING file at the top level of this
7 * source tree.
8
9 Test case for assertion #4 of the sigaction system call that shows
10 that attempting to add SIGSTOP can not be added to the signal mask
11 for a signal handler.
12
13 Steps:
14 1. Fork a new process
15 2. (parent) wait for child
16 3. (child) Setup a signal handler for SIGUSR2 with SIGSTOP added to
17 the signal mask
18 4. (child) raise SIGUSR2
19 5. (child, signal handler) raise SIGSTOP
20 5. (child) If still around then return -1
21 6. (parent - returning from wait) If child was stopped then return
22 kill the child and return success, otherwise fail.
23 */
24
25 #include <signal.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <sys/wait.h>
29 #include <sys/types.h>
30 #include <unistd.h>
31 #include "posixtest.h"
32
handler(int signo LTP_ATTRIBUTE_UNUSED)33 void handler(int signo LTP_ATTRIBUTE_UNUSED)
34 {
35 printf("About to stop child\n");
36 raise(SIGSTOP);
37 printf("Child has continued\n");
38 exit(0);
39 }
40
main(void)41 int main(void)
42 {
43 pid_t pid;
44 if ((pid = fork()) == 0) {
45 /* child */
46
47 struct sigaction act;
48
49 act.sa_handler = handler;
50 act.sa_flags = 0;
51 sigemptyset(&act.sa_mask);
52 sigaddset(&act.sa_mask, SIGSTOP);
53 if (sigaction(SIGUSR2, &act, 0) == -1) {
54 perror("Unexpected error while attempting to "
55 "setup test pre-conditions");
56 return PTS_UNRESOLVED;
57 }
58
59 if (raise(SIGUSR2) == -1) {
60 perror("Unexpected error while attempting to "
61 "setup test pre-conditions");
62 }
63
64 return PTS_UNRESOLVED;
65 } else {
66 int s;
67
68 /* parent */
69 if (waitpid(pid, &s, WUNTRACED) == -1) {
70 perror("Unexpected error while setting up test "
71 "pre-conditions");
72 return PTS_UNRESOLVED;
73 }
74
75 if (WIFSTOPPED(s)) {
76 printf("Test PASSED\n");
77 kill(pid, SIGKILL);
78 return PTS_PASS;
79 }
80 }
81
82 printf("Test FAILED\n");
83 return PTS_FAIL;
84 }
85