]> git.ipfire.org Git - thirdparty/dbus.git/commitdiff
Suppress Windows popups and jit debugger when app crashes with exception.
authorRalf Habacker <ralf.habacker@freenet.de>
Mon, 9 May 2016 15:31:17 +0000 (17:31 +0200)
committerRalf Habacker <ralf.habacker@freenet.de>
Mon, 9 May 2016 19:49:22 +0000 (21:49 +0200)
Based on a patch from Yiyang Fei.

Bug: https://bugs.freedesktop.org/show_bug.cgi?id=95155
Reviewed-by: Simon McVittie <simon.mcvittie@collabora.co.uk>
test/test-segfault.c

index c062ce1cdb3a4cc3da36bbd4aaca1e09fc6e335d..7e2e82a154f8d335f5039f4d4abdd19060d5997b 100644 (file)
 #include <sys/prctl.h>
 #endif
 
+#ifdef DBUS_WIN
+#include <windows.h>
+
+int
+exception_handler(LPEXCEPTION_POINTERS p);
+
+/* Explicit Windows exception handlers needed to supress OS popups */
+int
+exception_handler(LPEXCEPTION_POINTERS p)
+{
+  fprintf(stderr, "test-segfault: raised fatal exception as intended\n");
+  ExitProcess(0xc0000005);
+}
+#endif
+
 int
 main (int argc, char **argv)
 {
   char *p;  
 
+#ifdef DBUS_WIN
+  /* Disable Windows popup dialog when an app crashes so that app quits
+   * immediately with error code instead of waiting for user to dismiss
+   * the dialog.  */
+  DWORD dwMode = SetErrorMode(SEM_NOGPFAULTERRORBOX);
+  SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX);
+  /* Disable "just in time" debugger */
+  SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)&exception_handler);
+#endif
+
 #if HAVE_SETRLIMIT
   /* No core dumps please, we know we crashed. */
   struct rlimit r = { 0, };