From owner-svn-src-head@FreeBSD.ORG Sat Feb 28 18:22:11 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id E04D88DF; Sat, 28 Feb 2015 18:22:11 +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 CA6C4826; Sat, 28 Feb 2015 18:22:11 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t1SIMBNB009836; Sat, 28 Feb 2015 18:22:11 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t1SIMAEw009831; Sat, 28 Feb 2015 18:22:10 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201502281822.t1SIMAEw009831@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Sat, 28 Feb 2015 18:22:10 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r279397 - 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-head@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Feb 2015 18:22:12 -0000 Author: jilles Date: Sat Feb 28 18:22:10 2015 New Revision: 279397 URL: https://svnweb.freebsd.org/changeset/base/279397 Log: 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 Reported by: bde 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 Sat Feb 28 17:44:31 2015 (r279396) +++ head/contrib/netbsd-tests/lib/libc/gen/t_nice.c Sat Feb 28 18:22:10 2015 (r279397) @@ -93,7 +93,11 @@ 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; @@ -106,8 +110,10 @@ 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 @@ -119,10 +125,18 @@ 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); @@ -161,7 +175,11 @@ 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; /* @@ -173,7 +191,12 @@ 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 Sat Feb 28 17:44:31 2015 (r279396) +++ head/lib/libc/gen/nice.3 Sat Feb 28 18:22:10 2015 (r279397) @@ -28,7 +28,7 @@ .\" @(#)nice.3 8.1 (Berkeley) 6/4/93 .\" $FreeBSD$ .\" -.Dd February 22, 2015 +.Dd February 28, 2015 .Dt NICE 3 .Os .Sh NAME @@ -48,9 +48,9 @@ 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. @@ -60,8 +60,9 @@ Children inherit the priority of their p .Sh RETURN VALUES Upon successful completion, .Fn nice -returns the new nice value minus -.Dv NZERO . +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. @@ -84,7 +85,11 @@ argument is negative and the caller does The .Fn nice function conforms to -.St -xpg4.2 . +.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: head/lib/libc/gen/nice.c ============================================================================== --- head/lib/libc/gen/nice.c Sat Feb 28 17:44:31 2015 (r279396) +++ head/lib/libc/gen/nice.c Sat Feb 28 18:22:10 2015 (r279397) @@ -45,16 +45,18 @@ __FBSDID("$FreeBSD$"); int nice(int incr) { - int prio; + int saverrno, prio; + saverrno = errno; errno = 0; prio = getpriority(PRIO_PROCESS, 0); - if (prio == -1 && errno) - return -1; + if (prio == -1 && errno != 0) + return (-1); if (setpriority(PRIO_PROCESS, 0, prio + incr) == -1) { if (errno == EACCES) errno = EPERM; - return -1; + return (-1); } - return getpriority(PRIO_PROCESS, 0); + errno = saverrno; + return (0); }