Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <CAK4o1WyG7kqqUp1dADCW2DDbSLswi4p2xb+4dyTALW8WVQSL2g@mail.gmail.com>
Date: Mon, 15 Apr 2013 08:31:45 +0100
From: Justin Cormack <justin@...cialbusservice.com>
To: musl@...ts.openwall.com
Subject: Re: nice standards complaince issue

On Mon, Apr 15, 2013 at 2:45 AM, Rich Felker <dalias@...ifal.cx> wrote:

> On Sat, Apr 13, 2013 at 11:23:08PM +0100, Justin Cormack wrote:
> > Since glibc 2.2.4, nice() is implemented as a library function that calls
> > getpriority(2) to obtain the new nice value to be returned  to  the
> >  caller.   With this implementation, a successful call can legitimately
> > return -1.  To reliably detect an error, set errno to 0 before the call,
> > and check its value when nice() returns -1.
>
> Thanks for the heads-up. Actually, I think there's a much bigger issue
> with both nice and setpriority: they're affecting one thread rather
> than the process. This may technically not be non-conforming as long
> as SCHED_OTHER scheduling is in effect, but it's sketchy. Basically
> this all stems from a complete failure of Linux to support process
> contention scope and the [PS] option of POSIX... (despite glibc
> claiming to support it!)
>
> In any case, the issue you reported should be fixed. Do you have a
> proposed patch?
>

Something like

--- src/unistd/nice.c-old 2013-04-15 08:16:06.855064898 +0100
+++ src/unistd/nice.c 2013-04-15 08:21:55.920848795 +0100
@@ -3,10 +3,11 @@
 #include "syscall.h"

 int nice(int inc)
-{
 #ifdef SYS_nice
- return syscall(SYS_nice, inc);
+ int ret = syscall(SYS_nice, inc);
 #else
- return setpriority(PRIO_PROCESS, 0, getpriority(PRIO_PROCESS, 0)+inc);
+ int ret = setpriority(PRIO_PROCESS, 0, getpriority(PRIO_PROCESS, 0)+inc);
 #endif
+        if (ret < 0) return ret;
+        return 20-getpriority(PRIO_PROCESS, 0);
 }

Content of type "text/html" skipped

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.