// // daemon_init // void daemon_init(void) { int pid; FILE *fpid; string pidfile; Printf(PRINT_HIGH, "Launched into the background\n"); if ((pid = fork()) != 0) { call_terms(); exit(0); } const char *forkargs = Args.CheckValue("-fork"); if (forkargs) pidfile = string(forkargs); if(!pidfile.size() || pidfile[0] == '-') pidfile = "doomsv.pid"; pid = getpid(); fpid = fopen(pidfile.c_str(), "w"); fprintf(fpid, "%d\n", pid); fclose(fpid); }
int __cdecl main(int argc, char *argv[]) { try { // Handle ctrl-c, close box, shutdown and logoff events if (!SetConsoleCtrlHandler(ConsoleHandlerRoutine, TRUE)) throw CDoomError("Could not set console control handler!\n"); if (!(hEvent = CreateEvent(NULL, FALSE, FALSE, NULL))) throw CDoomError("Could not create console control event!\n"); // [ML] 2007/9/3: From Eternity (originally chocolate Doom) Thanks SoM & fraggle! Args.SetArgs (argc, argv); const char *CON_FILE = Args.CheckValue("-confile"); if(CON_FILE)CON.open(CON_FILE, std::ios::in); // Set the timer to be as accurate as possible TIMECAPS tc; if (timeGetDevCaps (&tc, sizeof(tc) != TIMERR_NOERROR)) TimerPeriod = 1; // Assume minimum resolution of 1 ms else TimerPeriod = tc.wPeriodMin; timeBeginPeriod (TimerPeriod); // Don't call this on windows! //atexit (call_terms); Z_Init(); atterm (I_Quit); atterm (DObject::StaticShutdown); progdir = I_GetBinaryDir(); startdir = I_GetCWD(); C_InitConsole (80*8, 25*8, false); D_DoomMain (); } catch (CDoomError &error) { if (LOG.is_open()) { LOG << error.GetMessage() << std::endl; LOG << std::endl; } else { MessageBox(NULL, error.GetMessage().c_str(), "Odasrv Error", MB_OK); } exit (-1); } catch (...) { call_terms (); throw; } return 0; }
int main (int argc, char **argv) { try { if(!getuid() || !geteuid()) I_FatalError("root user detected, quitting odamex immediately"); seteuid (getuid ()); Args.SetArgs (argc, argv); const char *CON_FILE = Args.CheckValue("-confile"); if(CON_FILE)CON.open(CON_FILE, std::ios::in); /* killough 1/98: This fixes some problems with exit handling during abnormal situations. The old code called I_Quit() to end program, while now I_Quit() is installed as an exit handler and exit() is called to exit, either normally or abnormally. Seg faults are caught and the error handler is used, to prevent being left in graphics mode or having very loud SFX noise because the sound card is left in an unstable state. */ // Don't use this on other platforms either //atexit (call_terms); Z_Init(); // 1/18/98 killough: start up memory stuff first atterm (I_Quit); atterm (DObject::StaticShutdown); signal(SIGSEGV, handler); signal(SIGTERM, handler); signal(SIGILL, handler); signal(SIGFPE, handler); signal(SIGINT, handler); // killough 3/6/98: allow CTRL-BRK during init signal(SIGABRT, handler); progdir = I_GetBinaryDir(); C_InitConsole (80*8, 25*8, false); D_DoomMain (); } catch (CDoomError &error) { fprintf (stderr, "%s\n", error.GetMessage().c_str()); if (LOG.is_open()) { LOG << error.GetMessage() << std::endl; LOG << std::endl; } call_terms(); exit (-1); } catch (...) { call_terms (); throw; } return 0; }
int __cdecl main(int argc, char *argv[]) { try { Args.SetArgs (argc, argv); LOG_FILE = Args.CheckValue("-logfile"); if(!LOG_FILE)LOG_FILE = "odamex.log"; LOG.open(LOG_FILE, std::ios::out); if (!LOG.is_open()) cerr << "Unable to create logfile: %s" << endl; const char *CON_FILE = Args.CheckValue("-confile"); if(CON_FILE)CON.open(CON_FILE, std::ios::in); // Set the timer to be as accurate as possible TIMECAPS tc; if (timeGetDevCaps (&tc, sizeof(tc) != TIMERR_NOERROR)) TimerPeriod = 1; // Assume minimum resolution of 1 ms else TimerPeriod = tc.wPeriodMin; timeBeginPeriod (TimerPeriod); atexit (call_terms); Z_Init(); atterm (I_Quit); atterm (DObject::StaticShutdown); progdir = I_GetBinaryDir(); startdir = I_GetCWD(); C_InitConsole (80*8, 25*8, false); Printf (PRINT_HIGH, "Heapsize: %u megabytes\n", got_heapsize); D_DoomMain (); } catch (CDoomError &error) { if (LOG.is_open()) { LOG << error.GetMessage() << std::endl; } else { MessageBox(NULL, error.GetMessage().c_str(), "Odasrv Error", MB_OK); } exit (-1); } catch (...) { call_terms (); throw; } return 0; }
int main(int argc, char *argv[]) #endif { try { #if defined(UNIX) && !defined(GEKKO) if(!getuid() || !geteuid()) I_FatalError("root user detected, quitting odamex immediately"); #endif // [ML] 2007/9/3: From Eternity (originally chocolate Doom) Thanks SoM & fraggle! Args.SetArgs (argc, argv); const char *CON_FILE = Args.CheckValue("-confile"); if(CON_FILE)CON.open(CON_FILE, std::ios::in); // denis - if argv[1] starts with "odamex://" if(argc == 2 && argv && argv[1]) { const char *protocol = "odamex://"; const char *uri = argv[1]; if(strncmp(uri, protocol, strlen(protocol)) == 0) { std::string location = uri + strlen(protocol); size_t term = location.find_first_of('/'); if(term == std::string::npos) term = location.length(); Args.AppendArg("-connect"); Args.AppendArg(location.substr(0, term).c_str()); } } // [Russell] - No more double-tapping of capslock to enable autorun putenv("SDL_DISABLE_LOCK_KEYS=1"); #if defined WIN32 && !defined _XBOX // From the SDL 1.2.10 release notes: // // > The "windib" video driver is the default now, to prevent // > problems with certain laptops, 64-bit Windows, and Windows // > Vista. // // The hell with that. // SoM: the gdi interface is much faster for windowed modes which are more // commonly used. Thus, GDI is default. // // GDI mouse issues fill many users with great sadness. We are going back // to directx as defulat for now and the people will rejoice. --Hyper_Eye if (Args.CheckParm ("-gdi")) putenv("SDL_VIDEODRIVER=windib"); else if (getenv("SDL_VIDEODRIVER") == NULL || Args.CheckParm ("-directx") > 0) putenv("SDL_VIDEODRIVER=directx"); // Set the process affinity mask to 1 on Windows, so that all threads // run on the same processor. This is a workaround for a bug in // SDL_mixer that causes occasional crashes. Thanks to entryway and fraggle for this. // // [ML] 8/6/10: Updated to match prboom+'s I_SetAffinityMask. We don't do everything // you might find in there but we do enough for now. HMODULE kernel32_dll = LoadLibrary("kernel32.dll"); if (kernel32_dll) { SetAffinityFunc SetAffinity = (SetAffinityFunc)GetProcAddress(kernel32_dll, "SetProcessAffinityMask"); if (SetAffinity) { if (!SetAffinity(GetCurrentProcess(), 1)) LOG << "Failed to set process affinity mask: " << GetLastError() << std::endl; } } #endif if (SDL_Init (SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE) == -1) I_FatalError("Could not initialize SDL:\n%s\n", SDL_GetError()); atterm (SDL_Quit); /* killough 1/98: This fixes some problems with exit handling during abnormal situations. The old code called I_Quit() to end program, while now I_Quit() is installed as an exit handler and exit() is called to exit, either normally or abnormally. */ atexit (call_terms); Z_Init (); // 1/18/98 killough: start up memory stuff first atterm (R_Shutdown); atterm (I_Quit); atterm (DObject::StaticShutdown); // Figure out what directory the program resides in. progdir = I_GetBinaryDir(); startdir = I_GetCWD(); // init console C_InitConsole (80 * 8, 25 * 8, false); D_DoomMain (); } catch (CDoomError &error) { if (LOG.is_open()) { LOG << error.GetMessage() << std::endl; LOG << std::endl; } #ifndef WIN32 fprintf(stderr, "%s\n", error.GetMessage().c_str()); #elif _XBOX // Use future Xbox error message handling. -- Hyper_Eye #else MessageBox(NULL, error.GetMessage().c_str(), "Odamex Error", MB_OK); #endif exit (-1); } #ifndef _DEBUG catch (...) { // If an exception is thrown, be sure to do a proper shutdown. // This is especially important if we are in fullscreen mode, // because the OS will only show the alert box if we are in // windowed mode. Graphics gets shut down first in case something // goes wrong calling the cleanup functions. call_terms (); // Now let somebody who understands the exception deal with it. throw; } #endif return 0; }
int main(int argc, char *argv[]) { try { #ifdef UNIX if(!getuid() || !geteuid()) I_FatalError("root user detected, quitting odamex immediately"); #endif // [ML] 2007/9/3: From Eternity (originally chocolate Doom) Thanks SoM & fraggle! Args.SetArgs (argc, argv); LOG_FILE = Args.CheckValue("-logfile"); if(!LOG_FILE)LOG_FILE = "odamex.log"; LOG.open(LOG_FILE, std::ios::out); if (!LOG.is_open()) std::cerr << "Unable to create logfile: %s\n" << std::endl; const char *CON_FILE = Args.CheckValue("-confile"); if(CON_FILE)CON.open(CON_FILE, std::ios::in); // denis - if argv[1] starts with "odamex://" if(argc == 2 && argv && argv[1]) { const char *protocol = "odamex://"; const char *uri = argv[1]; if(strncmp(uri, protocol, strlen(protocol)) == 0) { std::string location = uri + strlen(protocol); size_t term = location.find_first_of('/'); if(term == std::string::npos) term = location.length(); Args.AppendArg("-connect"); Args.AppendArg(location.substr(0, term).c_str()); } } #ifdef WIN32 // From the SDL 1.2.10 release notes: // // > The "windib" video driver is the default now, to prevent // > problems with certain laptops, 64-bit Windows, and Windows // > Vista. // // The hell with that. // SoM: the gdi interface is much faster for windowed modes which are more // commonly used. Thus, GDI is default. if (Args.CheckParm ("-directx")) putenv("SDL_VIDEODRIVER=directx"); else if (getenv("SDL_VIDEODRIVER") == NULL || Args.CheckParm ("-gdi") > 0) putenv("SDL_VIDEODRIVER=windib"); // Set the process affinity mask to 1 on Windows, so that all threads // run on the same processor. This is a workaround for a bug in // SDL_mixer that causes occasional crashes. // Thanks to entryway and fraggle for this. if (!SetProcessAffinityMask(GetCurrentProcess(), 1)) LOG << "Failed to set process affinity mask: " << GetLastError() << std::endl; #endif if (SDL_Init (SDL_INIT_TIMER|SDL_INIT_NOPARACHUTE) == -1) I_FatalError("Could not initialize SDL:\n%s\n", SDL_GetError()); atterm (SDL_Quit); /* killough 1/98: This fixes some problems with exit handling during abnormal situations. The old code called I_Quit() to end program, while now I_Quit() is installed as an exit handler and exit() is called to exit, either normally or abnormally. */ atexit (call_terms); Z_Init (); // 1/18/98 killough: start up memory stuff first atterm (I_Quit); atterm (DObject::StaticShutdown); // Figure out what directory the program resides in. progdir = I_GetBinaryDir(); startdir = I_GetCWD(); // init console C_InitConsole (80 * 8, 25 * 8, false); Printf (PRINT_HIGH, "Heapsize: %u megabytes\n", got_heapsize); D_DoomMain (); } catch (CDoomError &error) { if (LOG.is_open()) { LOG << error.GetMessage() << std::endl; } #ifndef WIN32 fprintf(stderr, "%s\n", error.GetMessage().c_str()); #else MessageBox(NULL, error.GetMessage().c_str(), "Odamex Error", MB_OK); #endif exit (-1); } #ifndef _DEBUG catch (...) { // If an exception is thrown, be sure to do a proper shutdown. // This is especially important if we are in fullscreen mode, // because the OS will only show the alert box if we are in // windowed mode. Graphics gets shut down first in case something // goes wrong calling the cleanup functions. call_terms (); // Now let somebody who understands the exception deal with it. throw; } #endif return 0; }