diff Python/pythonrun.c @ 14637:37397bd1f8a8 legacy-trunk

Add PyOS_getsig() and PyOS_setsig() -- wrappers around signal() or sigaction() (if HAVE_SIGACTION is defined).
author Guido van Rossum <guido@python.org>
date Sat, 16 Sep 2000 16:32:19 +0000
parents 6f6f965c5e2d
children 992460c668c1 76caf0855d1f
line wrap: on
line diff
--- a/Python/pythonrun.c	Sat Sep 16 16:31:31 2000 +0000
+++ b/Python/pythonrun.c	Sat Sep 16 16:32:19 2000 +0000
@@ -1214,3 +1214,37 @@
 /* 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
+}