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