1 /* 2 * Copyright (c) International Business Machines Corp., 2001 3 * 07/2001 Ported by Wayne Boyer 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation; either version 2 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 * the GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 */ 19 /* 20 * Test Description: 21 * pause() does not return due to receipt of SIGKILL signal and specified 22 * process should be terminated. 23 */ 24 #include <unistd.h> 25 #include <errno.h> 26 #include <fcntl.h> 27 #include <sys/wait.h> 28 29 #include "test.h" 30 #include "safe_macros.h" 31 32 static pid_t cpid; 33 34 char *TCID = "pause03"; 35 int TST_TOTAL = 1; 36 37 static void do_child(void); 38 static void setup(void); 39 static void cleanup(void); 40 41 int main(int ac, char **av) 42 { 43 int lc; 44 int status; 45 46 tst_parse_opts(ac, av, NULL, NULL); 47 #ifdef UCLINUX 48 maybe_run_child(&do_child, ""); 49 #endif 50 51 setup(); 52 53 for (lc = 0; TEST_LOOPING(lc); lc++) { 54 tst_count = 0; 55 56 if ((cpid = FORK_OR_VFORK()) == -1) 57 tst_brkm(TBROK | TERRNO, NULL, "fork() failed"); 58 59 if (cpid == 0) { 60 #ifdef UCLINUX 61 if (self_exec(av[0], "") < 0) 62 tst_brkm(TBROK, cleanup, "self_exec failed"); 63 #else 64 do_child(); 65 #endif 66 } 67 68 TST_PROCESS_STATE_WAIT(cleanup, cpid, 'S'); 69 70 kill(cpid, SIGKILL); 71 72 SAFE_WAIT(NULL, &status); 73 74 if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) { 75 tst_resm(TPASS, "pause() did not return after SIGKILL"); 76 continue; 77 } 78 79 if (WIFSIGNALED(status)) { 80 tst_resm(TFAIL, "child killed by %s unexpectedly", 81 tst_strsig(WTERMSIG(status))); 82 continue; 83 } 84 85 tst_resm(TFAIL, "child exited with %i", WEXITSTATUS(status)); 86 } 87 88 cleanup(); 89 tst_exit(); 90 91 } 92 93 void do_child(void) 94 { 95 TEST(pause()); 96 97 tst_resm(TFAIL, "Unexpected return from pause()"); 98 99 exit(0); 100 } 101 102 void setup(void) 103 { 104 tst_sig(FORK, DEF_HANDLER, cleanup); 105 106 TEST_PAUSE; 107 } 108 109 110 void cleanup(void) 111 { 112 kill(cpid, SIGKILL); 113 } 114