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
main(int ac,char ** av)41 int main(int ac, char **av)
42 {
43 int lc;
44 int status;
45
46 tst_parse_opts(ac, av, NULL, NULL);
47
48 setup();
49
50 for (lc = 0; TEST_LOOPING(lc); lc++) {
51 tst_count = 0;
52
53 if ((cpid = tst_fork()) == -1)
54 tst_brkm(TBROK | TERRNO, NULL, "fork() failed");
55
56 if (cpid == 0)
57 do_child();
58
59 TST_PROCESS_STATE_WAIT(cleanup, cpid, 'S');
60
61 kill(cpid, SIGKILL);
62
63 SAFE_WAIT(NULL, &status);
64
65 if (WIFSIGNALED(status) && WTERMSIG(status) == SIGKILL) {
66 tst_resm(TPASS, "pause() did not return after SIGKILL");
67 continue;
68 }
69
70 if (WIFSIGNALED(status)) {
71 tst_resm(TFAIL, "child killed by %s unexpectedly",
72 tst_strsig(WTERMSIG(status)));
73 continue;
74 }
75
76 tst_resm(TFAIL, "child exited with %i", WEXITSTATUS(status));
77 }
78
79 cleanup();
80 tst_exit();
81
82 }
83
do_child(void)84 void do_child(void)
85 {
86 TEST(pause());
87
88 tst_resm(TFAIL, "Unexpected return from pause()");
89
90 exit(0);
91 }
92
setup(void)93 void setup(void)
94 {
95 tst_sig(FORK, DEF_HANDLER, cleanup);
96
97 TEST_PAUSE;
98 }
99
100
cleanup(void)101 void cleanup(void)
102 {
103 kill(cpid, SIGKILL);
104 }
105