diff options
author | Konstantin Belousov <kib@FreeBSD.org> | 2022-04-24 22:10:18 +0000 |
---|---|---|
committer | Konstantin Belousov <kib@FreeBSD.org> | 2022-04-25 14:22:09 +0000 |
commit | 67fc95025ccfc696ea5eaea0ecb1fff295760723 (patch) | |
tree | 1ecf3784034d15b4ce0cf64a158addaea4c4f685 | |
parent | 0a736f0a6aeb0bf8b7e677fab8b562704eb4980e (diff) | |
download | src-67fc95025ccfc696ea5eaea0ecb1fff295760723.tar.gz src-67fc95025ccfc696ea5eaea0ecb1fff295760723.zip |
sched_getaffinity(3): more compatibility with Linux
Report EINVAL instead of EDEADLK when impossible cpu mask is set.
Noted by: dchagin
Reviewed by: dchagin (previous version), markj
Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D35045
-rw-r--r-- | lib/libc/gen/sched_setaffinity.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/libc/gen/sched_setaffinity.c b/lib/libc/gen/sched_setaffinity.c index 91ab2a401bda..09e2b9097d5a 100644 --- a/lib/libc/gen/sched_setaffinity.c +++ b/lib/libc/gen/sched_setaffinity.c @@ -34,6 +34,7 @@ int sched_setaffinity(pid_t pid, size_t cpusetsz, const cpuset_t *cpuset) { cpuset_t c; + int error; if (cpusetsz > sizeof(cpuset_t)) { errno = EINVAL; @@ -42,6 +43,10 @@ sched_setaffinity(pid_t pid, size_t cpusetsz, const cpuset_t *cpuset) memset(&c, 0, sizeof(c)); memcpy(&c, cpuset, cpusetsz); } - return (cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, - pid == 0 ? -1 : pid, sizeof(cpuset_t), &c)); + error = cpuset_setaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, + pid == 0 ? -1 : pid, sizeof(cpuset_t), &c); + if (error == -1 && errno == EDEADLK) + errno = EINVAL; + + return (error); } |