• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) International Business Machines Corp., 2001
4  * Ported to LTP: Wayne Boyer
5  * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
6  */
7 /*
8  *  Verify that, nice(2) fails when, a non-root user attempts to increase
9  *  the priority of a process by specifying a negative increment value.
10  */
11 #include <pwd.h>
12 #include <unistd.h>
13 #include <errno.h>
14 #include "tst_test.h"
15 
16 #define NICEINC -10
17 
verify_nice(void)18 static void verify_nice(void)
19 {
20 	TEST(nice(NICEINC));
21 
22 	if (TST_RET != -1) {
23 		tst_res(TFAIL, "nice(%i) succeded unexpectedly (returned %li)",
24 			NICEINC, TST_RET);
25 		return;
26 	}
27 
28 	if (TST_ERR != EPERM) {
29 		tst_res(TFAIL | TTERRNO, "nice(%i) should fail with EPERM",
30 			NICEINC);
31 		return;
32 	}
33 
34 	tst_res(TPASS, "nice(%i) failed with EPERM", NICEINC);
35 }
36 
setup(void)37 static void setup(void)
38 {
39 	struct passwd *ltpuser;
40 
41 	ltpuser = SAFE_GETPWNAM("nobody");
42 	SAFE_SETUID(ltpuser->pw_uid);
43 }
44 
45 static struct tst_test test = {
46 	.setup = setup,
47 	.test_all = verify_nice,
48 	.needs_root = 1,
49 };
50