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. Add only SIGABRT to the signal mask. 10 2. Make a call such as this: pthread_sigmask(SIG_BLOCK, NULL, &oactl). At 11 this point, we have obtained the signal mask in oactl. 12 3. Now call is_changed to make sure that SIGABRT is still in oactl, and 13 that no other signal in the set is in oactl. 14 15 */ 16 17 #include <pthread.h> 18 #include <signal.h> 19 #include <stdio.h> 20 #include "posixtest.h" 21 22 #define NUMSIGNALS (sizeof(siglist) / sizeof(siglist[0])) 23 24 int is_changed(sigset_t set, int sig) 25 { 26 27 int i; 28 int siglist[] = { SIGABRT, SIGALRM, SIGBUS, SIGCHLD, 29 SIGCONT, SIGFPE, SIGHUP, SIGILL, SIGINT, 30 SIGPIPE, SIGQUIT, SIGSEGV, 31 SIGTERM, SIGTSTP, SIGTTIN, SIGTTOU, 32 SIGUSR1, SIGUSR2, 33 #ifdef SIGPOLL 34 SIGPOLL, 35 #endif 36 #ifdef SIGPROF 37 SIGPROF, 38 #endif 39 SIGSYS, 40 SIGTRAP, SIGURG, SIGVTALRM, SIGXCPU, SIGXFSZ 41 }; 42 43 if (sigismember(&set, sig) != 1) { 44 return 1; 45 } 46 for (i = 0; i < NUMSIGNALS; i++) { 47 if ((siglist[i] != sig)) { 48 if (sigismember(&set, siglist[i]) != 0) { 49 return 1; 50 } 51 } 52 } 53 return 0; 54 } 55 56 void *a_thread_func() 57 { 58 59 sigset_t actl, oactl; 60 61 sigemptyset(&actl); 62 sigemptyset(&oactl); 63 64 sigaddset(&actl, SIGABRT); 65 66 pthread_sigmask(SIG_SETMASK, &actl, NULL); 67 pthread_sigmask(SIG_BLOCK, NULL, &oactl); 68 69 if (is_changed(oactl, SIGABRT)) { 70 pthread_exit((void *)-1); 71 } 72 printf("PASS: signal mask was not changed.\n"); 73 pthread_exit(NULL); 74 75 /* To please some compilers */ 76 return NULL; 77 } 78 79 int main(void) 80 { 81 82 int *thread_return_value; 83 84 pthread_t new_thread; 85 86 if (pthread_create(&new_thread, NULL, a_thread_func, NULL) != 0) { 87 perror("Error creating new thread\n"); 88 return PTS_UNRESOLVED; 89 } 90 91 if (pthread_join(new_thread, (void *)&thread_return_value) != 0) { 92 perror("Error in pthread_join()\n"); 93 return PTS_UNRESOLVED; 94 } 95 96 if ((long)thread_return_value != 0) { 97 if ((long)thread_return_value == 1) { 98 printf("Test UNRESOLVED\n"); 99 return PTS_UNRESOLVED; 100 } else if ((long)thread_return_value == -1) { 101 printf("Test FAILED\n"); 102 return PTS_FAIL; 103 } else { 104 printf("Test UNRESOLVED\n"); 105 return PTS_UNRESOLVED; 106 } 107 } 108 return PTS_PASS; 109 } 110