1 /*
2 * Copyright (c) International Business Machines Corp., 2001
3 * 07/2001 Ported by Wayne Boyer
4 * Copyright (c) 2016 Cyril Hrubis <chrubis@suse.cz>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 * the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 */
20 /*
21 * Verify that, nice(2) fails when, a non-root user attempts to increase
22 * the priority of a process by specifying a negative increment value.
23 */
24 #include <pwd.h>
25 #include <unistd.h>
26 #include <errno.h>
27 #include "tst_test.h"
28
29 #define NICEINC -10
30
verify_nice(void)31 static void verify_nice(void)
32 {
33 TEST(nice(NICEINC));
34
35 if (TST_RET != -1) {
36 tst_res(TFAIL, "nice(%i) succeded unexpectedly (returned %li)",
37 NICEINC, TST_RET);
38 return;
39 }
40
41 if (TST_ERR != EPERM) {
42 tst_res(TFAIL | TTERRNO, "nice(%i) should fail with EPERM",
43 NICEINC);
44 return;
45 }
46
47 tst_res(TPASS, "nice(%i) failed with EPERM", NICEINC);
48 }
49
setup(void)50 static void setup(void)
51 {
52 struct passwd *ltpuser;
53
54 ltpuser = SAFE_GETPWNAM("nobody");
55 SAFE_SETUID(ltpuser->pw_uid);
56 }
57
58 static struct tst_test test = {
59 .setup = setup,
60 .test_all = verify_nice,
61 .needs_root = 1,
62 };
63