• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2019 Red Hat, Inc.
4  */
5 
6 #define TST_NO_DEFAULT_MAIN
7 
8 #include <sys/time.h>
9 #include <sys/resource.h>
10 
11 #include "tst_test.h"
12 #include "tst_coredump.h"
13 
tst_no_corefile(int verbose)14 void tst_no_corefile(int verbose)
15 {
16 	struct rlimit new_r, old_r;
17 
18 	SAFE_GETRLIMIT(RLIMIT_CORE, &old_r);
19 	if (old_r.rlim_max >= 1 || geteuid() == 0) {
20 		/*
21 		 * 1 is a special value, that disables core-to-pipe.
22 		 * At the same time it is small enough value for
23 		 * core-to-file, so it skips creating cores as well.
24 		 */
25 		new_r.rlim_cur = 1;
26 		new_r.rlim_max = 1;
27 		SAFE_SETRLIMIT(RLIMIT_CORE, &new_r);
28 
29 		if (verbose) {
30 			tst_res(TINFO,
31 				"Avoid dumping corefile for process(pid=%d)",
32 				getpid());
33 		}
34 	}
35 }
36