From f9c5e3f5f61cd380f8a17c814766fc3730b7fbdf Mon Sep 17 00:00:00 2001 From: Pablo Galindo Date: Wed, 2 Sep 2020 15:29:12 +0100 Subject: [PATCH] bpo-41675: Modernize siginterrupt calls (GH-22028) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit siginterrupt is deprecated: ./Modules/signalmodule.c:667:5: warning: ‘siginterrupt’ is deprecated: Use sigaction with SA_RESTART instead [-Wdeprecated-declarations] 667 | if (siginterrupt(signalnum, flag)<0) { --- .../2020-08-31-14-53-17.bpo-41675.VSoqWU.rst | 3 +++ Modules/signalmodule.c | 14 +++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2020-08-31-14-53-17.bpo-41675.VSoqWU.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2020-08-31-14-53-17.bpo-41675.VSoqWU.rst b/Misc/NEWS.d/next/Core and Builtins/2020-08-31-14-53-17.bpo-41675.VSoqWU.rst new file mode 100644 index 00000000000..aa102f8fe43 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2020-08-31-14-53-17.bpo-41675.VSoqWU.rst @@ -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. diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 7bc1b535e6e..c49a3ea52e7 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -664,7 +664,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; }