| 872 | }; |
| 873 | |
| 874 | bool AppInitBasicSetup() |
| 875 | { |
| 876 | // ********************************************************* Step 1: setup |
| 877 | #ifdef _MSC_VER |
| 878 | // Turn off Microsoft heap dump noise |
| 879 | _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); |
| 880 | _CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, nullptr, OPEN_EXISTING, 0, 0)); |
| 881 | // Disable confusing "helpful" text message on abort, Ctrl-C |
| 882 | _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); |
| 883 | #endif |
| 884 | #ifdef WIN32 |
| 885 | // Enable Data Execution Prevention (DEP) |
| 886 | // Minimum supported OS versions: WinXP SP3, WinVista >= SP1, Win Server 2008 |
| 887 | // A failure is non-critical and needs no further attention! |
| 888 | #ifndef PROCESS_DEP_ENABLE |
| 889 | // We define this here, because GCCs winbase.h limits this to _WIN32_WINNT >= 0x0601 (Windows 7), |
| 890 | // which is not correct. Can be removed, when GCCs winbase.h is fixed! |
| 891 | #define PROCESS_DEP_ENABLE 0x00000001 |
| 892 | #endif |
| 893 | typedef BOOL (WINAPI *PSETPROCDEPPOL)(DWORD); |
| 894 | PSETPROCDEPPOL setProcDEPPol = (PSETPROCDEPPOL)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "SetProcessDEPPolicy"); |
| 895 | if (setProcDEPPol != nullptr) setProcDEPPol(PROCESS_DEP_ENABLE); |
| 896 | #endif |
| 897 | |
| 898 | if (!SetupNetworking()) |
| 899 | return InitError("Initializing networking failed"); |
| 900 | |
| 901 | #ifndef WIN32 |
| 902 | if (!gArgs.GetBoolArg("-sysperms", false)) { |
| 903 | umask(077); |
| 904 | } |
| 905 | |
| 906 | // Clean shutdown on SIGTERM |
| 907 | registerSignalHandler(SIGTERM, HandleSIGTERM); |
| 908 | registerSignalHandler(SIGINT, HandleSIGTERM); |
| 909 | |
| 910 | // Reopen debug.log on SIGHUP |
| 911 | registerSignalHandler(SIGHUP, HandleSIGHUP); |
| 912 | |
| 913 | // Ignore SIGPIPE, otherwise it will bring the daemon down if the client closes unexpectedly |
| 914 | signal(SIGPIPE, SIG_IGN); |
| 915 | #else |
| 916 | SetConsoleCtrlHandler(consoleCtrlHandler, true); |
| 917 | #endif |
| 918 | |
| 919 | std::set_new_handler(new_handler_terminate); |
| 920 | |
| 921 | return true; |
| 922 | } |
| 923 | |
| 924 | bool AppInitParameterInteraction() |
| 925 | { |
no test coverage detected