• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  This program verifies that sigpause() returns -1 and sets errno to EINTR
9  when it returns.
10 
11  Steps:
12  1. From the main() function, create a new thread. Give the new thread a
13     a second to set up for receiving a signal, and to suspend itself using
14     sigpause().
15  2. From the main() thread, send signal to new thread to make sigpause return.
16  3. Verify that sigpause returns -1 and sets errno to EINTR.
17  */
18 
19 
20 #include <pthread.h>
21 #include <stdio.h>
22 #include <signal.h>
23 #include <errno.h>
24 #include <unistd.h>
25 #include "posixtest.h"
26 
27 #define SIGTOTEST SIGABRT
28 #define INTHREAD 0
29 #define INMAIN 1
30 
31 static int result = 2;
32 static int sem = INTHREAD;
33 
handler()34 static void handler()
35 {
36 	printf("signal was called\n");
37 	return;
38 }
39 
a_thread_func()40 static void *a_thread_func()
41 {
42 	int return_value = 0;
43 	struct sigaction act;
44 	act.sa_flags = 0;
45 	act.sa_handler = handler;
46 	sigemptyset(&act.sa_mask);
47 	sigaction(SIGTOTEST, &act, 0);
48 	return_value = sigpause(SIGTOTEST);
49 	if (return_value == -1) {
50 		if (errno == EINTR) {
51 			printf("Test PASSED: sigpause returned -1 "
52 			       "and set errno to EINTR\n");
53 			result = 0;
54 		} else {
55 			printf("Test FAILED: sigpause did not "
56 			       "set errno to EINTR\n");
57 			result = 1;
58 		}
59 	} else {
60 		if (errno == EINTR)
61 			printf("Test FAILED: sigpause did not return -1\n");
62 
63 		printf("Test FAILED: sigpause did not set errno to EINTR\n");
64 		printf("Test FAILED: sigpause did not return -1\n");
65 		result = 1;
66 
67 	}
68 	sem = INMAIN;
69 	return NULL;
70 }
71 
main(void)72 int main(void)
73 {
74 	pthread_t new_th;
75 
76 	if (pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) {
77 		perror("Error creating thread\n");
78 		return PTS_UNRESOLVED;
79 	}
80 
81 	sleep(1);
82 
83 	if (pthread_kill(new_th, SIGTOTEST) != 0) {
84 		printf("Test UNRESOLVED: Couldn't send signal to thread\n");
85 		return PTS_UNRESOLVED;
86 	}
87 
88 	while (sem == INTHREAD)
89 		sleep(1);
90 
91 	if (result == 2)
92 		return PTS_UNRESOLVED;
93 
94 	if (result == 1)
95 		return PTS_FAIL;
96 
97 	printf("Test PASSED\n");
98 	return PTS_PASS;
99 }
100