• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2002-3, Intel Corporation. All rights reserved.
3  * Created by:  julie.n.fleischer 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  *  Test that the kill() function shall send signal sig to the process
9  *  specified by pid.
10  *  1) Set up a signal handler for the signal that says we have caught the
11  *     signal.
12  *  2) Call kill on the current process with the signal.
13  *  3) If signal handler was called, test passed.
14  *  This test is only performed on one signal.  All other signals are
15  *  considered to be in the same equivalence class.
16  */
17 
18 #define SIGTOTEST SIGABRT
19 
20 #include <signal.h>
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include "posixtest.h"
25 
handler(int signo)26 static void handler(int signo)
27 {
28 	(void) signo;
29 
30 	printf("Caught signal being tested!\n");
31 	printf("Test PASSED\n");
32 	_exit(PTS_PASS);
33 }
34 
main(void)35 int main(void)
36 {
37 	struct sigaction act;
38 
39 	act.sa_handler = handler;
40 	act.sa_flags = 0;
41 	if (sigemptyset(&act.sa_mask) == -1) {
42 		perror("Error calling sigemptyset\n");
43 		return PTS_UNRESOLVED;
44 	}
45 	if (sigaction(SIGTOTEST, &act, 0) == -1) {
46 		perror("Error calling sigaction\n");
47 		return PTS_UNRESOLVED;
48 	}
49 	if (kill(getpid(), SIGTOTEST) != 0) {
50 		printf("Could not raise signal being tested\n");
51 		return PTS_UNRESOLVED;
52 	}
53 
54 	printf("Should have exited from signal handler\n");
55 	printf("Test FAILED\n");
56 	return PTS_FAIL;
57 }
58