summaryrefslogtreecommitdiffstats
path: root/kernel/tests/lib/tst_coredump.c
blob: 83aa2c3980d9552e59de6733e6404b1017ce87b2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Copyright (c) 2019 Red Hat, Inc.
 */

#define TST_NO_DEFAULT_MAIN

#include <sys/time.h>
#include <sys/resource.h>

#include "tst_test.h"
#include "tst_coredump.h"

void tst_no_corefile(int verbose)
{
	struct rlimit new_r, old_r;

	SAFE_GETRLIMIT(RLIMIT_CORE, &old_r);
	if (old_r.rlim_max >= 1 || geteuid() == 0) {
		/*
		 * 1 is a special value, that disables core-to-pipe.
		 * At the same time it is small enough value for
		 * core-to-file, so it skips creating cores as well.
		 */
		new_r.rlim_cur = 1;
		new_r.rlim_max = 1;
		SAFE_SETRLIMIT(RLIMIT_CORE, &new_r);

		if (verbose) {
			tst_res(TINFO,
				"Avoid dumping corefile for process(pid=%d)",
				getpid());
		}
	}
}