1 // SPDX-License-Identifier: GPL-2.0-or-later
2
3 /*
4 * Copyright (c) International Business Machines Corp., 2002
5 * 01/02/2003 Port to LTP [email protected]
6 * 11/11/2002: Ported to LTP Suite by Ananda
7 * 06/30/2001 Port to Linux [email protected]
8 */
9
10 /*\
11 * [Description]
12 *
13 * Checks that process which called abort() gets killed by SIGIOT and dumps core.
14 *
15 * [Algorithm]
16 * - Fork child.
17 * - Child calls abort.
18 * - Parent checks return status.
19 */
20
21 #include <sys/types.h>
22 #include <sys/wait.h>
23 #include <errno.h>
24 #include <signal.h>
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <unistd.h>
28 #include <sys/resource.h>
29
30 #include "tst_test.h"
31
do_child(void)32 static void do_child(void)
33 {
34 abort();
35 tst_res(TFAIL, "Abort returned");
36 exit(0);
37 }
38
verify_abort(void)39 void verify_abort(void)
40 {
41 int status, kidpid;
42 int sig, core;
43
44 kidpid = SAFE_FORK();
45 if (kidpid == 0)
46 do_child();
47
48 SAFE_WAIT(&status);
49
50 if (!WIFSIGNALED(status)) {
51 tst_res(TFAIL, "Child %s, expected SIGIOT",
52 tst_strstatus(status));
53 return;
54 }
55
56 core = WCOREDUMP(status);
57 sig = WTERMSIG(status);
58
59 if (core == 0)
60 tst_res(TFAIL, "abort() failed to dump core");
61 else
62 tst_res(TPASS, "abort() dumped core");
63
64 if (sig == SIGIOT)
65 tst_res(TPASS, "abort() raised SIGIOT");
66 else
67 tst_res(TFAIL, "abort() raised %s", tst_strsig(sig));
68 }
69
70 #define MIN_RLIMIT_CORE (512 * 1024)
71
setup(void)72 static void setup(void)
73 {
74 struct rlimit rlim;
75
76 /* make sure we get core dumps */
77 SAFE_GETRLIMIT(RLIMIT_CORE, &rlim);
78
79 if (rlim.rlim_max < MIN_RLIMIT_CORE) {
80 if (geteuid() != 0) {
81 tst_brk(TCONF, "hard limit(%lu)less than MIN_RLIMT_CORE(%i)",
82 rlim.rlim_max, MIN_RLIMIT_CORE);
83 }
84 tst_res(TINFO, "Raising rlim_max to %i", MIN_RLIMIT_CORE);
85 rlim.rlim_max = MIN_RLIMIT_CORE;
86 }
87 if (rlim.rlim_cur < MIN_RLIMIT_CORE) {
88 rlim.rlim_cur = MIN_RLIMIT_CORE;
89 SAFE_SETRLIMIT(RLIMIT_CORE, &rlim);
90 }
91 }
92
93 static struct tst_test test = {
94 .needs_tmpdir = 1,
95 .forks_child = 1,
96 .setup = setup,
97 .test_all = verify_abort,
98 };
99