From owner-svn-src-stable@freebsd.org Thu Feb 9 21:19:26 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 69AB8CD8408; Thu, 9 Feb 2017 21:19:26 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::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 44370FA3; Thu, 9 Feb 2017 21:19:26 +0000 (UTC) (envelope-from ngie@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v19LJPp2067969; Thu, 9 Feb 2017 21:19:25 GMT (envelope-from ngie@FreeBSD.org) Received: (from ngie@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v19LJPaC067966; Thu, 9 Feb 2017 21:19:25 GMT (envelope-from ngie@FreeBSD.org) Message-Id: <201702092119.v19LJPaC067966@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: ngie set sender to ngie@FreeBSD.org using -f From: Ngie Cooper Date: Thu, 9 Feb 2017 21:19:25 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r313479 - in stable/10: contrib/netbsd-tests/lib/libc/gen lib/libc/gen X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Feb 2017 21:19:26 -0000 Author: ngie Date: Thu Feb 9 21:19:24 2017 New Revision: 313479 URL: https://svnweb.freebsd.org/changeset/base/313479 Log: MFC r279154,r279397: r279154 (by jilles): nice(): Correct return value and [EPERM] error. PR: 189821 Obtained from: NetBSD Relnotes: yes r279397 (by jilles): nice(): Put back old return value, keeping [EPERM] error. Commit r279154 changed the API and ABI significantly, and {NZERO} is still wrong. Also, preserve errno on success instead of setting it to 0. PR: 189821 Relnotes: yes Modified: stable/10/contrib/netbsd-tests/lib/libc/gen/t_nice.c stable/10/lib/libc/gen/nice.3 stable/10/lib/libc/gen/nice.c Directory Properties: stable/10/ (props changed) Modified: stable/10/contrib/netbsd-tests/lib/libc/gen/t_nice.c ============================================================================== --- stable/10/contrib/netbsd-tests/lib/libc/gen/t_nice.c Thu Feb 9 21:12:26 2017 (r313478) +++ stable/10/contrib/netbsd-tests/lib/libc/gen/t_nice.c Thu Feb 9 21:19:24 2017 (r313479) @@ -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 Modified: stable/10/lib/libc/gen/nice.3 ============================================================================== --- stable/10/lib/libc/gen/nice.3 Thu Feb 9 21:12:26 2017 (r313478) +++ stable/10/lib/libc/gen/nice.3 Thu Feb 9 21:19:24 2017 (r313479) @@ -28,7 +28,7 @@ .\" @(#)nice.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd June 4, 1993 +.Dd February 28, 2015 .Dt NICE 3 .Os .Sh NAME @@ -48,20 +48,48 @@ This interface is obsoleted by .Pp The .Fn nice -function obtains the scheduling priority of the process -from the system and sets it to the priority value specified in -.Fa incr . +function adds +.Fa incr +to the scheduling priority of the process. The priority is a value in the range -20 to 20. The default priority is 0; lower priorities cause more favorable scheduling. 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 0, and +.Va errno +is unchanged. +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 -p1003.1-2008 +except for the return value. +This implementation returns 0 upon successful completion but +the standard requires returning the new nice value, +which could be \-1. .Sh HISTORY A .Fn nice Modified: stable/10/lib/libc/gen/nice.c ============================================================================== --- stable/10/lib/libc/gen/nice.c Thu Feb 9 21:12:26 2017 (r313478) +++ stable/10/lib/libc/gen/nice.c Thu Feb 9 21:19:24 2017 (r313479) @@ -43,14 +43,20 @@ __FBSDID("$FreeBSD$"); * Backwards compatible nice. */ int -nice(incr) - int incr; +nice(int incr) { - int prio; + int saverrno, prio; + saverrno = errno; errno = 0; prio = getpriority(PRIO_PROCESS, 0); - if (prio == -1 && errno) + if (prio == -1 && errno != 0) return (-1); - return (setpriority(PRIO_PROCESS, 0, prio + incr)); + if (setpriority(PRIO_PROCESS, 0, prio + incr) == -1) { + if (errno == EACCES) + errno = EPERM; + return (-1); + } + errno = saverrno; + return (0); }