plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
Cyril Hrubis | 32f179b | 2015-03-05 13:35:45 +0100 | [diff] [blame] | 2 | * Copyright (c) International Business Machines Corp., 2001 |
| 3 | * 07/2001 Ported by Wayne Boyer |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 4 | * |
Cyril Hrubis | 32f179b | 2015-03-05 13:35:45 +0100 | [diff] [blame] | 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. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 9 | * |
Cyril Hrubis | 32f179b | 2015-03-05 13:35:45 +0100 | [diff] [blame] | 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. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 14 | * |
Cyril Hrubis | 32f179b | 2015-03-05 13:35:45 +0100 | [diff] [blame] | 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 |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 19 | /* |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 20 | * Test Description: |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 21 | * pause() does not return due to receipt of SIGKILL signal and specified |
| 22 | * process should be terminated. |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 23 | */ |
| 24 | #include <unistd.h> |
| 25 | #include <errno.h> |
| 26 | #include <fcntl.h> |
| 27 | #include <wait.h> |
| 28 | |
| 29 | #include "test.h" |
Cyril Hrubis | d584ad1 | 2015-03-05 14:08:31 +0100 | [diff] [blame] | 30 | #include "safe_macros.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 31 | |
Cyril Hrubis | 32f179b | 2015-03-05 13:35:45 +0100 | [diff] [blame] | 32 | static pid_t cpid; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 33 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 34 | char *TCID = "pause03"; |
| 35 | int TST_TOTAL = 1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 36 | |
Cyril Hrubis | 32f179b | 2015-03-05 13:35:45 +0100 | [diff] [blame] | 37 | static void do_child(void); |
| 38 | static void setup(void); |
| 39 | static void cleanup(void); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 40 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 41 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 42 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 43 | int lc; |
Cyril Hrubis | 32f179b | 2015-03-05 13:35:45 +0100 | [diff] [blame] | 44 | int status; |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 45 | |
Cyril Hrubis | d6d11d0 | 2015-03-09 17:35:43 +0100 | [diff] [blame] | 46 | tst_parse_opts(ac, av, NULL, NULL); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 47 | #ifdef UCLINUX |
| 48 | maybe_run_child(&do_child, ""); |
| 49 | #endif |
| 50 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 51 | setup(); |
| 52 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 53 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 54 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 55 | |
Cyril Hrubis | d584ad1 | 2015-03-05 14:08:31 +0100 | [diff] [blame] | 56 | if ((cpid = FORK_OR_VFORK()) == -1) |
| 57 | tst_brkm(TBROK | TERRNO, NULL, "fork() failed"); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 58 | |
Cyril Hrubis | 32f179b | 2015-03-05 13:35:45 +0100 | [diff] [blame] | 59 | if (cpid == 0) { |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 60 | #ifdef UCLINUX |
Cyril Hrubis | 32f179b | 2015-03-05 13:35:45 +0100 | [diff] [blame] | 61 | if (self_exec(av[0], "") < 0) |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 62 | tst_brkm(TBROK, cleanup, "self_exec failed"); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 63 | #else |
| 64 | do_child(); |
| 65 | #endif |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 66 | } |
| 67 | |
Cyril Hrubis | d584ad1 | 2015-03-05 14:08:31 +0100 | [diff] [blame] | 68 | TST_PROCESS_STATE_WAIT(cleanup, cpid, 'S'); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 69 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 70 | kill(cpid, SIGKILL); |
| 71 | |
Cyril Hrubis | d584ad1 | 2015-03-05 14:08:31 +0100 | [diff] [blame] | 72 | SAFE_WAIT(NULL, &status); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 73 | |
Cyril Hrubis | d584ad1 | 2015-03-05 14:08:31 +0100 | [diff] [blame] | 74 | if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) { |
| 75 | tst_resm(TPASS, "pause() did not return after SIGKILL"); |
| 76 | continue; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Cyril Hrubis | d584ad1 | 2015-03-05 14:08:31 +0100 | [diff] [blame] | 79 | if (WIFSIGNALED(status)) { |
| 80 | tst_resm(TFAIL, "child killed by %s unexpectedly", |
| 81 | tst_strsig(WTERMSIG(status))); |
| 82 | continue; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 83 | } |
| 84 | |
Cyril Hrubis | d584ad1 | 2015-03-05 14:08:31 +0100 | [diff] [blame] | 85 | tst_resm(TFAIL, "child exited with %i", WEXITSTATUS(status)); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 86 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 87 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | cleanup(); |
Garrett Cooper | 1e6f5a6 | 2010-12-19 09:58:10 -0800 | [diff] [blame] | 89 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 90 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 91 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 92 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 93 | void do_child(void) |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 94 | { |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 95 | TEST(pause()); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 96 | |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 97 | tst_resm(TFAIL, "Unexpected return from pause()"); |
Cyril Hrubis | 32f179b | 2015-03-05 13:35:45 +0100 | [diff] [blame] | 98 | |
Cyril Hrubis | d584ad1 | 2015-03-05 14:08:31 +0100 | [diff] [blame] | 99 | exit(0); |
robbiew | d34d581 | 2005-07-11 22:28:09 +0000 | [diff] [blame] | 100 | } |
| 101 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 102 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 103 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 104 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 105 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 106 | TEST_PAUSE; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 107 | } |
| 108 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 109 | |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 110 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 111 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 112 | kill(cpid, SIGKILL); |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 113 | } |