1 /*
2 * Copyright (c) 2003, Intel Corporation. All rights reserved.
3 * Created by: salwan.searty REMOVE-THIS AT intel DOT com
4 * This file is licensed under the GPL license. For the full content
5 * of this license, see the COPYING file at the top level of this
6 * source tree.
7
8 Steps:
9 1. Set the signal mask to only having SIGABRT.
10 2. Call sigprocmask again, this time with a randomly generated value of
11 how that is checked to make sure it does not equal any of the three defined
12 values of how which are SIG_SETMASK, SIG_BLOCK, or SIG_UNBLOCK. This should
13 cause sigprocmask() to return -1. For the second parameter in the sigprocmask()
14 function, use a set which contains SIGABRT and SIGALRM.
15 3. Now verify using the is_changed() function that the only signal that is still
16 in the signal mask is SIGABRT. Neither SIGALRM nor any other signal should be
17 in the signal mask of the process.
18
19 */
20
21 #include <signal.h>
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include "posixtest.h"
25
26 #define NUMSIGNALS (sizeof(siglist) / sizeof(siglist[0]))
27
is_changed(sigset_t set)28 int is_changed(sigset_t set)
29 {
30
31 int i;
32 int siglist[] = { SIGALRM, SIGBUS, SIGCHLD,
33 SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT,
34 SIGPIPE, SIGQUIT, SIGSEGV,
35 SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU,
36 SIGUSR1, SIGUSR2,
37 #ifdef SIGPOLL
38 SIGPOLL,
39 #endif
40 #ifdef SIGPROF
41 SIGPROF,
42 #endif
43 SIGSYS,
44 SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ
45 };
46
47 for (i = 0; i < NUMSIGNALS; i++) {
48 if (sigismember(&set, siglist[i]) != 0)
49 return 1;
50 }
51 return 0;
52 }
53
get_rand(void)54 int get_rand(void)
55 {
56
57 int r;
58 r = rand();
59 while ((r == SIG_BLOCK) || (r == SIG_SETMASK) || (r == SIG_UNBLOCK)) {
60 r = get_rand();
61 }
62 return r;
63 }
64
main(void)65 int main(void)
66 {
67
68 int r = get_rand();
69 sigset_t actl, oactl;
70
71 sigemptyset(&actl);
72 sigemptyset(&oactl);
73 sigaddset(&actl, SIGABRT);
74
75 sigprocmask(SIG_SETMASK, &actl, NULL);
76
77 sigaddset(&actl, SIGALRM);
78 if (sigprocmask(r, &actl, NULL) != -1) {
79 perror
80 ("sigprocmask() did not fail even though invalid how parameter was passed to it.\n");
81 return PTS_UNRESOLVED;
82 }
83
84 sigprocmask(SIG_SETMASK, NULL, &oactl);
85
86 if (sigismember(&oactl, SIGABRT) != 1) {
87 printf("FAIL: signal mask was changed. \n");
88 return PTS_FAIL;
89 }
90
91 if (is_changed(oactl)) {
92 printf("FAIL: signal mask was changed. \n");
93 return PTS_FAIL;
94 }
95
96 printf("Test PASSED: signal mask was not changed.\n");
97 return PTS_PASS;
98 }
99