robbiew | 42129a8 | 2003-04-14 15:55:37 +0000 | [diff] [blame] | 1 | /* |
| 2 | |
| 3 | * Copyright (c) 2002-2003, Intel Corporation. All rights reserved. |
| 4 | * Created by: rusty.lynch REMOVE-THIS AT intel DOT com |
| 5 | * This file is licensed under the GPL license. For the full content |
| 6 | * of this license, see the COPYING file at the top level of this |
| 7 | * source tree. |
| 8 | |
| 9 | Test case for assertion #4 of the sigaction system call that shows |
| 10 | that attempting to add SIGKILL can not be added to the signal mask |
| 11 | for a signal handler. |
| 12 | |
| 13 | Steps: |
| 14 | 1. Fork a new process |
| 15 | 2. (parent) wait for child |
| 16 | 3. (child) Setup a signal handler for SIGSEGV with SIGKILL added to |
| 17 | the signal mask |
| 18 | 4. (child) raise SIGSEGV |
| 19 | 5. (child, signal handler) raise SIGKILL |
| 20 | 5. (child) If still alive then exit -1 |
| 21 | 6. (parent - returning from wait) If child was killed then return success, |
| 22 | otherwise fail. |
| 23 | */ |
| 24 | |
| 25 | #include <signal.h> |
| 26 | #include <stdio.h> |
| 27 | #include <stdlib.h> |
| 28 | #include <sys/wait.h> |
| 29 | #include <unistd.h> |
| 30 | #include "posixtest.h" |
| 31 | |
| 32 | void handler(int signo) |
| 33 | { |
| 34 | raise(SIGKILL); |
| 35 | exit(0); |
| 36 | } |
| 37 | |
| 38 | int main() |
| 39 | { |
| 40 | if (fork() == 0) { |
| 41 | /* child */ |
| 42 | |
| 43 | /* |
| 44 | * NOTE: This block of code will return 0 for error |
| 45 | * and anything else for success. |
| 46 | */ |
| 47 | |
| 48 | struct sigaction act; |
| 49 | |
| 50 | act.sa_handler = handler; |
| 51 | act.sa_flags = 0; |
| 52 | sigemptyset(&act.sa_mask); |
| 53 | sigaddset(&act.sa_mask, SIGKILL); |
| 54 | if (sigaction(SIGSEGV, &act, 0) == -1) { |
| 55 | perror("Unexpected error while attempting to " |
| 56 | "setup test pre-conditions"); |
| 57 | return PTS_PASS; |
| 58 | } |
| 59 | |
| 60 | if (raise(SIGSEGV) == -1) { |
| 61 | perror("Unexpected error while attempting to " |
| 62 | "setup test pre-conditions"); |
| 63 | } |
| 64 | |
| 65 | return PTS_PASS; |
| 66 | } else { |
| 67 | int s; |
| 68 | |
| 69 | /* parent */ |
| 70 | if (wait(&s) == -1) { |
| 71 | perror("Unexpected error while setting up test " |
| 72 | "pre-conditions"); |
| 73 | return PTS_UNRESOLVED; |
| 74 | } |
| 75 | |
| 76 | if (!WIFEXITED(s)) { |
| 77 | printf("Test PASSED\n"); |
| 78 | return PTS_PASS; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | printf("Test FAILED\n"); |
| 83 | return PTS_FAIL; |
| 84 | } |
| 85 | |