1 /*
2 * Copyright (c) International Business Machines Corp., 2001
3 * 07/2001 John George
4 * Copyright (c) 2018 Cyril Hrubis <chrubis@suse.cz>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 * the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20
21 /*
22 * Check that when a child kills itself by SIGALRM the waiting parent is
23 * correctly notified.
24 *
25 * Fork a child that raises(SIGALRM), the parent checks that SIGALRM was
26 * returned.
27 */
28 #include <stdlib.h>
29 #include <sys/wait.h>
30 #include "tst_test.h"
31
run(void)32 static void run(void)
33 {
34 pid_t pid, rpid;
35 int status;
36
37 pid = SAFE_FORK();
38 if (!pid) {
39 raise(SIGALRM);
40 exit(0);
41 }
42
43 rpid = waitpid(pid, &status, 0);
44 if (rpid < 0)
45 tst_brk(TBROK | TERRNO, "waitpid() failed");
46
47 if (rpid != pid) {
48 tst_res(TFAIL, "waitpid() returned wrong pid %i, expected %i",
49 rpid, pid);
50 } else {
51 tst_res(TPASS, "waitpid() returned correct pid %i", pid);
52 }
53
54 if (!WIFSIGNALED(status)) {
55 tst_res(TFAIL, "WIFSIGNALED() not set in status (%s)",
56 tst_strstatus(status));
57 return;
58 }
59
60 tst_res(TPASS, "WIFSIGNALED() set in status");
61
62 if (WTERMSIG(status) != SIGALRM) {
63 tst_res(TFAIL, "WTERMSIG() != SIGALRM but %s",
64 tst_strsig(WTERMSIG(status)));
65 return;
66 }
67
68 tst_res(TPASS, "WTERMSIG() == SIGALRM");
69 }
70
71 static struct tst_test test = {
72 .forks_child = 1,
73 .test_all = run,
74 };
75