NetBSD-Bugs archive

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

lib/53495: sched_get_priority_max/sched_get_priority_min not returning useful values



>Number:         53495
>Category:       lib
>Synopsis:       sched_get_priority_max/sched_get_priority_min not returning useful values
>Confidential:   no
>Severity:       serious
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Aug 02 21:40:00 +0000 2018
>Originator:     Thomas Klausner
>Release:        NetBSD 8.99.22
>Organization:
Curiosity is the very basis of education and if you tell me that 
curiosity killed the cat, I say only that the cat died nobly.
- Arnold Edinborough
>Environment:
	
	
Architecture: x86_64
Machine: amd64
>Description:
The man page describes the functions as follows:

     sched_get_priority_max(policy)
              Returns the maximal priority which may be used for the
              scheduling policy specified by policy.

     sched_get_priority_min(policy)
              Returns the minimal priority which may be used for the
              scheduling policy specified by policy.

and later:

     sched_get_priority_max() and sched_get_priority_min() return the
     maximal/minimal priority value on success.  Otherwise, -1 is returned and
     errno is set to indicate the error.

So programs check for "-1" to detect errors.

However, in NetBSD, -1 is also returned in other cases, see
/usr/src/lib/libc/sys/sched.c:

int
sched_get_priority_min(int policy)
{

        switch (policy) {
        case SCHED_OTHER:
                return PRI_NONE;
        case SCHED_RR:
        case SCHED_FIFO:
                return (int)sysconf(_SC_SCHED_PRI_MIN);
        default:
                errno = EINVAL;
                return -1;
        }
}


and

/usr/include/sys/param.h:#define        PRI_NONE                (-1)

I'm not sure what the correct fix is. I suggest returning 0 instead of -1;
I don't know what the definition of PRI_NONE is supposed to be and if that
should be changed, or if the return value should just be zero for both
functions and not use PRI_NONE.

>How-To-Repeat:

#include <sched.h>
int main() {
printf("%d-%d\n", sched_get_priority_max(0), sched_get_priority_min(0));
}

gives:

-1--1


Worse, wxGTK30 pops up unnecessary error messages at runtime.

>Fix:
Return 0, and/or redefine PRI_NONE.

>Unformatted:
 	
 	


Home | Main Index | Thread Index | Old Index