diff --git a/src/backend/main/main.c b/src/backend/main/main.c index a9edbfd..d55022c 100644 --- a/src/backend/main/main.c +++ b/src/backend/main/main.c @@ -61,14 +61,6 @@ main(int argc, char *argv[]) { bool do_check_root = true; - /* - * If supported on the current platform, set up a handler to be called if - * the backend/postmaster crashes with a fatal signal or exception. - */ -#if defined(WIN32) && defined(HAVE_MINIDUMP_TYPE) - pgwin32_install_crashdump_handler(); -#endif - progname = get_progname(argv[0]); /* @@ -231,6 +223,17 @@ startup_hacks(const char *progname) * Windows-specific execution environment hacking. */ #ifdef WIN32 + /* In case of general protection fault, don't show GUI popup box */ + SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); + + /* + * If supported on the current platform, set up a handler to be called if + * the backend/postmaster crashes with a fatal signal or exception. + */ +#ifdef HAVE_MINIDUMP_TYPE + pgwin32_install_crashdump_handler(); +#endif + { WSADATA wsaData; int err; @@ -248,9 +251,6 @@ startup_hacks(const char *progname) exit(1); } - /* In case of general protection fault, don't show GUI popup box */ - SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX); - #if defined(_M_AMD64) && _MSC_VER == 1800 /*---------- diff --git a/src/backend/postmaster/postmaster.c b/src/backend/postmaster/postmaster.c index a5446d5..79768e1 100644 --- a/src/backend/postmaster/postmaster.c +++ b/src/backend/postmaster/postmaster.c @@ -4609,6 +4609,7 @@ internal_forkexec(int argc, char *argv[], Port *port) SECURITY_ATTRIBUTES sa; char paramHandleStr[32]; win32_deadchild_waitinfo *childinfo; + UINT errorMode; /* Make sure caller set up argv properly */ Assert(argc >= 3); @@ -4676,14 +4677,20 @@ retry: /* * Create the subprocess in a suspended state. This will be resumed later, * once we have written out the parameter file. + * + * Start the subprocess with the default error mode, so that a crash before + * main() generates a crash dump. */ + errorMode = SetErrorMode(0); if (!CreateProcess(NULL, cmdLine, NULL, NULL, TRUE, CREATE_SUSPENDED, NULL, NULL, &si, &pi)) { elog(LOG, "CreateProcess call failed: %m (error code %lu)", GetLastError()); + SetErrorMode(errorMode); return -1; } + SetErrorMode(errorMode); if (!save_backend_variables(param, port, pi.hProcess, pi.dwProcessId)) {