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