From 88d51db558a32c930d18d7e60e403acafa5fdeb9 Mon Sep 17 00:00:00 2001 From: Yiyang Fei Date: Wed, 27 Apr 2016 07:42:14 -0700 Subject: [PATCH] Suppress Windows popups when app crashes with exception. See https://blogs.msdn.microsoft.com/oldnewthing/20040727-00/?p=38323/ and http://stackoverflow.com/questions/396369/how-do-i-disable-the-debug-close-application-dialog-on-windows-vista --- test/test-segfault.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/test/test-segfault.c b/test/test-segfault.c index c062ce1..ee88f0b 100644 --- a/test/test-segfault.c +++ b/test/test-segfault.c @@ -13,11 +13,32 @@ #include #endif +#ifdef DBUS_WIN +#include + +/* Explicit Windows exception handlers needed to supress OS popups */ +int +exception_handler(LPEXCEPTION_POINTERS p) +{ + printf("Exception detected during the unit tests!\n"); + exit(1); +} +#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); + SetUnhandledExceptionFilter((LPTOP_LEVEL_EXCEPTION_FILTER)&exception_handler); +#endif + #if HAVE_SETRLIMIT /* No core dumps please, we know we crashed. */ struct rlimit r = { 0, }; -- 2.5.4 (Apple Git-61)