[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#286825: glibc: nice() should set errno=EPERM not EACCES on error



At Wed, 22 Dec 2004 14:12:04 +0000,
Gerrit Pape wrote:
> Hi, according to the man page and
> http://www.opengroup.org/onlinepubs/009695399/functions/nice.html
> nice() should set errno=EPERM in case the incr argument is negative and
> the calling process does not have appropriate privileges.
> 
> $ cat test.c
> #include <errno.h>
> int main() {
>   if (nice(-1) == -1) printf("%d\n", errno);
> }
> $ gcc test.c && ./a.out
> 13
> $ grep 13 /usr/include/asm-generic/errno-base.h
> #define EACCES          13      /* Permission denied */
> $ 

It's like old BSD vs SysV question.  This behavior written in SUS is
SysV derived.  However, BSD returns EACCES like glibc.  Look at info
libc, it describes as follows:

 - Function: int nice (int INCREMENT)
     Increment the nice value of the calling process by INCREMENT.  The
     return value is the new nice value on success, and `-1' on
     failure.  In the case of failure, `errno' will be set to the same
     values as for `setpriority'.

     Here is an equivalent definition of `nice':

          int
          nice (int increment)
          {
            int result, old = getpriority (PRIO_PROCESS, 0);
            result = setpriority (PRIO_PROCESS, 0, old + increment);
            if (result != -1)
                return old + increment;
            else
                return -1;
          }

I think it's not bug - it's expected behavior.  Note that the
definition of between BSD and SysV conflicts each other, so I guess
it's hard to fix SUS description.  

I'll close this report unless you have other opinion.

Regards,
-- gotom



Reply to: