Kaydet (Commit) 9ceaa72e authored tarafından Anthony Baxter's avatar Anthony Baxter

Patch #975056 - fixes for restartable signals on *BSD. In addition,

a few remaining calls to signal() were converted to PyOS_setsig().
üst 7d428788
...@@ -2903,18 +2903,18 @@ posix_openpty(PyObject *self, PyObject *noargs) ...@@ -2903,18 +2903,18 @@ posix_openpty(PyObject *self, PyObject *noargs)
master_fd = open(DEV_PTY_FILE, O_RDWR | O_NOCTTY); /* open master */ master_fd = open(DEV_PTY_FILE, O_RDWR | O_NOCTTY); /* open master */
if (master_fd < 0) if (master_fd < 0)
return posix_error(); return posix_error();
sig_saved = signal(SIGCHLD, SIG_DFL); sig_saved = PyOS_setsig(SIGCHLD, SIG_DFL);
/* change permission of slave */ /* change permission of slave */
if (grantpt(master_fd) < 0) { if (grantpt(master_fd) < 0) {
signal(SIGCHLD, sig_saved); PyOS_setsig(SIGCHLD, sig_saved);
return posix_error(); return posix_error();
} }
/* unlock slave */ /* unlock slave */
if (unlockpt(master_fd) < 0) { if (unlockpt(master_fd) < 0) {
signal(SIGCHLD, sig_saved); PyOS_setsig(SIGCHLD, sig_saved);
return posix_error(); return posix_error();
} }
signal(SIGCHLD, sig_saved); PyOS_setsig(SIGCHLD, sig_saved);
slave_name = ptsname(master_fd); /* get name of slave */ slave_name = ptsname(master_fd); /* get name of slave */
if (slave_name == NULL) if (slave_name == NULL)
return posix_error(); return posix_error();
......
...@@ -136,9 +136,6 @@ signal_handler(int sig_num) ...@@ -136,9 +136,6 @@ signal_handler(int sig_num)
to the Python handler... */ to the Python handler... */
return; return;
} }
#endif
#ifdef HAVE_SIGINTERRUPT
siginterrupt(sig_num, 1);
#endif #endif
PyOS_setsig(sig_num, signal_handler); PyOS_setsig(sig_num, signal_handler);
} }
...@@ -217,9 +214,6 @@ signal_signal(PyObject *self, PyObject *args) ...@@ -217,9 +214,6 @@ signal_signal(PyObject *self, PyObject *args)
} }
else else
func = signal_handler; func = signal_handler;
#ifdef HAVE_SIGINTERRUPT
siginterrupt(sig_num, 1);
#endif
if (PyOS_setsig(sig_num, func) == SIG_ERR) { if (PyOS_setsig(sig_num, func) == SIG_ERR) {
PyErr_SetFromErrno(PyExc_RuntimeError); PyErr_SetFromErrno(PyExc_RuntimeError);
return NULL; return NULL;
......
...@@ -217,7 +217,7 @@ shutdown(how) -- shut down traffic in one or both directions\n\ ...@@ -217,7 +217,7 @@ shutdown(how) -- shut down traffic in one or both directions\n\
/* Generic includes */ /* Generic includes */
#include <sys/types.h> #include <sys/types.h>
#include <signal.h> //#include <signal.h>
/* Generic socket object definitions and includes */ /* Generic socket object definitions and includes */
#define PySocket_BUILDING_SOCKET #define PySocket_BUILDING_SOCKET
......
...@@ -137,7 +137,7 @@ intcatcher(int sig) ...@@ -137,7 +137,7 @@ intcatcher(int sig)
Py_Exit(1); Py_Exit(1);
break; break;
} }
signal(SIGINT, intcatcher); PyOS_setsig(SIGINT, intcatcher);
Py_AddPendingCall(checksignals_witharg, NULL); Py_AddPendingCall(checksignals_witharg, NULL);
} }
...@@ -146,23 +146,14 @@ static void (*old_siginthandler)(int) = SIG_DFL; ...@@ -146,23 +146,14 @@ static void (*old_siginthandler)(int) = SIG_DFL;
void void
PyOS_InitInterrupts(void) PyOS_InitInterrupts(void)
{ {
if ((old_siginthandler = signal(SIGINT, SIG_IGN)) != SIG_IGN) if ((old_siginthandler = PyOS_setsig(SIGINT, SIG_IGN)) != SIG_IGN)
signal(SIGINT, intcatcher); PyOS_setsig(SIGINT, intcatcher);
#ifdef HAVE_SIGINTERRUPT
/* This is for SunOS and other modern BSD derivatives.
It means that system calls (like read()) are not restarted
after an interrupt. This is necessary so interrupting a
read() or readline() call works as expected.
XXX On old BSD (pure 4.2 or older) you may have to do this
differently! */
siginterrupt(SIGINT, 1);
#endif /* HAVE_SIGINTERRUPT */
} }
void void
PyOS_FiniInterrupts(void) PyOS_FiniInterrupts(void)
{ {
signal(SIGINT, old_siginthandler); PyOS_setsig(SIGINT, old_siginthandler);
} }
int int
......
...@@ -1576,13 +1576,13 @@ static void ...@@ -1576,13 +1576,13 @@ static void
initsigs(void) initsigs(void)
{ {
#ifdef SIGPIPE #ifdef SIGPIPE
signal(SIGPIPE, SIG_IGN); PyOS_setsig(SIGPIPE, SIG_IGN);
#endif #endif
#ifdef SIGXFZ #ifdef SIGXFZ
signal(SIGXFZ, SIG_IGN); PyOS_setsig(SIGXFZ, SIG_IGN);
#endif #endif
#ifdef SIGXFSZ #ifdef SIGXFSZ
signal(SIGXFSZ, SIG_IGN); PyOS_setsig(SIGXFSZ, SIG_IGN);
#endif #endif
PyOS_InitInterrupts(); /* May imply initsignal() */ PyOS_InitInterrupts(); /* May imply initsignal() */
} }
...@@ -1646,18 +1646,14 @@ PyOS_getsig(int sig) ...@@ -1646,18 +1646,14 @@ PyOS_getsig(int sig)
{ {
#ifdef HAVE_SIGACTION #ifdef HAVE_SIGACTION
struct sigaction context; struct sigaction context;
/* Initialize context.sa_handler to SIG_ERR which makes about as if (sigaction(sig, NULL, &context) == -1)
* much sense as anything else. It should get overwritten if return SIG_ERR;
* sigaction actually succeeds and otherwise we avoid an
* uninitialized memory read.
*/
context.sa_handler = SIG_ERR;
sigaction(sig, NULL, &context);
return context.sa_handler; return context.sa_handler;
#else #else
PyOS_sighandler_t handler; PyOS_sighandler_t handler;
handler = signal(sig, SIG_IGN); handler = signal(sig, SIG_IGN);
signal(sig, handler); if (handler != SIG_ERR)
signal(sig, handler);
return handler; return handler;
#endif #endif
} }
...@@ -1666,20 +1662,19 @@ PyOS_sighandler_t ...@@ -1666,20 +1662,19 @@ PyOS_sighandler_t
PyOS_setsig(int sig, PyOS_sighandler_t handler) PyOS_setsig(int sig, PyOS_sighandler_t handler)
{ {
#ifdef HAVE_SIGACTION #ifdef HAVE_SIGACTION
struct sigaction context; struct sigaction context, ocontext;
PyOS_sighandler_t oldhandler;
/* Initialize context.sa_handler to SIG_ERR which makes about as
* much sense as anything else. It should get overwritten if
* sigaction actually succeeds and otherwise we avoid an
* uninitialized memory read.
*/
context.sa_handler = SIG_ERR;
sigaction(sig, NULL, &context);
oldhandler = context.sa_handler;
context.sa_handler = handler; context.sa_handler = handler;
sigaction(sig, &context, NULL); sigemptyset(&context.sa_mask);
return oldhandler; context.sa_flags = 0;
if (sigaction(sig, &context, &ocontext) == -1)
return SIG_ERR;
return ocontext.sa_handler;
#else #else
return signal(sig, handler); PyOS_sighandler_t oldhandler;
oldhandler = signal(sig, handler);
#ifdef HAVE_SIGINTERRUPT
siginterrupt(sig, 1);
#endif
return oldhandler;
#endif #endif
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment