mailing list of musl libc
 help / color / mirror / code / Atom feed
* nice standards complaince issue
@ 2013-04-13 22:23 Justin Cormack
  2013-04-15  1:45 ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: Justin Cormack @ 2013-04-13 22:23 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 947 bytes --]

According to the man page, Musl nice is not compliant, it is defined to
return 0 if successful

int nice(int inc)
{
#ifdef SYS_nice
        return syscall(SYS_nice, inc);
#else
        return setpriority(PRIO_PROCESS, 0, getpriority(PRIO_PROCESS,
0)+inc);
#endif
}

However the manpage says it is required to return the new value:

SUSv2 and POSIX.1-2001 specify that nice() should return the new nice
value.  However, the Linux  syscall  and  the  nice() library  function
provided in older versions of (g)libc (earlier than glibc 2.2.4) return 0
on success.  The new nice value can be found using getpriority(2).

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.

[-- Attachment #2: Type: text/html, Size: 1212 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: nice standards complaince issue
  2013-04-13 22:23 nice standards complaince issue Justin Cormack
@ 2013-04-15  1:45 ` Rich Felker
  2013-04-15  7:31   ` Justin Cormack
  0 siblings, 1 reply; 3+ messages in thread
From: Rich Felker @ 2013-04-15  1:45 UTC (permalink / raw)
  To: musl

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?

Rich


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: nice standards complaince issue
  2013-04-15  1:45 ` Rich Felker
@ 2013-04-15  7:31   ` Justin Cormack
  0 siblings, 0 replies; 3+ messages in thread
From: Justin Cormack @ 2013-04-15  7:31 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 1565 bytes --]

On Mon, Apr 15, 2013 at 2:45 AM, Rich Felker <dalias@aerifal.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);
 }

[-- Attachment #2: Type: text/html, Size: 2586 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-04-15  7:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-04-13 22:23 nice standards complaince issue Justin Cormack
2013-04-15  1:45 ` Rich Felker
2013-04-15  7:31   ` Justin Cormack

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).