/* ================== main ================== */ int main(int argc, char **argv) { #if USE_WINSVC int i; #endif hGlobalInstance = GetModuleHandle(NULL); #if USE_WINSVC for (i = 1; i < argc; i++) { if (!strcmp(argv[i], "-service")) { argv[i] = NULL; sys_argc = argc; sys_argv = argv; if (StartServiceCtrlDispatcher(serviceTable)) { return 0; } if (GetLastError() == ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) { break; // fall back to normal server startup } return 1; } } #endif return Sys_Main(argc, argv); }
/* ================== WinMain ================== */ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { // previous instances do not exist in Win32 if (hPrevInstance) { return 1; } hGlobalInstance = hInstance; #ifndef UNICODE // TODO: wince support Sys_ParseCommandLine(lpCmdLine); #endif return Sys_Main(sys_argc, sys_argv); }
int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { char lpFilename[MAX_OSPATH]; char sys_cmdline[MAX_STRING_CHARS]; char *lastSep; DWORD copylen; if(lpCmdLine != NULL) Q_strncpyz( sys_cmdline, lpCmdLine, sizeof( sys_cmdline ) ); else sys_cmdline[0] = '\0'; g_wv.hInstance = hInstance; copylen = GetModuleFileName(NULL, lpFilename, sizeof(lpFilename)); if(copylen >= (sizeof(lpFilename) -1)) { Sys_SetExeFile( "" ); Sys_SetBinaryPath( "" ); MessageBoxA(NULL, "Path is too long. The whole path to location of this .exe file must not exceed 254 characters", CLIENT_WINDOW_TITLE " Error", MB_OK | MB_ICONERROR); return 1; }else{ Sys_SetExeFile( lpFilename ); lastSep = strrchr(lpFilename, '\\'); if(lastSep != NULL) { *lastSep = '\0'; if(strlen(lastSep +1) > MAX_QPATH) { MessageBoxA(NULL, ".EXE filename exceeds " "64" " characters.", CLIENT_WINDOW_TITLE " Error", MB_OK | MB_ICONERROR); return 1; } Sys_SetBinaryPath( lpFilename ); }else{ MessageBoxA(NULL, "GetModuleFileName() returned an unexpected filepath.", CLIENT_WINDOW_TITLE " Error", MB_OK | MB_ICONERROR); return 1; } } return Sys_Main(sys_cmdline); }
static VOID WINAPI ServiceMain(DWORD argc, LPTSTR *argv) { SERVICE_STATUS status; statusHandle = RegisterServiceCtrlHandler(APPLICATION, ServiceHandler); if (!statusHandle) { return; } memset(&status, 0, sizeof(status)); status.dwServiceType = SERVICE_WIN32_OWN_PROCESS; status.dwCurrentState = SERVICE_RUNNING; status.dwControlsAccepted = SERVICE_ACCEPT_STOP; SetServiceStatus(statusHandle, &status); Sys_Main(sys_argc, sys_argv); status.dwCurrentState = SERVICE_STOPPED; status.dwControlsAccepted = 0; SetServiceStatus(statusHandle, &status); }
int main(int argc, char* argv[]) { int i; uid_t uid = getuid(); if( uid == 0 || uid != geteuid() ) { // warn user that he/she's operating as a privliged user Com_Printf( "********************************************************\n" ); Com_Printf( "***** RUNNING SERVER AS A ROOT IS GENERALLY UNSAFE *****\n" ); Com_Printf( "********************************************************\n\n" ); } // go back to real user for config loads seteuid( uid ); char commandLine[MAX_STRING_CHARS]; commandLine[0] = 0; // Concatenate the command line for passing to Com_Init for( i = 1; i < argc; i++ ) { const qboolean containsSpaces = strchr(argv[i], ' ') != NULL; if (containsSpaces) Q_strcat( commandLine, sizeof( commandLine ), "\"" ); Q_strcat( commandLine, sizeof( commandLine ), argv[ i ] ); if (containsSpaces) Q_strcat( commandLine, sizeof( commandLine ), "\"" ); Q_strcat( commandLine, sizeof( commandLine ), " " ); } Sys_SetExeFile( argv[ 0 ] ); /* This function modifies argv[ 0 ] :S */ Sys_SetBinaryPath( Sys_Dirname( argv[ 0 ] ) ); return Sys_Main(commandLine); }