Modern operating systems come with systemwide "crash catching"
facilities; for example, the Linux kernel can now pipe core
dumps out to userspace, and programs like "systemd-coredump"
and "abrt" record these.

In this model, it's actively counterproductive for individual
processes to catch SIGSEGV because:

1) Trying to unwind from inside the process after arbitrary
   corruption is destined to fail.
2) It hides the fact that a crash happened at all - my OS test
   framework wants to know if any process crashed, and I don't
   want to guess by running regexps against /var/log/Xorg.0.log
   or whatever.

Signed-off-by: Colin Walters <[email protected]>
---
 configure.ac |   12 ++++++++++++
 os/osinit.c  |    8 ++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

>From aa4a246a2130f7d37547d071e838c38203c52a0d Mon Sep 17 00:00:00 2001
From: Colin Walters <[email protected]>
Date: Fri, 18 Jan 2013 13:24:58 -0500
Subject: [PATCH] os/osinit: Allow builders to --disable-segv-handler

Modern operating systems come with systemwide "crash catching"
facilities; for example, the Linux kernel can now pipe core
dumps out to userspace, and programs like "systemd-coredump"
and "abrt" record these.

In this model, it's actively counterproductive for individual
processes to catch SIGSEGV because:

1) Trying to unwind from inside the process after arbitrary
   corruption is destined to fail.
2) It hides the fact that a crash happened at all - my OS test
   framework wants to know if any process crashed, and I don't
   want to guess by running regexps against /var/log/Xorg.0.log
   or whatever.

Signed-off-by: Colin Walters <[email protected]>
---
 configure.ac |   12 ++++++++++++
 os/osinit.c  |    8 ++++----
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 435a38f..b429b29 100644
--- a/configure.ac
+++ b/configure.ac
@@ -453,6 +453,18 @@ AC_ARG_ENABLE(debug,         AS_HELP_STRING([--enable-debug],
 AC_ARG_ENABLE(use-sigio-by-default, AS_HELP_STRING([--enable-use-sigio-by-default]
   [Enable SIGIO input handlers by default (default: $USE_SIGIO_BY_DEFAULT)]),
                                 [USE_SIGIO_BY_DEFAULT=$enableval], [])
+AC_ARG_ENABLE(segv-handler, AS_HELP_STRING([--enable-segv-handler]
+  [Catch SIGSEGV and log a backtrace (default: auto)]),
+                                [SEGV_HANDLER=$enableval], [SEGV_HANDLER=auto])
+AS_IF([test x$SEGV_HANDLER = xauto], [
+case $host_os in
+	mingw*) SEGV_HANDLER=no;;
+	*) SEGV_HANDLER=yes;;
+esac
+])
+AS_IF([test x$SEGV_HANDLER = xyes], [
+  AC_DEFINE(ENABLE_SEGV_HANDLER, 1, [Define if X server should catch SIGSEGV])
+])
 AC_ARG_WITH(int10,           AS_HELP_STRING([--with-int10=BACKEND], [int10 backend: vm86, x86emu or stub]),
 				[INT10="$withval"],
 				[INT10="$DEFAULT_INT10"])
diff --git a/os/osinit.c b/os/osinit.c
index 6c66f9c..2bafb08 100644
--- a/os/osinit.c
+++ b/os/osinit.c
@@ -102,7 +102,7 @@ OsRegisterSigWrapper(OsSigWrapperPtr newSigWrapper)
  * OsSigHandler --
  *    Catch unexpected signals and exit or continue cleanly.
  */
-#if !defined(WIN32) || defined(__CYGWIN__)
+#ifdef ENABLE_SEGV_HANDLER
 static void
 #ifdef SA_SIGINFO
 OsSigHandler(int signo, siginfo_t * sip, void *unused)
@@ -147,7 +147,7 @@ OsSigHandler(int signo)
     FatalError("Caught signal %d (%s). Server aborting\n",
                signo, strsignal(signo));
 }
-#endif /* !WIN32 || __CYGWIN__ */
+#endif /* ENABLE_SEGV_HANDLER */
 
 void
 OsInit(void)
@@ -157,7 +157,7 @@ OsInit(void)
     char fname[PATH_MAX];
 
     if (!been_here) {
-#if !defined(WIN32) || defined(__CYGWIN__)
+#ifdef ENABLE_SEGV_HANDLER
         struct sigaction act, oact;
         int i;
 
@@ -184,7 +184,6 @@ OsInit(void)
                        siglist[i], strerror(errno));
             }
         }
-#endif /* !WIN32 || __CYGWIN__ */
 
 #ifdef HAVE_BACKTRACE
         /*
@@ -197,6 +196,7 @@ OsInit(void)
             backtrace(&array, 1);
         } while (0);
 #endif
+#endif /* ENABLE_SEGV_HANDLER */
 
 #ifdef RTLD_DI_SETSIGNAL
         /* Tell runtime linker to send a signal we can catch instead of SIGKILL
-- 
1.7.1

_______________________________________________
[email protected]: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel

Reply via email to