From owner-svn-src-all@FreeBSD.ORG Sun Feb 22 13:36:45 2015 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 8C45670E; Sun, 22 Feb 2015 13:36:45 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 768071F2; Sun, 22 Feb 2015 13:36:45 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t1MDajcX042776; Sun, 22 Feb 2015 13:36:45 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t1MDaimK042770; Sun, 22 Feb 2015 13:36:44 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201502221336.t1MDaimK042770@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Sun, 22 Feb 2015 13:36:44 +0000 (UTC) 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 X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 22 Feb 2015 13:36:45 -0000 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); }