Skip to content

Commit 878403d

Browse files
pablogsalmcepl
authored andcommitted
Modernize siginterrupt calls
The implementation of `signal.siginterrupt` now uses `sigaction` (if it is available in the system) instead of the deprecated `siginterrupt`. Fixes: gh#python#85841 From-PR: gh#python/cpython!22028 Patch: bpo-41675-modernize-siginterrupt.patch
1 parent d8877aa commit 878403d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The implementation of :func:`signal.siginterrupt` now uses :c:func:`sigaction`
2+
(if it is available in the system) instead of the deprecated :c:func:`siginterrupt`.
3+
Patch by Pablo Galindo.

Modules/signalmodule.c

+13-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,19 @@ signal_siginterrupt_impl(PyObject *module, int signalnum, int flag)
532532
"signal number out of range");
533533
return NULL;
534534
}
535-
if (siginterrupt(signalnum, flag)<0) {
535+
#ifdef HAVE_SIGACTION
536+
struct sigaction act;
537+
(void) sigaction(signalnum, NULL, &act);
538+
if (flag) {
539+
act.sa_flags &= ~SA_RESTART;
540+
}
541+
else {
542+
act.sa_flags |= SA_RESTART;
543+
}
544+
if (sigaction(signalnum, &act, NULL) < 0) {
545+
#else
546+
if (siginterrupt(signalnum, flag) < 0) {
547+
#endif
536548
PyErr_SetFromErrno(PyExc_OSError);
537549
return NULL;
538550
}

0 commit comments

Comments
 (0)