Home | History | Annotate | Download | only in nice
      1 /*
      2  * Copyright (c) International Business Machines  Corp., 2001
      3  *  07/2001 Ported by Wayne Boyer
      4  * Copyright (c) 2016 Cyril Hrubis <chrubis (at) 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 
     31 static void verify_nice(void)
     32 {
     33 	TEST(nice(NICEINC));
     34 
     35 	if (TEST_RETURN != -1) {
     36 		tst_res(TFAIL, "nice(%i) succeded unexpectedly (returned %li)",
     37 			NICEINC, TEST_RETURN);
     38 		return;
     39 	}
     40 
     41 	if (TEST_ERRNO != 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 
     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 	.tid = "nice04",
     60 	.setup = setup,
     61 	.test_all = verify_nice,
     62 	.needs_root = 1,
     63 };
     64