summaryrefslogtreecommitdiff
path: root/Python/pythonrun.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-09-16 16:32:19 +0000
committerGuido van Rossum <guido@python.org>2000-09-16 16:32:19 +0000
commit81ab05f21313b534aedaac8249b83c934bded24c (patch)
tree61aba27b0fb02809c62b16b72eecf066ec285d61 /Python/pythonrun.c
parentabd9e63f2e57ba354ec2b0e23544e0ae73e5ceaf (diff)
downloadcpython-81ab05f21313b534aedaac8249b83c934bded24c.tar.gz
Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or
sigaction() (if HAVE_SIGACTION is defined).
Diffstat (limited to 'Python/pythonrun.c')
-rw-r--r--Python/pythonrun.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
index 924ebf3357..e29e719d10 100644
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -1214,3 +1214,37 @@ PyOS_CheckStack(void)
/* Alternate implementations can be added here... */
#endif /* USE_STACKCHECK */
+
+
+/* Wrappers around sigaction() or signal(). */
+
+PyOS_sighandler_t
+PyOS_getsig(int sig)
+{
+#ifdef HAVE_SIGACTION
+ struct sigaction context;
+ sigaction(sig, NULL, &context);
+ return context.sa_handler;
+#else
+ PyOS_sighandler_t handler;
+ handler = signal(sig, SIG_IGN);
+ signal(sig, handler);
+ return handler;
+#endif
+}
+
+PyOS_sighandler_t
+PyOS_setsig(int sig, PyOS_sighandler_t handler)
+{
+#ifdef HAVE_SIGACTION
+ struct sigaction context;
+ PyOS_sighandler_t oldhandler;
+ sigaction(sig, NULL, &context);
+ oldhandler = context.sa_handler;
+ context.sa_handler = handler;
+ sigaction(sig, &context, NULL);
+ return oldhandler;
+#else
+ return signal(sig, handler);
+#endif
+}