10dc076565f772bb1953209fb69ea150b494aaa40robbiew/* 20dc076565f772bb1953209fb69ea150b494aaa40robbiew * Copyright (c) 2003, Intel Corporation. All rights reserved. 30dc076565f772bb1953209fb69ea150b494aaa40robbiew * Created by: salwan.searty REMOVE-THIS AT intel DOT com 40dc076565f772bb1953209fb69ea150b494aaa40robbiew * This file is licensed under the GPL license. For the full content 52c28215423293e443469a07ae7011135d058b671Garrett Cooper * of this license, see the COPYING file at the top level of this 60dc076565f772bb1953209fb69ea150b494aaa40robbiew * source tree. 72c28215423293e443469a07ae7011135d058b671Garrett Cooper 82c28215423293e443469a07ae7011135d058b671Garrett Cooper The resulting set shall be the signal set pointed to by set, if the value 90dc076565f772bb1953209fb69ea150b494aaa40robbiew of the argument how is SIG_SETMASK 100dc076565f772bb1953209fb69ea150b494aaa40robbiew*/ 110dc076565f772bb1953209fb69ea150b494aaa40robbiew 120dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <signal.h> 130dc076565f772bb1953209fb69ea150b494aaa40robbiew#include <stdio.h> 140dc076565f772bb1953209fb69ea150b494aaa40robbiew#include "posixtest.h" 150dc076565f772bb1953209fb69ea150b494aaa40robbiew 160dc076565f772bb1953209fb69ea150b494aaa40robbiewint handler_called = 0; 170dc076565f772bb1953209fb69ea150b494aaa40robbiew 180dc076565f772bb1953209fb69ea150b494aaa40robbiewvoid handler(int signo) 190dc076565f772bb1953209fb69ea150b494aaa40robbiew{ 200dc076565f772bb1953209fb69ea150b494aaa40robbiew handler_called = 1; 210dc076565f772bb1953209fb69ea150b494aaa40robbiew} 220dc076565f772bb1953209fb69ea150b494aaa40robbiew 23e40d6bae0ade4626bdd83719f5237617add55437Cyril Hrubisint main(void) 240dc076565f772bb1953209fb69ea150b494aaa40robbiew{ 250dc076565f772bb1953209fb69ea150b494aaa40robbiew struct sigaction act; 260dc076565f772bb1953209fb69ea150b494aaa40robbiew sigset_t blocked_set, pending_set; 270dc076565f772bb1953209fb69ea150b494aaa40robbiew sigemptyset(&blocked_set); 280dc076565f772bb1953209fb69ea150b494aaa40robbiew sigaddset(&blocked_set, SIGABRT); 292c28215423293e443469a07ae7011135d058b671Garrett Cooper 300dc076565f772bb1953209fb69ea150b494aaa40robbiew act.sa_handler = handler; 310dc076565f772bb1953209fb69ea150b494aaa40robbiew act.sa_flags = 0; 320dc076565f772bb1953209fb69ea150b494aaa40robbiew sigemptyset(&act.sa_mask); 33354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao if (sigaction(SIGABRT, &act, 0) == -1) { 340dc076565f772bb1953209fb69ea150b494aaa40robbiew perror("Unexpected error while attempting to setup test " 350dc076565f772bb1953209fb69ea150b494aaa40robbiew "pre-conditions"); 360dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 370dc076565f772bb1953209fb69ea150b494aaa40robbiew } 380dc076565f772bb1953209fb69ea150b494aaa40robbiew 390dc076565f772bb1953209fb69ea150b494aaa40robbiew if (sigprocmask(SIG_SETMASK, &blocked_set, NULL) == -1) { 40354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao perror 41354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao ("Unexpected error while attempting to use sigprocmask.\n"); 420dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 430dc076565f772bb1953209fb69ea150b494aaa40robbiew } 440dc076565f772bb1953209fb69ea150b494aaa40robbiew 450dc076565f772bb1953209fb69ea150b494aaa40robbiew if (raise(SIGABRT) == -1) { 460dc076565f772bb1953209fb69ea150b494aaa40robbiew perror("Unexpected error while attempting to setup test " 470dc076565f772bb1953209fb69ea150b494aaa40robbiew "pre-conditions"); 480dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 490dc076565f772bb1953209fb69ea150b494aaa40robbiew } 500dc076565f772bb1953209fb69ea150b494aaa40robbiew 510dc076565f772bb1953209fb69ea150b494aaa40robbiew if (handler_called) { 520dc076565f772bb1953209fb69ea150b494aaa40robbiew printf("FAIL: Signal was not blocked\n"); 530dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_FAIL; 540dc076565f772bb1953209fb69ea150b494aaa40robbiew } 550dc076565f772bb1953209fb69ea150b494aaa40robbiew 560dc076565f772bb1953209fb69ea150b494aaa40robbiew if (sigpending(&pending_set) == -1) { 570dc076565f772bb1953209fb69ea150b494aaa40robbiew perror("Unexpected error while attempting to use sigpending\n"); 580dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 590dc076565f772bb1953209fb69ea150b494aaa40robbiew } 600dc076565f772bb1953209fb69ea150b494aaa40robbiew 610dc076565f772bb1953209fb69ea150b494aaa40robbiew if (sigismember(&pending_set, SIGABRT) == -1) { 62354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao perror 63354ebb48db8e66a853a58379a4808d5dcd1ceac3Wanlong Gao ("Unexpected error while attempting to use sigismember.\n"); 640dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 650dc076565f772bb1953209fb69ea150b494aaa40robbiew } 660dc076565f772bb1953209fb69ea150b494aaa40robbiew 670dc076565f772bb1953209fb69ea150b494aaa40robbiew if (sigismember(&pending_set, SIGABRT) != 1) { 680dc076565f772bb1953209fb69ea150b494aaa40robbiew perror("FAIL: sigismember did not return 1\n"); 690dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_UNRESOLVED; 700dc076565f772bb1953209fb69ea150b494aaa40robbiew } 710dc076565f772bb1953209fb69ea150b494aaa40robbiew 720dc076565f772bb1953209fb69ea150b494aaa40robbiew printf("Test PASSED: signal was added to the process's signal mask\n"); 730dc076565f772bb1953209fb69ea150b494aaa40robbiew return PTS_PASS; 74ec6edca7aa42b6affd989ef91b5897f96795e40fChris Dearman} 75