summaryrefslogtreecommitdiffstats
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorAnthony Baxter <anthonybaxter@gmail.com>2004-10-13 14:48:50 (GMT)
committerAnthony Baxter <anthonybaxter@gmail.com>2004-10-13 14:48:50 (GMT)
commit9ceaa72ebe96cb5423aa3fb2adede3fcd1c7b6b0 (patch)
tree89e6ac6b3f1ec58c13296765e2301b854a6150d6 /Python/pythonrun.c
parent7d428788e156200df2f8e6421cad9fce083fd96b (diff)
downloadcpython-9ceaa72ebe96cb5423aa3fb2adede3fcd1c7b6b0.zip
cpython-9ceaa72ebe96cb5423aa3fb2adede3fcd1c7b6b0.tar.gz
cpython-9ceaa72ebe96cb5423aa3fb2adede3fcd1c7b6b0.tar.bz2
Patch #975056 - fixes for restartable signals on *BSD. In addition,
a few remaining calls to signal() were converted to PyOS_setsig().
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c43
1 files changed, 19 insertions, 24 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 92e051b..e9f4765 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1576,13 +1576,13 @@ static void
initsigs(void)
{
#ifdef SIGPIPE
- signal(SIGPIPE, SIG_IGN);
+ PyOS_setsig(SIGPIPE, SIG_IGN);
#endif
#ifdef SIGXFZ
- signal(SIGXFZ, SIG_IGN);
+ PyOS_setsig(SIGXFZ, SIG_IGN);
#endif
#ifdef SIGXFSZ
- signal(SIGXFSZ, SIG_IGN);
+ PyOS_setsig(SIGXFSZ, SIG_IGN);
#endif
PyOS_InitInterrupts(); /* May imply initsignal() */
}
@@ -1646,18 +1646,14 @@ PyOS_getsig(int sig)
{
#ifdef HAVE_SIGACTION
struct sigaction context;
- /* 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);
+ if (sigaction(sig, NULL, &context) == -1)
+ return SIG_ERR;
return context.sa_handler;
#else
PyOS_sighandler_t handler;
handler = signal(sig, SIG_IGN);
- signal(sig, handler);
+ if (handler != SIG_ERR)
+ signal(sig, handler);
return handler;
#endif
}
@@ -1666,20 +1662,19 @@ PyOS_sighandler_t
PyOS_setsig(int sig, PyOS_sighandler_t handler)
{
#ifdef HAVE_SIGACTION
- struct sigaction context;
- 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;
+ struct sigaction context, ocontext;
context.sa_handler = handler;
- sigaction(sig, &context, NULL);
- return oldhandler;
+ sigemptyset(&context.sa_mask);
+ context.sa_flags = 0;
+ if (sigaction(sig, &context, &ocontext) == -1)
+ return SIG_ERR;
+ return ocontext.sa_handler;
#else
- return signal(sig, handler);
+ PyOS_sighandler_t oldhandler;
+ oldhandler = signal(sig, handler);
+#ifdef HAVE_SIGINTERRUPT
+ siginterrupt(sig, 1);
+#endif
+ return oldhandler;
#endif
}