Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

signal.signal, et al, doesn't support [SIGRTMIN,SIGRTMAX] on FreeBSD (not included in NSIG) #91145

Closed
ngie-eign mannequin opened this issue Mar 11, 2022 · 4 comments
Closed
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes OS-freebsd

Comments

@ngie-eign
Copy link
Mannequin

ngie-eign mannequin commented Mar 11, 2022

BPO 46989
Nosy @ngie-eign, @koobs

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = None
created_at = <Date 2022-03-11.19:12:02.712>
labels = ['3.7', '3.8', '3.9', '3.10', '3.11']
title = "signal.signal, et al, doesn't support [SIGRTMIN,SIGRTMAX] on FreeBSD (not included in NSIG)"
updated_at = <Date 2022-03-11.19:12:02.712>
user = 'https://github.com/ngie-eign'

bugs.python.org fields:

activity = <Date 2022-03-11.19:12:02.712>
actor = 'ngie'
assignee = 'none'
closed = False
closed_date = None
closer = None
components = ['FreeBSD']
creation = <Date 2022-03-11.19:12:02.712>
creator = 'ngie'
dependencies = []
files = []
hgrepos = []
issue_num = 46989
keywords = []
message_count = 1.0
messages = ['414932']
nosy_count = 2.0
nosy_names = ['ngie', 'koobs']
pr_nums = []
priority = 'normal'
resolution = None
stage = None
status = 'open'
superseder = None
type = None
url = 'https://bugs.python.org/issue46989'
versions = ['Python 3.7', 'Python 3.8', 'Python 3.9', 'Python 3.10', 'Python 3.11']

@ngie-eign
Copy link
Mannequin Author

ngie-eign mannequin commented Mar 11, 2022

As noted in https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=262487, cpython relies on the definition of NSIG when building signal handlers to determine what signals are and aren't invalid.

Unfortunately on FreeBSD, NSIG doesn't include [SIGRTMIN,SIGRTMAX], as shown below:

$ python2
Python 2.7.18 (default, Dec  3 2020, 01:19:40) 
[GCC 4.2.1 Compatible FreeBSD Clang 8.0.1 (tags/RELEASE_801/final 366581)] on freebsd12
Type "help", "copyright", "credits" or "license" for more information.
>>> import signal
>>> signal.signal(signal.SIGRTMIN, signal.SIG_DFL)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: signal number out of range
>>> exit()
$ python3
Python 3.8.12 (default, Jan  4 2022, 01:10:15) 
[Clang 10.0.1 (git@github.com:llvm/llvm-project.git llvmorg-10.0.1-0-gef32c611a on freebsd12
Type "help", "copyright", "credits" or "license" for more information.
>>> import signal
>>> signal.signal(signal.SIGRTMIN, signal.SIG_IGN)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.8/signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal number out of range
>>> exit()
$ python3.11
Python 3.11.0a3 (main, Feb  4 2022, 02:34:52) [Clang 10.0.1 (git@github.com:llvm/llvm-project.git llvmorg-10.0.1-0-gef32c611aa on freebsd12
Type "help", "copyright", "credits" or "license" for more information.
>>> import signal
>>> signal.signal(signal.SIGRTMIN, signal.SIG_IGN)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.11/signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: signal number out of range
>>> exit()
$

This results in a cpython interface which doesn't match the OS's signal(3) interface:

$ cat signal_rtmin.c 
#include <err.h>
#include <signal.h>

int     
main(void)      
{       

        if (signal(SIGRTMIN, SIG_DFL) == SIG_ERR)
                warn("signal");
        return (0);
}
$ cc -o signal_rtmin -Wall signal_rtmin.c
$ ./signal_rtmin
$ uname -a
FreeBSD picasso.local 12.2-RELEASE-p7 FreeBSD 12.2-RELEASE-p7 GENERIC  amd64
$

Linux includes [SIGRTMIN,SIGRTMAX] in NSIG, which means it allows these values in signal.signal without issue (confirmed on Ubuntu 18.04.6 LTS).

While one can definitely argue that this is an OS portability defect and this should be resolved in FreeBSD (and thus, not fixed in cpython), it doesn't address existing behavior on older versions of FreeBSD where this hasn't been resolved yet.

FreeBSD bug: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=262487

@ngie-eign ngie-eign mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes labels Mar 11, 2022
@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
@vstinner
Copy link
Member

This issue is a duplicate of #64783.

@tiran
Copy link
Member

tiran commented May 5, 2022

The test is incorrect and breaks Emscripten because it also checks the value of SIG_IGN and SIG_DFL. Both constants are not values but actually pointers we just happen to be 0 and 1 on most POSIX-like OS.

@tiran tiran reopened this May 5, 2022
@vstinner
Copy link
Member

vstinner commented May 5, 2022

It seems like it has been fixed by #92350

@vstinner vstinner closed this as completed May 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes OS-freebsd
Projects
None yet
Development

No branches or pull requests

3 participants
@vstinner @tiran and others