Home | History | Annotate | Download | only in sigrelse
      1 /*
      2  * Copyright (c) 2003, Intel Corporation. All rights reserved.
      3  * Copyright (c) 2013, Cyril Hrubis <chrubis (at) suse.cz>
      4  *
      5  * Created by:  salwan.searty REMOVE-THIS AT intel DOT com
      6  * This file is licensed under the GPL license.  For the full content
      7  * of this license, see the COPYING file at the top level of this
      8  * source tree.
      9  *
     10  * Steps:
     11  * 1. Set up a handler for signal SIGABRT, such that it is called if
     12  *    signal is ever raised.
     13  * 2. Call sighold on that SIGABRT.
     14  * 3. Raise a SIGABRT and verify that the signal handler was not called.
     15  *    Otherwise, the test exits with unresolved results.
     16  * 4. Call sigrelse on SIGABRT.
     17  * 5. Verify that the handler gets called this time.
     18  */
     19 #define _XOPEN_SOURCE 600
     20 
     21 #include <signal.h>
     22 #include <stdio.h>
     23 #include <unistd.h>
     24 #include "posixtest.h"
     25 
     26 static int handler_called;
     27 
     28 static void handler(int signo)
     29 {
     30 	handler_called = 1;
     31 }
     32 
     33 int main(void)
     34 {
     35 	struct sigaction act;
     36 
     37 	act.sa_handler = handler;
     38 	act.sa_flags = 0;
     39 	sigemptyset(&act.sa_mask);
     40 	if (sigaction(SIGABRT, &act, 0) == -1) {
     41 		perror("Failed to set signal handler.");
     42 		return PTS_UNRESOLVED;
     43 	}
     44 
     45 	sighold(SIGABRT);
     46 
     47 	if (raise(SIGABRT) == -1) {
     48 		perror("Failed to raise SIGABRT.");
     49 		return PTS_UNRESOLVED;
     50 	}
     51 
     52 	if (handler_called) {
     53 		printf("UNRESOLVED. possible problem in sigrelse\n");
     54 		return PTS_UNRESOLVED;
     55 	}
     56 
     57 	if (sigrelse(SIGABRT) == -1) {
     58 		printf("UNRESOLVED. possible problem in sigrelse\n");
     59 		return PTS_UNRESOLVED;
     60 	}
     61 
     62 	usleep(100000);
     63 
     64 	if (handler_called) {
     65 		printf("Test PASSED: SIGABRT removed from signal mask\n");
     66 		return PTS_PASS;
     67 	}
     68 	printf("Test FAILED\n");
     69 	return PTS_FAIL;
     70 }
     71