mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Fix the return value of pthread_getschedparam in musl libc
@ 2020-05-20  2:09 tangyizhou
  2020-05-20 15:50 ` dalias
  0 siblings, 1 reply; 6+ messages in thread
From: tangyizhou @ 2020-05-20  2:09 UTC (permalink / raw)
  To: musl; +Cc: Wanghui (John), Huangshuai (OSLab), dalias

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

Hi,

From the latest upstream, I find the return value of pthread_getschedparam() is wrong when syscall sched_getparam succeeds but sched_getscheduler fails. It is rare to see this situation. When it happens, pthread_getschedparam() will return r which must be 0, that means a success according to POSIX 2017 specification. It's wrong.

Also, POSIX 2017 specification says an error number shall be returned to indicate the error. I think returning -*policy is appropriate because syscall sched_getscheduler returns an negative error code in kernel like Linux when it fails.

Here is my patch. I want to be Cc'd on replies. Thanks.

diff --git a/src/thread/pthread_getschedparam.c b/src/thread/pthread_getschedparam.c
index 1cba073d..8203d609 100644
--- a/src/thread/pthread_getschedparam.c
+++ b/src/thread/pthread_getschedparam.c
@@ -12,6 +12,9 @@ int pthread_getschedparam(pthread_t t, int *restrict policy, struct sched_param
                if (!r) {
                        *policy = __syscall(SYS_sched_getscheduler, t->tid);
                }
+               if (*policy < 0) {
+                       r = -*policy;
+               }
        }
        UNLOCK(t->killlock);
        return r;


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

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

end of thread, other threads:[~2020-05-28 16:09 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-20  2:09 [musl] Fix the return value of pthread_getschedparam in musl libc tangyizhou
2020-05-20 15:50 ` dalias
2020-05-22  1:53   ` tangyizhou
2020-05-22  2:26     ` dalias
2020-05-28 14:27       ` tangyizhou
2020-05-28 16:09         ` dalias

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).