New submission from Enji Cooper <yaneurab...@gmail.com>:

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 (g...@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 
(g...@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

----------
components: FreeBSD
messages: 414932
nosy: koobs, ngie
priority: normal
severity: normal
status: open
title: signal.signal, et al, doesn't support [SIGRTMIN,SIGRTMAX] on FreeBSD 
(not included in NSIG)
versions: Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46989>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to