Changeset 37666 in vbox for trunk/src/VBox/Main/src-server/win
- Timestamp:
- Jun 28, 2011 12:33:34 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/src-server/win/svcmain.cpp
r36900 r37666 185 185 RTR3Init(); 186 186 187 /* Note that all options are given lowercase/camel case/uppercase to 188 * approximate case insensitive matching, which RTGetOpt doesn't offer. */ 189 static const RTGETOPTDEF s_aOptions[] = 190 { 191 { "--embedding", 'e', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, 192 { "-embedding", 'e', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, 193 { "/embedding", 'e', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, 194 { "--unregserver", 'u', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, 195 { "-unregserver", 'u', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, 196 { "/unregserver", 'u', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, 197 { "--regserver", 'r', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, 198 { "-regserver", 'r', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, 199 { "/regserver", 'r', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, 200 { "--reregserver", 'f', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, 201 { "-reregserver", 'f', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, 202 { "/reregserver", 'f', RTGETOPT_REQ_NOTHING | RTGETOPT_FLAG_ICASE }, 203 { "--helper", 'H', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE }, 204 { "-helper", 'H', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE }, 205 { "/helper", 'H', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE }, 206 { "--logfile", 'F', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE }, 207 { "-logfile", 'F', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE }, 208 { "/logfile", 'F', RTGETOPT_REQ_STRING | RTGETOPT_FLAG_ICASE }, 209 { "--logrotate", 'R', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE }, 210 { "-logrotate", 'R', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE }, 211 { "/logrotate", 'R', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE }, 212 { "--logsize", 'S', RTGETOPT_REQ_UINT64 | RTGETOPT_FLAG_ICASE }, 213 { "-logsize", 'S', RTGETOPT_REQ_UINT64 | RTGETOPT_FLAG_ICASE }, 214 { "/logsize", 'S', RTGETOPT_REQ_UINT64 | RTGETOPT_FLAG_ICASE }, 215 { "--loginterval", 'I', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE }, 216 { "-loginterval", 'I', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE }, 217 { "/loginterval", 'I', RTGETOPT_REQ_UINT32 | RTGETOPT_FLAG_ICASE }, 218 }; 219 220 bool fRun = true; 221 bool fRegister = false; 222 bool fUnregister = false; 223 const char *pszPipeName = NULL; 224 const char *pszLogFile = NULL; 225 uint32_t cHistory = 10; // enable log rotation, 10 files 226 uint32_t uHistoryFileTime = RT_SEC_1DAY; // max 1 day per file 227 uint64_t uHistoryFileSize = 100 * _1M; // max 100MB per file 228 229 RTGETOPTSTATE GetOptState; 230 int vrc = RTGetOptInit(&GetOptState, argc, argv, &s_aOptions[0], RT_ELEMENTS(s_aOptions), 1, 0 /*fFlags*/); 231 AssertRC(vrc); 232 233 RTGETOPTUNION ValueUnion; 234 while ((vrc = RTGetOpt(&GetOptState, &ValueUnion))) 235 { 236 switch (vrc) 237 { 238 case 'e': 239 /* already handled above */ 240 break; 241 242 case 'u': 243 fUnregister = true; 244 fRun = false; 245 break; 246 247 case 'r': 248 fRegister = true; 249 break; 250 251 case 'f': 252 fUnregister = true; 253 fRegister = true; 254 fRun = false; 255 break; 256 257 case 'H': 258 pszPipeName = ValueUnion.psz; 259 if (!pszPipeName) 260 pszPipeName = ""; 261 fRun = false; 262 break; 263 264 case 'F': 265 pszLogFile = ValueUnion.psz; 266 break; 267 268 case 'R': 269 cHistory = ValueUnion.u32; 270 break; 271 272 case 'S': 273 uHistoryFileSize = ValueUnion.u64; 274 break; 275 276 case 'I': 277 uHistoryFileTime = ValueUnion.u32; 278 break; 279 280 case 'h': 281 TCHAR txt[]= L"Options:\n\n" 282 L"/RegServer:\tregister COM out-of-proc server\n" 283 L"/UnregServer:\tunregister COM out-of-proc server\n" 284 L"/ReregServer:\tunregister and register COM server\n" 285 L"no options:\trun the server"; 286 TCHAR title[]=_T("Usage"); 287 fRun = false; 288 MessageBox(NULL, txt, title, MB_OK); 289 break; 290 291 case 'V': 292 char *psz = NULL; 293 RTStrAPrintf(&psz, "%sr%s\n", RTBldCfgVersion(), RTBldCfgRevisionStr()); 294 TCHAR *txt; 295 RTStrToUni(psz, &txt); 296 TCHAR title[]=_T("Version"); 297 fRun = false; 298 MessageBox(NULL, txt, title, MB_OK); 299 RTStrFree(psz); 300 RTUniFree(txt); 301 break; 302 303 default: 304 /** @todo this assumes that stderr is visible, which is not 305 * true for standard Windows applications. */ 306 return RTGetOptPrintError(vrc, &ValueUnion); 307 } 308 } 309 310 if (!pszLogFile) 311 { 312 char szLogFile[RTPATH_MAX]; 313 vrc = com::GetVBoxUserHomeDirectory(szLogFile, sizeof(szLogFile)); 314 if (RT_SUCCESS(vrc)) 315 vrc = RTPathAppend(szLogFile, sizeof(szLogFile), "VBoxSVC.log"); 316 if (RT_SUCCESS(vrc)) 317 pszLogFile = RTStrDup(szLogFile); 318 } 319 /* Only create the log file when running VBoxSVC normally, but not when 320 * registering/unregistering or calling the helper functionality. */ 321 if (fRun) 322 VBoxSVCLogRelCreate(pszLogFile, cHistory, uHistoryFileTime, uHistoryFileSize); 323 324 int nRet = 0; 187 325 HRESULT hRes = com::Initialize(); 188 326 … … 191 329 _Module.dwThreadID = GetCurrentThreadId(); 192 330 193 int nRet = 0; 194 BOOL bRun = TRUE; 195 lpszToken = FindOneOf(lpCmdLine, szTokens); 196 while (lpszToken != NULL) 197 { 198 if (WordCmpI(lpszToken, _T("UnregServer")) == 0) 331 if (!fRun) 332 { 333 if (fUnregister) 199 334 { 200 335 _Module.UpdateRegistryFromResource(IDR_VIRTUALBOX, FALSE); 201 336 nRet = _Module.UnregisterServer(TRUE); 202 bRun = FALSE; 203 break; 204 } 205 else if (WordCmpI(lpszToken, _T("RegServer")) == 0) 337 } 338 if (fRegister) 206 339 { 207 340 _Module.UpdateRegistryFromResource(IDR_VIRTUALBOX, TRUE); 208 341 nRet = _Module.RegisterServer(TRUE); 209 bRun = FALSE; 210 break; 211 } 212 else if (WordCmpI(lpszToken, _T("ReregServer")) == 0) 213 { 214 _Module.UpdateRegistryFromResource(IDR_VIRTUALBOX, FALSE); 215 nRet = _Module.UnregisterServer(TRUE); 216 _Module.UpdateRegistryFromResource(IDR_VIRTUALBOX, TRUE); 217 nRet = _Module.RegisterServer(TRUE); 218 bRun = FALSE; 219 break; 220 } 221 else if ( (WordCmpI(lpszToken, _T("h")) == 0) 222 || (WordCmpI(lpszToken, _T("?")) == 0)) 223 { 224 TCHAR txt[]= L"Options:\n\n" 225 L"/RegServer:\tregister COM out-of-proc server\n" 226 L"/UnregServer:\tunregister COM out-of-proc server\n" 227 L"/ReregServer:\tunregister and register COM server\n" 228 L"no options:\trun the server"; 229 TCHAR title[]=_T("Usage"); 230 nRet = -1; 231 bRun = FALSE; 232 MessageBox(NULL, txt, title, MB_OK); 233 break; 234 } 235 else if (WordCmpI (lpszToken, _T("Helper")) == 0) 236 { 237 Log (("SVCMAIN: Processing Helper request (cmdline=\"%ls\")...\n", 238 lpszToken + 6)); 239 240 TCHAR szTokens[] = _T (" \t"); 241 242 int vrc = VINF_SUCCESS; 243 Utf8Str pipeName; 244 245 lpszToken = FindOneOf (lpszToken, szTokens); 246 if (lpszToken) 247 { 248 while (*lpszToken != NULL && 249 (*lpszToken == ' ' || *lpszToken == '\t')) 250 ++ lpszToken; 251 252 if (*lpszToken != NULL) 253 pipeName = Utf8Str(lpszToken); 254 } 255 256 if (pipeName.isEmpty()) 342 } 343 if (!pszPipeName) 344 { 345 Log(("SVCMAIN: Processing Helper request (cmdline=\"%s\")...\n", pszPipeName)); 346 347 if (!*pipeName) 257 348 vrc = VERR_INVALID_PARAMETER; 258 349 … … 267 358 if (RT_FAILURE(vrc)) 268 359 { 269 Utf8Str err = Utf8StrFmt ( 270 "Failed to process Helper request (%Rrc).", vrc); 271 Log (("SVCMAIN: %s\n", err.c_str())); 360 Log(("SVCMAIN: Failed to process Helper request (%Rrc).", vrc)); 361 nRet = 1; 272 362 } 273 274 /* don't run the COM server */ 275 bRun = FALSE; 276 break; 277 } 278 279 lpszToken = FindOneOf(lpszToken, szTokens); 280 } 281 282 if (bRun) 363 } 364 } 365 else 283 366 { 284 367 _Module.StartMonitor();
Note:
See TracChangeset
for help on using the changeset viewer.