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 Assumption: The test assumes that this program is run under normal conditions,
9 and not when the processor and other resources are too stressed.
10
11 Steps:
12 1. Fork() a child process. Have the child suspend itself.
13 2. From the parent, send the child a SIGUSR1 signal so that the child returns from
14    suspension.
15 3. In the child process, make sure that sigsuspend returns a -1 and pass that info
16    to the parent process.
17
18*/
19
20#include <signal.h>
21#include <sys/types.h>
22#include <sys/wait.h>
23#include <stdio.h>
24#include <stdlib.h>
25#include <unistd.h>
26#include "posixtest.h"
27
28void handler(int signo)
29{
30	printf("Now inside signal handler\n");
31}
32
33int main()
34{
35	pid_t pid;
36	pid = fork();
37
38	if (pid == 0) {
39		/* child */
40
41	        sigset_t tempmask;
42
43	        struct sigaction act;
44
45	        act.sa_handler = handler;
46	        act.sa_flags=0;
47	        sigemptyset(&act.sa_mask);
48
49	        sigemptyset(&tempmask);
50
51	        if (sigaction(SIGUSR1,  &act, 0) == -1) {
52	                perror("Unexpected error while attempting to pre-conditions");
53                	return 3;
54	        }
55
56		printf("suspending child\n");
57	        if (sigsuspend(&tempmask) != -1) {
58	                perror("sigsuspend error");
59			return 1;
60		}
61	        printf("returned from suspend\n");
62
63		sleep(1);
64		return 2;
65
66	} else {
67		int s;
68		int exit_status;
69
70		/* parent */
71		sleep(1);
72
73		printf("parent sending child a SIGUSR1 signal\n");
74		kill (pid, SIGUSR1);
75
76		if (wait(&s) == -1) {
77			perror("Unexpected error while setting up test "
78			       "pre-conditions");
79			return PTS_UNRESOLVED;
80		}
81
82		exit_status = WEXITSTATUS(s);
83
84		printf("Exit status from child is %d\n", exit_status);
85
86                if (exit_status == 1) {
87			printf("Test FAILED\n");
88                        return PTS_FAIL;
89                }
90
91                if (exit_status == 2) {
92			printf("Test PASSED\n");
93                        return PTS_PASS;
94                }
95
96                if (exit_status == 3) {
97                        return PTS_UNRESOLVED;
98                }
99
100		printf("Child didn't exit with any of the expected return codes\n");
101		return PTS_UNRESOLVED;
102	}
103}
104
105