Initialize lux. * @pre Parameters should be parsed and config file should be read. */
| 751 | * @pre Parameters should be parsed and config file should be read. |
| 752 | */ |
| 753 | bool AppInit2() |
| 754 | { |
| 755 | // ********************************************************* Step 1: setup |
| 756 | #ifdef WIN32 |
| 757 | #ifdef _MSC_VER |
| 758 | // Turn off Microsoft heap dump noise |
| 759 | _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE); |
| 760 | _CrtSetReportFile(_CRT_WARN, CreateFileA("NUL", GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, 0)); |
| 761 | #endif |
| 762 | #if _MSC_VER >= 1400 |
| 763 | // Disable confusing "helpful" text message on abort, Ctrl-C |
| 764 | _set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT); |
| 765 | #endif |
| 766 | // Enable Data Execution Prevention (DEP) |
| 767 | // Minimum supported OS versions: WinXP SP3, WinVista >= SP1, Win Server 2008 |
| 768 | // A failure is non-critical and needs no further attention! |
| 769 | #ifndef PROCESS_DEP_ENABLE |
| 770 | // We define this here, because GCCs winbase.h limits this to _WIN32_WINNT >= 0x0601 (Windows 7), |
| 771 | // which is not correct. Can be removed, when GCCs winbase.h is fixed! |
| 772 | #define PROCESS_DEP_ENABLE 0x00000001 |
| 773 | #endif |
| 774 | typedef BOOL(WINAPI * PSETPROCDEPPOL)(DWORD); |
| 775 | PSETPROCDEPPOL setProcDEPPol = (PSETPROCDEPPOL)GetProcAddress(GetModuleHandleA("Kernel32.dll"), "SetProcessDEPPolicy"); |
| 776 | if (setProcDEPPol != NULL) setProcDEPPol(PROCESS_DEP_ENABLE); |
| 777 | |
| 778 | // Initialize Windows Sockets |
| 779 | WSADATA wsadata; |
| 780 | int ret = WSAStartup(MAKEWORD(2, 2), &wsadata); |
| 781 | if (ret != NO_ERROR || LOBYTE(wsadata.wVersion) != 2 || HIBYTE(wsadata.wVersion) != 2) { |
| 782 | return InitError(strprintf("Error: Winsock library failed to start (WSAStartup returned error %d)", ret)); |
| 783 | } |
| 784 | |
| 785 | SetConsoleCtrlHandler(consoleCtrlHandler, true); |
| 786 | |
| 787 | #else /* WIN32 */ |
| 788 | |
| 789 | if (GetBoolArg("-sysperms", false)) { |
| 790 | #ifdef ENABLE_WALLET |
| 791 | if (!GetBoolArg("-disablewallet", false)) |
| 792 | return InitError("Error: -sysperms is not allowed in combination with enabled wallet functionality"); |
| 793 | #endif |
| 794 | } else { |
| 795 | umask(077); |
| 796 | } |
| 797 | |
| 798 | //TODO: registerSignalHandler |
| 799 | // Clean shutdown on SIGTERM |
| 800 | struct sigaction sa; |
| 801 | sa.sa_handler = HandleSIGTERM; |
| 802 | sigemptyset(&sa.sa_mask); |
| 803 | sa.sa_flags = 0; |
| 804 | sigaction(SIGTERM, &sa, NULL); |
| 805 | sigaction(SIGINT, &sa, NULL); |
| 806 | |
| 807 | // Reopen debug.log on SIGHUP |
| 808 | struct sigaction sa_hup; |
| 809 | sa_hup.sa_handler = HandleSIGHUP; |
| 810 | sigemptyset(&sa_hup.sa_mask); |
no test coverage detected