[Python-checkins] r86215 - in python/branches/release31-maint: Misc/ACKS Misc/NEWS Modules/signalmodule.c

antoine.pitrou python-checkins at python.org
Fri Nov 5 20:54:58 CET 2010


Author: antoine.pitrou
Date: Fri Nov  5 20:54:58 2010
New Revision: 86215

Log:
Merged revisions 86214 via svnmerge from 
svn+ssh://pythondev@svn.python.org/python/branches/py3k

........
  r86214 | antoine.pitrou | 2010-11-05 20:47:27 +0100 (ven., 05 nov. 2010) | 4 lines
  
  Issue #10311: The signal module now restores errno before returning from
  its low-level signal handler.  Patch by Hallvard B Furuseth.
........


Modified:
   python/branches/release31-maint/   (props changed)
   python/branches/release31-maint/Misc/ACKS
   python/branches/release31-maint/Misc/NEWS
   python/branches/release31-maint/Modules/signalmodule.c

Modified: python/branches/release31-maint/Misc/ACKS
==============================================================================
--- python/branches/release31-maint/Misc/ACKS	(original)
+++ python/branches/release31-maint/Misc/ACKS	Fri Nov  5 20:54:58 2010
@@ -263,6 +263,7 @@
 Geoff Furnish
 Ulisses Furquim
 Hagen Fürstenau
+Hallvard B Furuseth
 Achim Gaedke
 Martin von Gagern
 Lele Gaifax

Modified: python/branches/release31-maint/Misc/NEWS
==============================================================================
--- python/branches/release31-maint/Misc/NEWS	(original)
+++ python/branches/release31-maint/Misc/NEWS	Fri Nov  5 20:54:58 2010
@@ -143,6 +143,9 @@
 Library
 -------
 
+- Issue #10311: The signal module now restores errno before returning from
+  its low-level signal handler.  Patch by Hallvard B Furuseth.
+
 - The keyword only restriction for the places argument in
   unittest.TestCase.assert[Not]AlmostEqual methods has been removed.
 

Modified: python/branches/release31-maint/Modules/signalmodule.c
==============================================================================
--- python/branches/release31-maint/Modules/signalmodule.c	(original)
+++ python/branches/release31-maint/Modules/signalmodule.c	Fri Nov  5 20:54:58 2010
@@ -166,16 +166,20 @@
 static void
 signal_handler(int sig_num)
 {
-#ifdef WITH_THREAD
-#ifdef WITH_PTH
+    int save_errno = errno;
+
+#if defined(WITH_THREAD) && defined(WITH_PTH)
     if (PyThread_get_thread_ident() != main_thread) {
         pth_raise(*(pth_t *) main_thread, sig_num);
-        return;
     }
+    else
 #endif
+    {
+#ifdef WITH_THREAD
     /* See NOTES section above */
-    if (getpid() == main_pid) {
+    if (getpid() == main_pid)
 #endif
+    {
         Handlers[sig_num].tripped = 1;
         /* Set is_tripped after setting .tripped, as it gets
            cleared in PyErr_CheckSignals() before .tripped. */
@@ -183,24 +187,26 @@
         Py_AddPendingCall(checksignals_witharg, NULL);
         if (wakeup_fd != -1)
             write(wakeup_fd, "\0", 1);
-#ifdef WITH_THREAD
     }
-#endif
+
+#ifndef HAVE_SIGACTION
 #ifdef SIGCHLD
-    if (sig_num == SIGCHLD) {
-        /* To avoid infinite recursion, this signal remains
-           reset until explicit re-instated.
-           Don't clear the 'func' field as it is our pointer
-           to the Python handler... */
-        return;
-    }
+    /* To avoid infinite recursion, this signal remains
+       reset until explicit re-instated.
+       Don't clear the 'func' field as it is our pointer
+       to the Python handler... */
+    if (sig_num != SIGCHLD)
 #endif
-#ifndef HAVE_SIGACTION
     /* If the handler was not set up with sigaction, reinstall it.  See
      * Python/pythonrun.c for the implementation of PyOS_setsig which
      * makes this true.  See also issue8354. */
     PyOS_setsig(sig_num, signal_handler);
 #endif
+    }
+
+    /* Issue #10311: asynchronously executing signal handlers should not
+       mutate errno under the feet of unsuspecting C code. */
+    errno = save_errno;
 }
 
 


More information about the Python-checkins mailing list