This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: signal.signal, et al, doesn't support [SIGRTMIN,SIGRTMAX] on FreeBSD (not included in NSIG)
Type: Stage:
Components: FreeBSD Versions: Python 3.11, Python 3.10, Python 3.9, Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: koobs, ngie
Priority: normal Keywords:

Created on 2022-03-11 19:12 by ngie, last changed 2022-04-11 14:59 by admin.

Messages (1)
msg414932 - (view) Author: Enji Cooper (ngie) * Date: 2022-03-11 19:12
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
History
Date User Action Args
2022-04-11 14:59:57adminsetgithub: 91145
2022-03-11 19:12:02ngiecreate