Skip to content

Commit

Permalink
Modernize siginterrupt calls
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pablogsal authored and mcepl committed May 16, 2024
1 parent d8877aa commit 878403d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
The implementation of :func:`signal.siginterrupt` now uses :c:func:`sigaction`
(if it is available in the system) instead of the deprecated :c:func:`siginterrupt`.
Patch by Pablo Galindo.
14 changes: 13 additions & 1 deletion Modules/signalmodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,19 @@ signal_siginterrupt_impl(PyObject *module, int signalnum, int flag)
"signal number out of range");
return NULL;
}
if (siginterrupt(signalnum, flag)<0) {
#ifdef HAVE_SIGACTION
struct sigaction act;
(void) sigaction(signalnum, NULL, &act);
if (flag) {
act.sa_flags &= ~SA_RESTART;
}
else {
act.sa_flags |= SA_RESTART;
}
if (sigaction(signalnum, &act, NULL) < 0) {
#else
if (siginterrupt(signalnum, flag) < 0) {
#endif
PyErr_SetFromErrno(PyExc_OSError);
return NULL;
}
Expand Down

0 comments on commit 878403d

Please sign in to comment.