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 #define _XOPEN_SOURCE 600
20
21 #include <pthread.h>
22 #include <stdio.h>
23 #include <signal.h>
24 #include <errno.h>
25 #include <unistd.h>
26 #include "posixtest.h"
27
28 #define SIGTOTEST SIGABRT
29 #define INTHREAD 0
30 #define INMAIN 1
31
32 static int result = 2;
33 static int sem = INTHREAD;
34
handler()35 static void handler()
36 {
37 printf("signal was called\n");
38 return;
39 }
40
a_thread_func()41 static void *a_thread_func()
42 {
43 int return_value = 0;
44 struct sigaction act;
45 act.sa_flags = 0;
46 act.sa_handler = handler;
47 sigemptyset(&act.sa_mask);
48 sigaction(SIGTOTEST, &act, 0);
49 return_value = sigpause(SIGTOTEST);
50 if (return_value == -1) {
51 if (errno == EINTR) {
52 printf("Test PASSED: sigpause returned -1 "
53 "and set errno to EINTR\n");
54 result = 0;
55 } else {
56 printf("Test FAILED: sigpause did not "
57 "set errno to EINTR\n");
58 result = 1;
59 }
60 } else {
61 if (errno == EINTR)
62 printf("Test FAILED: sigpause did not return -1\n");
63
64 printf("Test FAILED: sigpause did not set errno to EINTR\n");
65 printf("Test FAILED: sigpause did not return -1\n");
66 result = 1;
67
68 }
69 sem = INMAIN;
70 return NULL;
71 }
72
main(void)73 int main(void)
74 {
75 pthread_t new_th;
76
77 if (pthread_create(&new_th, NULL, a_thread_func, NULL) != 0) {
78 perror("Error creating thread\n");
79 return PTS_UNRESOLVED;
80 }
81
82 sleep(1);
83
84 if (pthread_kill(new_th, SIGTOTEST) != 0) {
85 printf("Test UNRESOLVED: Couldn't send signal to thread\n");
86 return PTS_UNRESOLVED;
87 }
88
89 while (sem == INTHREAD)
90 sleep(1);
91
92 if (result == 2)
93 return PTS_UNRESOLVED;
94
95 if (result == 1)
96 return PTS_FAIL;
97
98 printf("Test PASSED\n");
99 return PTS_PASS;
100 }
101