Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.3k
Closed
Description
Bug report
Bug description:
TheSignalEINTRTest.test_sigwaitinfo test intest_eintr fails on NetBSD. According to the officialPOSIX.1-2024 specification forsigwaitinfo:
"The sigtimedwait() and sigwaitinfo() functions may fail if: [EINTR] The wait was interrupted by an unblocked, caught signal."
NetBSD'ssigwaitinfo() implementation violates POSIX by returningerrno = ECANCELED (87) instead oferrno = EINTR (4) when interrupted by a signal not in the wait set.
Configuration
./configure --with-pydebug
Test
╰─$ ./python-munittesttest._test_eintr.SignalEINTRTest.test_sigwaitinfo-vtest_sigwaitinfo (test._test_eintr.SignalEINTRTest.test_sigwaitinfo) ...ERROR======================================================================ERROR:test_sigwaitinfo (test._test_eintr.SignalEINTRTest.test_sigwaitinfo)----------------------------------------------------------------------Traceback (mostrecentcalllast):File"/home/blue/Desktop/cpython/Lib/test/_test_eintr.py",line440,intest_sigwaitinfoself.check_sigwait(wait_func)~~~~~~~~~~~~~~~~~~^^^^^^^^^^^File"/home/blue/Desktop/cpython/Lib/test/_test_eintr.py",line430,incheck_sigwaitwait_func(signum)~~~~~~~~~^^^^^^^^File"/home/blue/Desktop/cpython/Lib/test/_test_eintr.py",line438,inwait_funcsignal.sigwaitinfo([signum])~~~~~~~~~~~~~~~~~~^^^^^^^^^^OSError: [Errno87]Operationcanceled----------------------------------------------------------------------Ran1testin0.112sFAILED (errors=1)
Reproduction
I created a minimal C program that reproduces the same issue.
#include<signal.h>#include<pthread.h>#include<unistd.h>#include<sys/wait.h>#include<stdio.h>#include<stdlib.h>#include<errno.h>#include<string.h>volatilesig_atomic_tgot_sigalrm=0;voidsigalrm_handler(intsig) {got_sigalrm=1;printf("SIGALRM handler called\n");}intmain() {printf("sigwaitinfo interruption test\n");sigset_tsigset;siginfo_tinfo;inttarget_signal=SIGUSR1;// Set SIGALRM handlerstructsigactionsa= {0};sa.sa_handler=sigalrm_handler;sigaction(SIGALRM,&sa,NULL);// Block SIGUSR1 and save old masksigemptyset(&sigset);sigaddset(&sigset,target_signal);pthread_sigmask(SIG_BLOCK,&sigset,NULL);printf("Blocked SIGUSR1, waiting with sigwaitinfo...\n");pid_tpid=fork();if (pid==0) {sleep(1);printf("Child: sending SIGALRM to interrupt parent\n");kill(getppid(),SIGALRM);exit(0); }printf("Parent: calling sigwaitinfo([SIGUSR1])...\n");intresult=sigwaitinfo(&sigset,&info);if (result==-1) {printf("sigwaitinfo failed: errno = %d (%s)\n",errno,strerror(errno)); }printf("SIGALRM handler was called: %s\n",got_sigalrm ?"yes" :"no");intstatus;waitpid(pid,&status,0);printf("Child exited with status: %d\n",WEXITSTATUS(status));return0;}
Output on NetBSD 10.0:
sigwaitinfo interruption testBlocked SIGUSR1, waiting with sigwaitinfo...Parent: calling sigwaitinfo([SIGUSR1])...Child: sending SIGALRM to interrupt parentSIGALRM handler calledsigwaitinfo failed: errno = 87 (Operation canceled)SIGALRM handler was called: yesChild exited with status: 0Expected POSIX-compliant output (Linux):
sigwaitinfo interruption testBlocked SIGUSR1, waiting with sigwaitinfo...Parent: calling sigwaitinfo([SIGUSR1])...Child: sending SIGALRM to interrupt parentSIGALRM handler calledsigwaitinfo failed: errno = 4 (Interrupted system call)SIGALRM handler was called: yesChild exited with status: 0CPython versions tested on:
CPython main branch, 3.15, 3.14, 3.13
Operating systems tested on:
Other