• 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 /*\
9  * [Description]
10  *
11  * Verify that, nice(2) fails when, a non-root user attempts to increase
12  * the priority of a process by specifying a negative increment value.
13  */
14 #include <pwd.h>
15 #include <unistd.h>
16 #include <errno.h>
17 #include "tst_test.h"
18 
19 #define NICEINC -10
20 
verify_nice(void)21 static void verify_nice(void)
22 {
23 	TEST(nice(NICEINC));
24 
25 	if (TST_RET != -1) {
26 		tst_res(TFAIL, "nice(%i) succeded unexpectedly (returned %li)",
27 			NICEINC, TST_RET);
28 		return;
29 	}
30 
31 	if (TST_ERR != EPERM) {
32 		tst_res(TFAIL | TTERRNO, "nice(%i) should fail with EPERM",
33 			NICEINC);
34 		return;
35 	}
36 
37 	tst_res(TPASS, "nice(%i) failed with EPERM", NICEINC);
38 }
39 
setup(void)40 static void setup(void)
41 {
42 	struct passwd *ltpuser;
43 
44 	ltpuser = SAFE_GETPWNAM("nobody");
45 	SAFE_SETUID(ltpuser->pw_uid);
46 }
47 
48 static struct tst_test test = {
49 	.setup = setup,
50 	.test_all = verify_nice,
51 	.needs_root = 1,
52 };
53