Skip to content

Conversation

kulikjak
Copy link
Contributor

@kulikjak kulikjak commented Sep 23, 2020

Python presumes that any negative number returned from sched_get_priority_min or sched_get_priority_max indicates that error has occurred. However, neither Linux manual pages nor POSIX.1-2001 specification forbids negative values to be returned; only -1 has a special meaning for error.

https://bugs.python.org/issue41839

@kulikjak
Copy link
Contributor Author

kulikjak commented Nov 2, 2020

If this seems too dangerous to merge, we can use the variant used by OmniOS instead, which makes the change Solaris specific.

https://github.com/omniosorg/omnios-build/blob/master/build/python313/patches/mod-posix-sched_priority.patch

@jstasiak
Copy link
Contributor

jstasiak commented Nov 5, 2020

Is it guaranteed that a successul syscall clears errno? Because if yes, then the if (max == -1) will still report legitimate -1 priority as an error. The illumos man page says "If unsuccessful, they return -1 and set errno to indicate the error." and I may be reading too much into this, but if errno is not set to indicate an error is a sufficient condition to conclude there's no error I think?

@kulikjak
Copy link
Contributor Author

kulikjak commented Nov 6, 2020

It is not guaranteed, and this simple case confirms that it is not being cleared:

errno = EINVAL;
res = sched_get_priority_min(SCHED_OTHER);
printf("%d %d\n", res, errno);  // EINVAL is still set

but we can still do it ourselves.

You are right that -1 is still a legitimate priority, and although I don't think it even happens in any Solaris (historically, some schedulers used -60 and 60, the newer ones are using positive values only), it is not impossible (and also, I might be wrong :)).

I updated the code, now it should always work on systems where sched_get_priority_* is POSIX.1-2001 compliant (which is True for Linux as well as all Unix systems) no matter the priority.

@kulikjak kulikjak force-pushed the fix-sched-error-checking branch 2 times, most recently from fe9ee56 to d1a27a6 Compare August 23, 2022 12:02
@kulikjak kulikjak force-pushed the fix-sched-error-checking branch from 5b7ab02 to 4d818a2 Compare March 20, 2023 13:42
kulikjak added a commit to kulikjak/cpython that referenced this pull request Mar 20, 2023
kulikjak added a commit to kulikjak/cpython that referenced this pull request May 9, 2023
@kulikjak kulikjak force-pushed the fix-sched-error-checking branch from 4d818a2 to f55a532 Compare November 7, 2023 09:59
@mtelka
Copy link

mtelka commented Feb 8, 2024

What needs to be done to see this PR merged? The change is obviously improving compatibility with POSIX and there is not known any regression.

Thank you.

kulikjak and others added 2 commits July 14, 2025 13:11
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
kulikjak added a commit to kulikjak/cpython that referenced this pull request Aug 27, 2025
kulikjak added a commit to kulikjak/cpython that referenced this pull request Aug 27, 2025
kulikjak added a commit to kulikjak/cpython that referenced this pull request Aug 27, 2025
kulikjak added a commit to kulikjak/cpython that referenced this pull request Aug 27, 2025
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. 👍

@serhiy-storchaka serhiy-storchaka added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Aug 27, 2025
@serhiy-storchaka serhiy-storchaka merged commit bbcb75c into python:main Aug 27, 2025
49 checks passed
@miss-islington-app
Copy link

Thanks @kulikjak for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖 I'm not a witch! I'm not a witch!

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 27, 2025
…nGH-22374)

(cherry picked from commit bbcb75c)

Co-authored-by: Jakub Kulík <Kulikjak@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Aug 27, 2025

GH-138201 is a backport of this pull request to the 3.14 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Aug 27, 2025
…nGH-22374)

(cherry picked from commit bbcb75c)

Co-authored-by: Jakub Kulík <Kulikjak@gmail.com>
@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Aug 27, 2025
@bedevere-app
Copy link

bedevere-app bot commented Aug 27, 2025

GH-138202 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Aug 27, 2025
serhiy-storchaka pushed a commit that referenced this pull request Aug 27, 2025
…GH-22374) (GH-138202)

(cherry picked from commit bbcb75c)

Co-authored-by: Jakub Kulík <Kulikjak@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants