From 48ce4897f8f8d91d948ecd1241ffab002df2be9e Mon Sep 17 00:00:00 2001 From: Michael Osipov <1983-01-06@gmx.net> Date: Thu, 23 Aug 2018 15:27:19 +0200 Subject: [PATCH] bpo-34412: Make signal.strsignal() work on HP-UX (GH-8786) Introduce a configure check for strsignal(3) which defines HAVE_STRSIGNAL for signalmodule.c. Add some common signals on HP-UX. This change applies for Windows and HP-UX. --- Lib/test/test_signal.py | 1 + .../2018-08-16-19-07-05.bpo-34412.NF5Jm2.rst | 1 + Modules/signalmodule.c | 22 +++++++++++++++++-- configure | 2 +- configure.ac | 2 +- pyconfig.h.in | 3 +++ 6 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2018-08-16-19-07-05.bpo-34412.NF5Jm2.rst diff --git a/Lib/test/test_signal.py b/Lib/test/test_signal.py index ecdffa60a65..d30a2d61290 100644 --- a/Lib/test/test_signal.py +++ b/Lib/test/test_signal.py @@ -60,6 +60,7 @@ class PosixTests(unittest.TestCase): def test_strsignal(self): self.assertIn("Interrupt", signal.strsignal(signal.SIGINT)) self.assertIn("Terminated", signal.strsignal(signal.SIGTERM)) + self.assertIn("Hangup", signal.strsignal(signal.SIGHUP)) # Issue 3864, unknown if this affects earlier versions of freebsd also def test_interprocess_signal(self): diff --git a/Misc/NEWS.d/next/Library/2018-08-16-19-07-05.bpo-34412.NF5Jm2.rst b/Misc/NEWS.d/next/Library/2018-08-16-19-07-05.bpo-34412.NF5Jm2.rst new file mode 100644 index 00000000000..8d7320f25e4 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2018-08-16-19-07-05.bpo-34412.NF5Jm2.rst @@ -0,0 +1 @@ +Make :func:`signal.strsignal` work on HP-UX. Patch by Michael Osipov. diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c index 9de5c2ed181..d1209485827 100644 --- a/Modules/signalmodule.c +++ b/Modules/signalmodule.c @@ -530,9 +530,27 @@ signal_strsignal_impl(PyObject *module, int signalnum) return NULL; } -#ifdef MS_WINDOWS - /* Custom redefinition of POSIX signals allowed on Windows */ +#ifndef HAVE_STRSIGNAL switch (signalnum) { + /* Though being a UNIX, HP-UX does not provide strsignal(3). */ +#ifndef MS_WINDOWS + case SIGHUP: + res = "Hangup"; + break; + case SIGALRM: + res = "Alarm clock"; + break; + case SIGPIPE: + res = "Broken pipe"; + break; + case SIGQUIT: + res = "Quit"; + break; + case SIGCHLD: + res = "Child exited"; + break; +#endif + /* Custom redefinition of POSIX signals allowed on Windows. */ case SIGINT: res = "Interrupt"; break; diff --git a/configure b/configure index 87f3392fec0..4de68432cbc 100755 --- a/configure +++ b/configure @@ -11256,7 +11256,7 @@ for ac_func in alarm accept4 setitimer getitimer bind_textdomain_codeset chown \ sched_get_priority_max sched_setaffinity sched_setscheduler sched_setparam \ sched_rr_get_interval \ sigaction sigaltstack sigfillset siginterrupt sigpending sigrelse \ - sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy symlinkat sync \ + sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy strsignal symlinkat sync \ sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ truncate uname unlinkat unsetenv utimensat utimes waitid waitpid wait3 wait4 \ wcscoll wcsftime wcsxfrm wmemcmp writev _getpty diff --git a/configure.ac b/configure.ac index 749303ee1b5..1e0b7f5e7ba 100644 --- a/configure.ac +++ b/configure.ac @@ -3448,7 +3448,7 @@ AC_CHECK_FUNCS(alarm accept4 setitimer getitimer bind_textdomain_codeset chown \ sched_get_priority_max sched_setaffinity sched_setscheduler sched_setparam \ sched_rr_get_interval \ sigaction sigaltstack sigfillset siginterrupt sigpending sigrelse \ - sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy symlinkat sync \ + sigtimedwait sigwait sigwaitinfo snprintf strftime strlcpy strsignal symlinkat sync \ sysconf tcgetpgrp tcsetpgrp tempnam timegm times tmpfile tmpnam tmpnam_r \ truncate uname unlinkat unsetenv utimensat utimes waitid waitpid wait3 wait4 \ wcscoll wcsftime wcsxfrm wmemcmp writev _getpty) diff --git a/pyconfig.h.in b/pyconfig.h.in index d80ddc0dc2e..a82c3737c3c 100644 --- a/pyconfig.h.in +++ b/pyconfig.h.in @@ -984,6 +984,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_STROPTS_H +/* Define to 1 if you have the `strsignal' function. */ +#undef HAVE_STRSIGNAL + /* Define to 1 if `pw_gecos' is a member of `struct passwd'. */ #undef HAVE_STRUCT_PASSWD_PW_GECOS