Bug 201826 - Calls to nice(2) will fail with errno set to EACCES rather than EPERM
Summary: Calls to nice(2) will fail with errno set to EACCES rather than EPERM
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: glibc   
(Show other bugs)
Version: 5
Hardware: All
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Keywords:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2006-08-09 04:02 UTC by William Kucharski
Modified: 2007-11-30 22:11 UTC (History)
0 users

Fixed In Version: 2.4.90-20
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2006-08-15 14:19:45 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

Description William Kucharski 2006-08-09 04:02:00 UTC
Description of problem:

The man page for nice(2) states:

ERRORS
       EPERM  The  calling  process attempted to increase its priority by sup-
              plying a negative inc but has  insufficient  privileges.   Under
              Linux  the  CAP_SYS_NICE  capability  is required.  (But see the
              discussion of the RLIMIT_NICE resource limit in setrlimit(2).)

However, glibc() converts a call to nice(2) into a call to setpriority(2)
which WILL return with errno set to EACCES.

An strace of the program:

#include <errno.h>

main()
{
        if (nice(-19) < 0)
                printf("%d\n", errno);
}

shows it in reality calls:

setpriority(PRIO_PROCESS, 0, 4294967277) = -1 EACCES (Permission denied)

Version-Release number of selected component (if applicable):

glibc-2.4.8

How reproducible:

Run the test program above.

Steps to Reproduce:
1. Compile the code snippet above
2. Run
3. See incorrect errno set
  
Actual results:

failure with errno set to EACCES

Expected results:

failure with errno set to EPERM

Additional info:

This isn't just a man page error, as if the legacy nice syscall is invoked,
it reacts as documented.

For example, this program:

#include <sys/types.h>
#include <sys/syscall.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>

main()
{
        if (nice(-19) < 0)
                printf("%d\n", errno);

        if (syscall(__NR_nice, -19) < 0)
                printf("%d\n", errno);
}

will return:

$ ./a.out
13
1

Comment 1 Jakub Jelinek 2006-08-15 14:19:45 UTC
Fixed in upstream CVS and glibc-2.4.90-20 in rawhide.


Note You need to log in before you can comment on or make changes to this bug.