• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2002, 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 nanosleep() does not effect the action of a signal.
9  * - Start nanosleep() in a child process
10  * - Send a signal to the child process and have the handler exit with
11  *   success; if the handler is not called, return 0
12  * - In the parent, if the child exited success, return success.
13  */
14 #include <stdio.h>
15 #include <time.h>
16 #include <signal.h>
17 #include <unistd.h>
18 #include <sys/wait.h>
19 #include <stdlib.h>
20 #include "posixtest.h"
21 
22 #define CHILDSUCCESS 1
23 #define CHILDFAIL 0
24 
handler(int signo PTS_ATTRIBUTE_UNUSED)25 static void handler(int signo PTS_ATTRIBUTE_UNUSED)
26 {
27 	printf("Received signal - exit success\n");
28 	exit(CHILDSUCCESS);
29 }
30 
main(void)31 int main(void)
32 {
33 	struct timespec tssleepfor, tsstorage;
34 	int sleepsec = 30;
35 	int pid;
36 	struct sigaction act;
37 
38 	if ((pid = fork()) == 0) {
39 		/* child here */
40 
41 		act.sa_handler = handler;
42 		act.sa_flags = 0;
43 		if (sigemptyset(&act.sa_mask) == -1) {
44 			perror("Error calling sigemptyset\n");
45 			return CHILDFAIL;
46 		}
47 		if (sigaction(SIGABRT, &act, 0) == -1) {
48 			perror("Error calling sigaction\n");
49 			return CHILDFAIL;
50 		}
51 		tssleepfor.tv_sec = sleepsec;
52 		tssleepfor.tv_nsec = 0;
53 		nanosleep(&tssleepfor, &tsstorage);
54 		return CHILDFAIL;
55 	} else {
56 		/* parent here */
57 		int i;
58 
59 		sleep(1);
60 
61 		if (kill(pid, SIGABRT) != 0) {
62 			printf("Could not raise signal being tested\n");
63 			return PTS_UNRESOLVED;
64 		}
65 
66 		if (wait(&i) == -1) {
67 			perror("Error waiting for child to exit\n");
68 			return PTS_UNRESOLVED;
69 		}
70 
71 		if (WIFEXITED(i) && WEXITSTATUS(i)) {
72 			printf("Child exited normally\n");
73 			printf("Test PASSED\n");
74 			return PTS_PASS;
75 		} else {
76 			printf("Child did not exit normally.\n");
77 			printf("Test FAILED\n");
78 			return PTS_FAIL;
79 		}
80 	}
81 	return PTS_UNRESOLVED;
82 }
83