[Mono-dev] [RFC] Handle lack of SA_SIGINFO

Andreas Färber andreas.faerber at web.de
Sun Mar 21 20:50:15 EDT 2010


SA_SIGINFO and sigaction are part of the optional POSIX XSI feature.
In mini, there's MONO_ARCH_USE_SIGACTION but it doesn't cover everything
and it isn't available elsewhere.

2010-03-21  Andreas Faerber  <andreas.faerber at web.de>

	* mini-posix.c: Fix the build on platforms without SA_SIGINFO (Haiku).

2010-03-21  Andreas Faerber  <andreas.faerber at web.de>

	* console-unix.c: Fix the build on platforms without sigaction (Haiku).

This commit is licensed under the MIT X11 license.
---
 Hello Zoltan,
 
 I've noticed you made some improvements for the non-sigaction code path in mini.
 There's still some places where SA_SIGINFO is used unguarded, also some outside
 mini. Could you please take a look if in the mini part of my patch we could do
 s/#ifdef SA_SIGINFO/#ifdef MONO_ARCH_USE_SIGACTION/ and drop the original #ifdefs?
 Thanks! I have a follow-on patch to add support for BeOS-style signal handlers.
 
 Regards,
 Andreas
 
 mono/metadata/ChangeLog      |    6 ++++++
 mono/metadata/console-unix.c |   18 ++++++++++++++++++
 mono/mini/ChangeLog          |    6 ++++++
 mono/mini/mini-posix.c       |   15 +++++++++++++--
 4 files changed, 43 insertions(+), 2 deletions(-)

diff --git a/mono/metadata/ChangeLog b/mono/metadata/ChangeLog
index b61f60a..ccb7803 100644
--- a/mono/metadata/ChangeLog
+++ b/mono/metadata/ChangeLog
@@ -1,5 +1,11 @@
 2010-03-21  Andreas Färber  <andreas.faerber at web.de>
 
+	* console-unix.c: Fix the build on platforms without sigaction (Haiku).
+	
+	Code is contributed under MIT/X11 license.
+
+2010-03-21  Andreas Färber  <andreas.faerber at web.de>
+
 	* socket-io.c: Don't depend on AF_SNA, AF_DECnet,
 	SOCK_RDM.
 	
diff --git a/mono/metadata/console-unix.c b/mono/metadata/console-unix.c
index 99e0754..a57042d 100644
--- a/mono/metadata/console-unix.c
+++ b/mono/metadata/console-unix.c
@@ -274,10 +274,19 @@ sigcont_handler (int signo, void *the_siginfo, void *data)
 		write (STDOUT_FILENO, keypad_xmit_str, strlen (keypad_xmit_str));
 
 	// Call previous handler
+#ifdef SA_SIGINFO
+	if (save_sigcont.sa_flags & SA_SIGINFO) {
 	if (save_sigcont.sa_sigaction != NULL &&
 	    save_sigcont.sa_sigaction != (void *)SIG_DFL &&
 	    save_sigcont.sa_sigaction != (void *)SIG_IGN)
 		(*save_sigcont.sa_sigaction) (signo, the_siginfo, data);
+	} else
+#else
+	if (save_sigcont.sa_handler != NULL &&
+	    save_sigcont.sa_handler != (void *)SIG_DFL &&
+	    save_sigcont.sa_handler != (void *)SIG_IGN)
+		(*save_sigcont.sa_handler) (signo);
+#endif
 }
 
 static void
@@ -288,10 +297,19 @@ sigwinch_handler (int signo, void *the_siginfo, void *data)
 		cols_and_lines = dims;
 	
 	// Call previous handler
