From: tangyizhou <tangyizhou@huawei.com>
To: "musl@lists.openwall.com" <musl@lists.openwall.com>
Cc: "Wanghui (John)" <john.wanghui@huawei.com>,
"Huangshuai (OSLab)" <elvis.huang@huawei.com>,
"dalias@aerifal.cx" <dalias@aerifal.cx>
Subject: [musl] Fix the return value of pthread_getschedparam in musl libc
Date: Wed, 20 May 2020 02:09:25 +0000 [thread overview]
Message-ID: <4EB7132F5A45D144AC896FC29A83F192011602E1@DGGEML521-MBS.china.huawei.com> (raw)
[-- 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 --]
next reply other threads:[~2020-05-20 9:53 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-20 2:09 tangyizhou [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4EB7132F5A45D144AC896FC29A83F192011602E1@DGGEML521-MBS.china.huawei.com \
--to=tangyizhou@huawei.com \
--cc=dalias@aerifal.cx \
--cc=elvis.huang@huawei.com \
--cc=john.wanghui@huawei.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).