1 /* 2 * Copyright (c) 2002-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 * Test that the sigqueue() function shall send signal signo and value 9 to the child process specified by pid. 10 * 1) Fork a child process. 11 * 2) In the parent process, call sigqueue with signal SIGTOTEST and 12 * value VALTOTEST for the pid of the child 13 * In the child, 14 * 3) Wait for signal SIGTOTEST. 15 * 4) Return 1 if SIGTOTEST and SIGTOVAL are the values of signo and 16 info->si_value.sival_intel respectively. Have the child return 0 otherwise. 17 * 5) In the parent, return success if 1 was returned from child. 18 * 19 */ 20 21 #define _XOPEN_REALTIME 1 22 #define SIGTOTEST SIGRTMIN 23 #define VALTOTEST 100 /* Application-defined value sent by sigqueue */ 24 25 #include <signal.h> 26 #include <stdio.h> 27 #include <stdlib.h> 28 #include <unistd.h> 29 #include <sys/wait.h> 30 #include "posixtest.h" 31 32 void myhandler(int signo, siginfo_t * info, void *context) 33 { 34 if ((signo == SIGTOTEST) && (info->si_value.sival_int == VALTOTEST)) { 35 printf 36 ("sigqueue()'s signo and value parameters were passed to the child process.\n"); 37 exit(1); 38 } 39 } 40 41 int main(void) 42 { 43 int pid; 44 45 if ((pid = fork()) == 0) { 46 /* child here */ 47 struct sigaction act; 48 act.sa_flags = SA_SIGINFO; 49 act.sa_sigaction = myhandler; 50 sigemptyset(&act.sa_mask); 51 sigaction(SIGTOTEST, &act, 0); 52 53 while (1) { 54 sleep(1); 55 } 56 printf("shouldn't be here\n"); 57 return 0; 58 } else { 59 /* parent here */ 60 int i; 61 union sigval value; 62 value.sival_int = VALTOTEST; 63 64 sleep(1); 65 if (sigqueue(pid, SIGTOTEST, value) != 0) { 66 printf("Could not raise signal being tested\n"); 67 return PTS_UNRESOLVED; 68 } 69 70 if (wait(&i) == -1) { 71 perror("Error waiting for child to exit\n"); 72 return PTS_UNRESOLVED; 73 } 74 75 if (WEXITSTATUS(i)) { 76 printf("Child exited normally\n"); 77 printf("Test PASSED\n"); 78 return PTS_PASS; 79 } else { 80 printf("Child did not exit normally.\n"); 81 printf("Test FAILED\n"); 82 return PTS_FAIL; 83 } 84 } 85 86 printf("Should have exited from parent\n"); 87 printf("Test FAILED\n"); 88 return PTS_FAIL; 89 } 90