Skip to content

bpo-34412: strsignal(3) does not exist on HP-UX #8786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 23, 2018

Conversation

michael-o
Copy link
Contributor

@michael-o michael-o commented Aug 16, 2018

Introduce a configure check for strsignal(3) and define HAVE_STRSIGNAL for
signalmodule.c. This change applies for Windows and HP-UX.

https://bugs.python.org/issue34412

@@ -530,7 +530,7 @@ signal_strsignal_impl(PyObject *module, int signalnum)
return NULL;
}

#ifdef MS_WINDOWS
#ifndef HAVE_STRSIGNAL
/* Custom redefinition of POSIX signals allowed on Windows */
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is now somewhat inaccurate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shall I drop it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd keep it and add HP-UX instead.

Copy link
Member

@berkerpeksag berkerpeksag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Please add a NEWS entry. See https://devguide.python.org/committing/#what-s-new-and-news-entries for details.

  2. Please regenerate configure.

  3. Does the test_strsignal test in Lib/test/test_signal.py passed on HP-UX when you applied this patch?

configure.ac Outdated
@@ -5541,6 +5541,15 @@ AC_MSG_RESULT(python)
AC_DEFINE(PY_SSL_DEFAULT_CIPHERS, 1)
])

# Windows and HP-UX do not support strsignal(3)
AC_MSG_CHECKING(for strsignal)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <string.h>]], [[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have considered this, but it is nowhere documented that it will include string.h. I went for the safe bet.

Copy link
Member

@berkerpeksag berkerpeksag Aug 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Many of the functions listed there require a header file to be included and none of them are documented in the autoconf documentation. For example, alarm() requires unistd.h and Modules/signalmodule.c already uses it:

https://github.com/python/cpython/blob/7980d771c76d55aca55e1e619bada7c4707305b2/Modules/signalmodule.c#L344

Does that check works on HP-UX? If it works, I think we can try adding signalstr to that list.

Currently, configure.ac is a mess, so it would nice if we can keep it shorter :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check that too.

Copy link
Contributor Author

@michael-o michael-o Aug 16, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just check on FreeBSD and HP-UX. It does its job in both config.log and config.status for both platforms. Will change accordingly.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@michael-o
Copy link
Contributor Author

michael-o commented Aug 16, 2018

@berkerpeksag

  1. Will do
  2. Will do, though I do not understand why you are committing a generated file.
  3. Yes, this test passes.

Output:

$ make test TESTOPTS="-v test_signal"
 CC='/opt/aCC/bin/cc' LDSHARED='/opt/aCC/bin/cc -b -L/usr/local/lib/hpux32 -L/usr/local/lib/hpux32' OPT='-O'    _TCLTK_INCLUDES='' _TCLTK_LIBS=''       ./python -E ./setup.py  build
running build
running build_ext
...
Python build finished successfully!
The necessary bits to build these optional modules were not found:
_gdbm                 _lzma                 _tkinter
_uuid                 ossaudiodev           spwd
To find the necessary bits, look in setup.py in detect_modules() for the module's name.


The following modules found by detect_modules() in setup.py, have been
built by the Makefile instead, as configured by the Setup files:
_abc                  atexit                pwd
time


Failed to build these modules:
_curses_panel


Following modules built successfully but were removed because they could not be imported:
_curses

running build_scripts
copying and adjusting /var/osipovmi/cpython/Tools/scripts/pydoc3 -> build/scripts-3.8
copying and adjusting /var/osipovmi/cpython/Tools/scripts/idle3 -> build/scripts-3.8
copying and adjusting /var/osipovmi/cpython/Tools/scripts/2to3 -> build/scripts-3.8
changing mode of build/scripts-3.8/pydoc3 from 640 to 755
changing mode of build/scripts-3.8/idle3 from 640 to 755
changing mode of build/scripts-3.8/2to3 from 640 to 755
renaming build/scripts-3.8/pydoc3 to build/scripts-3.8/pydoc3.8
renaming build/scripts-3.8/idle3 to build/scripts-3.8/idle3.8
renaming build/scripts-3.8/2to3 to build/scripts-3.8/2to3-3.8
         ./python  ./Tools/scripts/run_tests.py -v test_signal
/var/osipovmi/cpython/python -u -W default -bb -E -m test -r -w -j 0 -u all,-largefile,-audio,-gui -v test_signal
== CPython 3.8.0a0 (heads/[bpo-34412](https://www.bugs.python.org/issue34412)-dirty:7980d771c7, Aug 16 2018, 17:43:10) [C]
== HP-UX-B.11.31-ia64-32bit-ELF big-endian
== cwd: /var/osipovmi/cpython/build/test_python_6640
== CPU count: 4
== encodings: locale=utf8, FS=utf-8
Using random seed 9950569
Run tests in parallel using 6 child processes
0:00:25 [1/1/1] test_signal failed
test_enums (test.test_signal.GenericTests) ... ok
test_itimer_exc (test.test_signal.ItimerTest) ... ok
test_itimer_prof (test.test_signal.ItimerTest) ... ok
test_itimer_real (test.test_signal.ItimerTest) ... ok
test_itimer_virtual (test.test_signal.ItimerTest) ... ok
test_setitimer_tiny (test.test_signal.ItimerTest) ... ok
test_pthread_kill (test.test_signal.PendingSignalsTests) ... ok
test_pthread_kill_main_thread (test.test_signal.PendingSignalsTests) ... ok
test_pthread_sigmask (test.test_signal.PendingSignalsTests) ... ok
test_pthread_sigmask_arguments (test.test_signal.PendingSignalsTests) ... ok
test_pthread_sigmask_valid_signals (test.test_signal.PendingSignalsTests) ... ok
test_sigpending (test.test_signal.PendingSignalsTests) ... ok
test_sigpending_empty (test.test_signal.PendingSignalsTests) ... ok
test_sigtimedwait (test.test_signal.PendingSignalsTests) ... ok
test_sigtimedwait_negative_timeout (test.test_signal.PendingSignalsTests) ... ok
test_sigtimedwait_poll (test.test_signal.PendingSignalsTests) ... ok
test_sigtimedwait_timeout (test.test_signal.PendingSignalsTests) ... ok
test_sigwait (test.test_signal.PendingSignalsTests) ... ok
test_sigwait_thread (test.test_signal.PendingSignalsTests) ... ok
test_sigwaitinfo (test.test_signal.PendingSignalsTests) ... ok
test_getsignal (test.test_signal.PosixTests) ... ok
test_interprocess_signal (test.test_signal.PosixTests) ... ok
...

@michael-o michael-o force-pushed the bpo-34412 branch 2 times, most recently from 26627f0 to 20df665 Compare August 16, 2018 17:08
@michael-o
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@berkerpeksag: please review the changes made to this pull request.

tiran
tiran previously requested changes Aug 16, 2018
Copy link
Member

@tiran tiran left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have a typo in your test:

======================================================================
ERROR: test_strsignal (test.test_signal.PosixTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/python/cpython/Lib/test/test_signal.py", line 66, in test_strsignal
    self.assertIn("Hangup", signal.strsignal(singal.SIGHUP))
NameError: name 'singal' is not defined

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@@ -60,6 +60,10 @@ def test_getsignal(self):
def test_strsignal(self):
self.assertIn("Interrupt", signal.strsignal(signal.SIGINT))
self.assertIn("Terminated", signal.strsignal(signal.SIGTERM))
if sys.platform.startswith("hp-ux"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think SIGHUP is a pretty common signal, so it can be added to the list in Modules/signalmodule.c:

#ifndef MS_WINDOWS
         /* TODO: Add a comment to explain why we need this on HP-UX. */
         case SIGHUP:
             res = "Hangup";
             break;
#endif

Then we can test self.assertIn("Hangup", signal.strsignal(singal.SIGHUP)) unconditionally.

@@ -0,0 +1 @@
Add HAVE_STRSIGNAL to avoid build failure on HP-UX with strsignal(3)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we say something like "make :func:`signal.strsignal` work on HP-UX"?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add "Patch by Your Name.".

@michael-o michael-o force-pushed the bpo-34412 branch 2 times, most recently from 391f445 to bdc1a80 Compare August 17, 2018 07:38
@michael-o
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@tiran, @berkerpeksag: please review the changes made to this pull request.

@michael-o
Copy link
Contributor Author

There are test failures on Windows because SIGHUP needs to be declared at several spots. I think this is out of scope for this PR, I will drop that spot.

@berkerpeksag
Copy link
Member

berkerpeksag commented Aug 17, 2018

There are test failures on Windows because SIGHUP needs to be declared at several spots.

Did you cover it with #ifndef MS_WINDOWS ... #endif? I think if you add that #ifndef, it should cover the Windows case since it would only added to the list if HAVE_STRSIGNAL and MS_WINDOWS aren't defined.

@michael-o
Copy link
Contributor Author

@berkerpeksag

So you are looking for this:

diff --git a/Modules/signalmodule.c b/Modules/signalmodule.c
index 056645c124..84095a24c0 100644
--- a/Modules/signalmodule.c
+++ b/Modules/signalmodule.c
@@ -533,6 +533,11 @@ signal_strsignal_impl(PyObject *module, int signalnum)
 #ifndef HAVE_STRSIGNAL
     switch (signalnum) {
         /* Though being a UNIX, HP-UX does not provide strsignal(3) */
+#ifndef MS_WINDOWS
+        case SIGHUP:
+            res = "Hangup";
+            break;
+#endif
         case SIGINT:
             res = "Interrupt";
             break;

This isn't there, I can add this. Shall I?

@michael-o
Copy link
Contributor Author

@berkerpeksag Change pushed.

@michael-o
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@tiran, @berkerpeksag: please review the changes made to this pull request.

@@ -0,0 +1 @@
make :func:`signal.strsignal` work on HP-UX. Patch by Michael Osipov.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: make -> Make

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do.

switch (signalnum) {
/* Though being a UNIX, HP-UX does not provide strsignal(3) */
#ifndef MS_WINDOWS
case SIGHUP:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This list was just a redefinition of POSIX signals supported by Windows. I think we need to check whether there is more than one signal to add to this list for other Unix systems.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I can go through signal.h on HP-UX and provide those, but this is out of scope of this PR because the motivation for this one is just to make this module properly compile on HP-UX. Is that OK for you?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@berkerpeksag I went through signal.h. There is a bus load of signals, some wrapped with ifdefs. I don't think that HP-UX is worth the effort for now just to have a nice string. If so, this has to be a separate PR.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We definitely can't maintain a full list of signals for every platform we support, so I agree with you. I was wondering whether there are other signals to include to make strsignal() useful for most common cases.

I just checked http://nixdoc.net/man-pages/hp-ux/man5/signal.5.html and I think the most common unlisted signals are SIGALRM, SIGPIPE, SIGQUIT, and SIGCHLD.

Since SIGINT and SIGTERM is already in the list, I'd expect SIGQUIT to be there as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, I added all those. checked FreeBSD and glibc implementation + manpages and took the strings (_sys_siglist[]) out of them. They are identical. I am sure whether the tests should be extented because the Open Group says about strsignal(3) that the return value is implementation-defined.

@berkerpeksag WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks! No need to update the tests.

I will take another look at this and merge tonight.

@bedevere-bot
Copy link

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@michael-o
Copy link
Contributor Author

I have made the requested changes; please review again

@bedevere-bot
Copy link

Thanks for making the requested changes!

@tiran, @berkerpeksag: please review the changes made to this pull request.

@michael-o
Copy link
Contributor Author

@berkerpeksag are we good to merge?

@berkerpeksag
Copy link
Member

@michael-o could you rerun autoreconf and commit the changes in pyconfig.h.in? It should look like:

diff --git a/pyconfig.h.in b/pyconfig.h.in
index d80ddc0..a82c373 100644
--- a/pyconfig.h.in
+++ b/pyconfig.h.in
@@ -984,6 +984,9 @@
 /* Define to 1 if you have the <stropts.h> 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

@berkerpeksag berkerpeksag dismissed tiran’s stale review August 22, 2018 16:59

Addressed in the latest review. Thanks!

Introduce a configure check for strsignal(3) which defines HAVE_STRSIGNAL for
signalmodule.c. This change applies for Windows and HP-UX.

Patch by Michael Osipov.
@michael-o
Copy link
Contributor Author

I have made the requested changes; please review again

@berkerpeksag Done. Should be fine now. Have a look please.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@berkerpeksag: please review the changes made to this pull request.

@berkerpeksag
Copy link
Member

Thanks!

@michael-o michael-o deleted the bpo-34412 branch August 23, 2018 14:35
@michael-o
Copy link
Contributor Author

@berkerpeksag Thanks for merging. Would you mind to take a look at my other HP-UX related PRs? I'd like to continue contributing.

@berkerpeksag
Copy link
Member

@michael-o I'm looking at #8846 and #8828, but the PRs about setup.py are out of my knowledge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants