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() returns -1 if interrupted. 9 * Test by sending a signal to a child doing nanosleep(). If nanosleep 10 * returns -1, return success from the child. 11 */ 12 #include <stdio.h> 13 #include <time.h> 14 #include <signal.h> 15 #include <unistd.h> 16 #include <sys/wait.h> 17 #include "posixtest.h" 18 19 #define CHILDSUCCESS 1 20 #define CHILDFAILURE 0 21 handler(int signo LTP_ATTRIBUTE_UNUSED)22void handler(int signo LTP_ATTRIBUTE_UNUSED) 23 { 24 printf("In handler\n"); 25 } 26 main(void)27int main(void) 28 { 29 struct timespec tssleepfor, tsstorage; 30 int sleepsec = 30; 31 int pid; 32 struct sigaction act; 33 34 if ((pid = fork()) == 0) { 35 /* child here */ 36 37 act.sa_handler = handler; 38 act.sa_flags = 0; 39 if (sigemptyset(&act.sa_mask) == -1) { 40 perror("Error calling sigemptyset\n"); 41 return CHILDFAILURE; 42 } 43 if (sigaction(SIGABRT, &act, 0) == -1) { 44 perror("Error calling sigaction\n"); 45 return CHILDFAILURE; 46 } 47 tssleepfor.tv_sec = sleepsec; 48 tssleepfor.tv_nsec = 0; 49 if (nanosleep(&tssleepfor, &tsstorage) == -1) { 50 return CHILDSUCCESS; 51 } else { 52 return CHILDFAILURE; 53 } 54 55 return CHILDFAILURE; 56 } else { 57 /* parent here */ 58 int i; 59 60 sleep(1); 61 62 if (kill(pid, SIGABRT) != 0) { 63 printf("Could not raise signal being tested\n"); 64 return PTS_UNRESOLVED; 65 } 66 67 if (wait(&i) == -1) { 68 perror("Error waiting for child to exit\n"); 69 return PTS_UNRESOLVED; 70 } 71 72 if (WIFEXITED(i) && WEXITSTATUS(i)) { 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