Date: Sun, 22 Feb 2015 13:36:44 +0000 (UTC) From: Jilles Tjoelker <jilles@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r279154 - in head: contrib/netbsd-tests/lib/libc/gen lib/libc/gen Message-ID: <201502221336.t1MDaimK042770@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: jilles Date: Sun Feb 22 13:36:44 2015 New Revision: 279154 URL: https://svnweb.freebsd.org/changeset/base/279154 Log: nice(): Correct return value and [EPERM] error. PR: 189821 Obtained from: NetBSD Relnotes: yes Modified: head/contrib/netbsd-tests/lib/libc/gen/t_nice.c head/lib/libc/gen/nice.3 head/lib/libc/gen/nice.c Modified: head/contrib/netbsd-tests/lib/libc/gen/t_nice.c ============================================================================== --- head/contrib/netbsd-tests/lib/libc/gen/t_nice.c Sun Feb 22 11:11:05 2015 (r279153) +++ head/contrib/netbsd-tests/lib/libc/gen/t_nice.c Sun Feb 22 13:36:44 2015 (r279154) @@ -72,11 +72,6 @@ ATF_TC_BODY(nice_err, tc) { int i; -#ifdef __FreeBSD__ - atf_tc_expect_fail("nice(incr) with incr < 0 fails with unprivileged " - "users and sets errno == EPERM; see PR # 189821 for more details"); -#endif - /* * The call should fail with EPERM if the * supplied parameter is negative and the @@ -98,11 +93,7 @@ ATF_TC_HEAD(nice_priority, tc) ATF_TC_BODY(nice_priority, tc) { -#ifdef __FreeBSD__ - int i, pri, pri2, nic; -#else int i, pri, nic; -#endif pid_t pid; int sta; @@ -115,10 +106,8 @@ ATF_TC_BODY(nice_priority, tc) pri = getpriority(PRIO_PROCESS, 0); ATF_REQUIRE(errno == 0); -#ifdef __NetBSD__ if (nic != pri) atf_tc_fail("nice(3) and getpriority(2) conflict"); -#endif /* * Also verify that the nice(3) values @@ -130,18 +119,10 @@ ATF_TC_BODY(nice_priority, tc) if (pid == 0) { errno = 0; -#ifdef __FreeBSD__ pri = getpriority(PRIO_PROCESS, 0); -#else - pri2 = getpriority(PRIO_PROCESS, 0); -#endif ATF_REQUIRE(errno == 0); -#ifdef __FreeBSD__ - if (pri != pri2) -#else if (nic != pri) -#endif _exit(EXIT_FAILURE); _exit(EXIT_SUCCESS); @@ -180,11 +161,7 @@ ATF_TC_HEAD(nice_thread, tc) ATF_TC_BODY(nice_thread, tc) { pthread_t tid[5]; -#ifdef __FreeBSD__ - int pri, rv, val; -#else int rv, val; -#endif size_t i; /* @@ -196,12 +173,7 @@ ATF_TC_BODY(nice_thread, tc) val = nice(i); ATF_REQUIRE(val != -1); -#ifdef __FreeBSD__ - pri = getpriority(PRIO_PROCESS, 0); - rv = pthread_create(&tid[i], NULL, threadfunc, &pri); -#else rv = pthread_create(&tid[i], NULL, threadfunc, &val); -#endif ATF_REQUIRE(rv == 0); rv = pthread_join(tid[i], NULL); Modified: head/lib/libc/gen/nice.3 ============================================================================== --- head/lib/libc/gen/nice.3 Sun Feb 22 11:11:05 2015 (r279153) +++ head/lib/libc/gen/nice.3 Sun Feb 22 13:36:44 2015 (r279154) @@ -28,7 +28,7 @@ .\" @(#)nice.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd June 4, 1993 +.Dd February 22, 2015 .Dt NICE 3 .Os .Sh NAME @@ -57,11 +57,34 @@ Only the super-user may lower priorities .Pp Children inherit the priority of their parent processes via .Xr fork 2 . +.Sh RETURN VALUES +Upon successful completion, +.Fn nice +returns the new nice value minus +.Dv NZERO . +Otherwise, \-1 is returned, the process' nice value is not changed, and +.Va errno +is set to indicate the error. +.Sh ERRORS +The +.Fn nice +function will fail if: +.Bl -tag -width Er +.It Bq Er EPERM +The +.Fa incr +argument is negative and the caller does not have appropriate privileges. +.El .Sh SEE ALSO .Xr nice 1 , .Xr fork 2 , .Xr setpriority 2 , .Xr renice 8 +.Sh STANDARDS +The +.Fn nice +function conforms to +.St -xpg4.2 . .Sh HISTORY A .Fn nice Modified: head/lib/libc/gen/nice.c ============================================================================== --- head/lib/libc/gen/nice.c Sun Feb 22 11:11:05 2015 (r279153) +++ head/lib/libc/gen/nice.c Sun Feb 22 13:36:44 2015 (r279154) @@ -43,14 +43,18 @@ __FBSDID("$FreeBSD$"); * Backwards compatible nice. */ int -nice(incr) - int incr; +nice(int incr) { int prio; errno = 0; prio = getpriority(PRIO_PROCESS, 0); if (prio == -1 && errno) - return (-1); - return (setpriority(PRIO_PROCESS, 0, prio + incr)); + return -1; + if (setpriority(PRIO_PROCESS, 0, prio + incr) == -1) { + if (errno == EACCES) + errno = EPERM; + return -1; + } + return getpriority(PRIO_PROCESS, 0); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201502221336.t1MDaimK042770>