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(void) 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 53 ("Unexpected error while attempting to pre-conditions"); 54 return 3; 55 } 56 57 printf("suspending child\n"); 58 if (sigsuspend(&tempmask) != -1) { 59 perror("sigsuspend error"); 60 return 1; 61 } 62 printf("returned from suspend\n"); 63 64 sleep(1); 65 return 2; 66 67 } else { 68 int s; 69 int exit_status; 70 71 /* parent */ 72 sleep(1); 73 74 printf("parent sending child a SIGUSR1 signal\n"); 75 kill(pid, SIGUSR1); 76 77 if (wait(&s) == -1) { 78 perror("Unexpected error while setting up test " 79 "pre-conditions"); 80 return PTS_UNRESOLVED; 81 } 82 83 exit_status = WEXITSTATUS(s); 84 85 printf("Exit status from child is %d\n", exit_status); 86 87 if (exit_status == 1) { 88 printf("Test FAILED\n"); 89 return PTS_FAIL; 90 } 91 92 if (exit_status == 2) { 93 printf("Test PASSED\n"); 94 return PTS_PASS; 95 } 96 97 if (exit_status == 3) { 98 return PTS_UNRESOLVED; 99 } 100 101 printf 102 ("Child didn't exit with any of the expected return codes\n"); 103 return PTS_UNRESOLVED; 104 } 105} 106