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