+#ifdef SA_SIGINFO
+	if (save_sigcont.sa_flags & SA_SIGINFO) {
 	if (save_sigwinch.sa_sigaction != NULL &&
 	    save_sigwinch.sa_sigaction != (void *)SIG_DFL &&
 	    save_sigwinch.sa_sigaction != (void *)SIG_IGN)
 		(*save_sigwinch.sa_sigaction) (signo, the_siginfo, data);
+	} else
+#else
+	if (save_sigwinch.sa_handler != NULL &&
+	    save_sigwinch.sa_handler != (void *)SIG_DFL &&
+	    save_sigwinch.sa_handler != (void *)SIG_IGN)
+		(*save_sigwinch.sa_handler) (signo);
+#endif
 }
 
 void
diff --git a/mono/mini/ChangeLog b/mono/mini/ChangeLog
index 3107a48..e876543 100755
--- a/mono/mini/ChangeLog
+++ b/mono/mini/ChangeLog
@@ -1,5 +1,11 @@
 2010-03-21  Andreas Faerber  <andreas.faerber at web.de>
 
+	* mini-posix.c: Fix the build on platforms without SA_SIGINFO (Haiku).
+	
+	Code is contributed under MIT/X11 license.
+
+2010-03-21  Andreas Faerber  <andreas.faerber at web.de>
+
 	* debugger-agent.c: #include sys/select.h for fd_set.
 	
 	Code is contributed under MIT/X11 license.
diff --git a/mono/mini/mini-posix.c b/mono/mini/mini-posix.c
index 823d93b..f53a850 100644
--- a/mono/mini/mini-posix.c
+++ b/mono/mini/mini-posix.c
@@ -82,13 +82,17 @@ save_old_signal_handler (int signo, struct sigaction *old_action)
 	mono_trace (G_LOG_LEVEL_DEBUG, MONO_TRACE_CONFIG,
 				"Saving old signal handler for signal %d.", signo);
 
+#ifdef SA_SIGINFO
 	if (! (old_action->sa_flags & SA_SIGINFO)) {
+#endif
 		handler_to_save->sa_handler = old_action->sa_handler;
+#ifdef SA_SIGINFO
 	} else {
 #ifdef MONO_ARCH_USE_SIGACTION
 		handler_to_save->sa_sigaction = old_action->sa_sigaction;
 #endif /* MONO_ARCH_USE_SIGACTION */
 	}
+#endif
 	handler_to_save->sa_mask = old_action->sa_mask;
 	handler_to_save->sa_flags = old_action->sa_flags;
 	
@@ -129,13 +133,17 @@ SIG_HANDLER_SIGNATURE (mono_chain_signal)
 	GET_CONTEXT;
 
 	if (saved_handler) {
+#ifdef SA_SIGINFO
 		if (!(saved_handler->sa_flags & SA_SIGINFO)) {
+#endif
 			saved_handler->sa_handler (signal);
+#ifdef SA_SIGINFO
 		} else {
 #ifdef MONO_ARCH_USE_SIGACTION
 			saved_handler->sa_sigaction (signal, info, ctx);
 #endif /* MONO_ARCH_USE_SIGACTION */
 		}
+#endif
 		return TRUE;
 	}
 	return FALSE;
@@ -381,9 +389,12 @@ add_signal_handler (int signo, gpointer handler)
 	g_assert (sigaction (signo, &sa, &previous_sa) != -1);
 
 	/* if there was already a handler in place for this signal, store it */
-	if (! (previous_sa.sa_flags & SA_SIGINFO) &&
+	if (
+#ifdef SA_SIGINFO
+		! (previous_sa.sa_flags & SA_SIGINFO) &&
+#endif
 			(SIG_DFL == previous_sa.sa_handler)) { 
-		/* it there is no sa_sigaction function and the sa_handler is default, we can safely ignore this */
+		/* if there is no sa_sigaction function and the sa_handler is default, we can safely ignore this */
 	} else {
 		if (mono_do_signal_chaining)
 			save_old_signal_handler (signo, &previous_sa);
-- 
1.7.0.14.g7e948



More information about the Mono-devel-list mailing list