blob: b1503fc5c18f0b75a867fb8964b4f25571f780b1 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
Cyril Hrubis32f179b2015-03-05 13:35:45 +01002 * Copyright (c) International Business Machines Corp., 2001
3 * 07/2001 Ported by Wayne Boyer
plars865695b2001-08-27 22:15:12 +00004 *
Cyril Hrubis32f179b2015-03-05 13:35:45 +01005 * 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.
plars865695b2001-08-27 22:15:12 +00009 *
Cyril Hrubis32f179b2015-03-05 13:35:45 +010010 * 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.
plars865695b2001-08-27 22:15:12 +000014 *
Cyril Hrubis32f179b2015-03-05 13:35:45 +010015 * 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
plars865695b2001-08-27 22:15:12 +000018 */
plars865695b2001-08-27 22:15:12 +000019/*
plars865695b2001-08-27 22:15:12 +000020 * Test Description:
plars865695b2001-08-27 22:15:12 +000021 * pause() does not return due to receipt of SIGKILL signal and specified
22 * process should be terminated.
plars865695b2001-08-27 22:15:12 +000023 */
24#include <unistd.h>
25#include <errno.h>
26#include <fcntl.h>
Steven Jackson249f4052016-12-13 16:16:00 +000027#include <sys/wait.h>
plars865695b2001-08-27 22:15:12 +000028
29#include "test.h"
Cyril Hrubisd584ad12015-03-05 14:08:31 +010030#include "safe_macros.h"
plars865695b2001-08-27 22:15:12 +000031
Cyril Hrubis32f179b2015-03-05 13:35:45 +010032static pid_t cpid;
plars865695b2001-08-27 22:15:12 +000033
Cyril Hrubisfdce7d52013-04-04 18:35:48 +020034char *TCID = "pause03";
35int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000036
Cyril Hrubis32f179b2015-03-05 13:35:45 +010037static void do_child(void);
38static void setup(void);
39static void cleanup(void);
plars865695b2001-08-27 22:15:12 +000040
subrata_modak56207ce2009-03-23 13:35:39 +000041int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000042{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020043 int lc;
Cyril Hrubis32f179b2015-03-05 13:35:45 +010044 int status;
subrata_modak56207ce2009-03-23 13:35:39 +000045
Cyril Hrubisd6d11d02015-03-09 17:35:43 +010046 tst_parse_opts(ac, av, NULL, NULL);
robbiewd34d5812005-07-11 22:28:09 +000047#ifdef UCLINUX
48 maybe_run_child(&do_child, "");
49#endif
50
plars865695b2001-08-27 22:15:12 +000051 setup();
52
plars865695b2001-08-27 22:15:12 +000053 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080054 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000055
Cyril Hrubisd584ad12015-03-05 14:08:31 +010056 if ((cpid = FORK_OR_VFORK()) == -1)
57 tst_brkm(TBROK | TERRNO, NULL, "fork() failed");
plars865695b2001-08-27 22:15:12 +000058
Cyril Hrubis32f179b2015-03-05 13:35:45 +010059 if (cpid == 0) {
robbiewd34d5812005-07-11 22:28:09 +000060#ifdef UCLINUX
Cyril Hrubis32f179b2015-03-05 13:35:45 +010061 if (self_exec(av[0], "") < 0)
robbiewd34d5812005-07-11 22:28:09 +000062 tst_brkm(TBROK, cleanup, "self_exec failed");
robbiewd34d5812005-07-11 22:28:09 +000063#else
64 do_child();
65#endif
plars865695b2001-08-27 22:15:12 +000066 }
67
Cyril Hrubisd584ad12015-03-05 14:08:31 +010068 TST_PROCESS_STATE_WAIT(cleanup, cpid, 'S');
plars865695b2001-08-27 22:15:12 +000069
plars865695b2001-08-27 22:15:12 +000070 kill(cpid, SIGKILL);
71
Cyril Hrubisd584ad12015-03-05 14:08:31 +010072 SAFE_WAIT(NULL, &status);
plars865695b2001-08-27 22:15:12 +000073
Cyril Hrubisd584ad12015-03-05 14:08:31 +010074 if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) {
75 tst_resm(TPASS, "pause() did not return after SIGKILL");
76 continue;
plars865695b2001-08-27 22:15:12 +000077 }
78
Cyril Hrubisd584ad12015-03-05 14:08:31 +010079 if (WIFSIGNALED(status)) {
80 tst_resm(TFAIL, "child killed by %s unexpectedly",
81 tst_strsig(WTERMSIG(status)));
82 continue;
plars865695b2001-08-27 22:15:12 +000083 }
84
Cyril Hrubisd584ad12015-03-05 14:08:31 +010085 tst_resm(TFAIL, "child exited with %i", WEXITSTATUS(status));
Garrett Cooper2c282152010-12-16 00:55:50 -080086 }
plars865695b2001-08-27 22:15:12 +000087
plars865695b2001-08-27 22:15:12 +000088 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -080089 tst_exit();
plars865695b2001-08-27 22:15:12 +000090
Garrett Cooper2c282152010-12-16 00:55:50 -080091}
plars865695b2001-08-27 22:15:12 +000092
Mike Frysingerc57fba52014-04-09 18:56:30 -040093void do_child(void)
robbiewd34d5812005-07-11 22:28:09 +000094{
robbiewd34d5812005-07-11 22:28:09 +000095 TEST(pause());
subrata_modakbdbaec52009-02-26 12:14:51 +000096
robbiewd34d5812005-07-11 22:28:09 +000097 tst_resm(TFAIL, "Unexpected return from pause()");
Cyril Hrubis32f179b2015-03-05 13:35:45 +010098
Cyril Hrubisd584ad12015-03-05 14:08:31 +010099 exit(0);
robbiewd34d5812005-07-11 22:28:09 +0000100}
101
Mike Frysingerc57fba52014-04-09 18:56:30 -0400102void setup(void)
plars865695b2001-08-27 22:15:12 +0000103{
plars865695b2001-08-27 22:15:12 +0000104 tst_sig(FORK, DEF_HANDLER, cleanup);
105
plars865695b2001-08-27 22:15:12 +0000106 TEST_PAUSE;
plars865695b2001-08-27 22:15:12 +0000107}
108
plars865695b2001-08-27 22:15:12 +0000109
Mike Frysingerc57fba52014-04-09 18:56:30 -0400110void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000111{
plars865695b2001-08-27 22:15:12 +0000112 kill(cpid, SIGKILL);
Chris Dearmanec6edca2012-10-17 19:54:01 -0700113}