Changeset 52000 in vbox for trunk/src/VBox/HostDrivers
- Timestamp:
- Jul 11, 2014 10:17:14 PM (10 years ago)
- Location:
- trunk/src/VBox/HostDrivers/Support
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/Support/testcase/SUPInstall.cpp
r39091 r52000 45 45 if (RT_SUCCESS(rc)) 46 46 { 47 RTMsgInfo("installed successfully"); 47 if (rc == VINF_SUCCESS) 48 RTMsgInfo("Installed successfully!"); 49 else if (rc == VINF_ALREADY_INITIALIZED) 50 RTMsgInfo("Already loaded."); 51 else if (rc == VWRN_ALREADY_EXISTS) 52 RTMsgInfo("Service already existed; started successfully."); 53 else 54 RTMsgInfo("Unexpected status: %Rrc", rc); 48 55 return RTEXITCODE_SUCCESS; 49 56 } -
trunk/src/VBox/HostDrivers/Support/win/SUPLib-win.cpp
r51978 r52000 229 229 int suplibOsInstall(void) 230 230 { 231 return suplibOsCreateService(); 231 int rc = suplibOsCreateService(); 232 if (RT_SUCCESS(rc)) 233 { 234 int rc2 = suplibOsStartService(); 235 if (rc2 != VINF_SUCCESS) 236 rc = rc2; 237 } 238 return rc; 232 239 } 233 240 … … 236 243 { 237 244 int rc = suplibOsStopService(); 238 if ( !rc)245 if (RT_SUCCESS(rc)) 239 246 rc = suplibOsDeleteService(); 240 247 return rc; … … 245 252 * Creates the service. 246 253 * 247 * @returns 0 on success.248 * @ret urns -1 on failure.254 * @returns VBox status code. 255 * @retval VWRN_ALREADY_EXISTS if it already exists. 249 256 */ 250 257 static int suplibOsCreateService(void) … … 253 260 * Assume it didn't exist, so we'll create the service. 254 261 */ 255 SC_HANDLE hSMgrCreate = OpenSCManager(NULL, NULL, SERVICE_CHANGE_CONFIG); 256 DWORD LastError = GetLastError(); NOREF(LastError); 257 AssertMsg(hSMgrCreate, ("OpenSCManager(,,create) failed rc=%d\n", LastError)); 258 if (hSMgrCreate) 262 int rc; 263 SC_HANDLE hSMgrCreate = OpenSCManager(NULL, NULL, SERVICE_CHANGE_CONFIG); 264 DWORD dwErr = GetLastError(); 265 AssertMsg(hSMgrCreate, ("OpenSCManager(,,create) failed dwErr=%d\n", dwErr)); 266 if (hSMgrCreate != NULL) 259 267 { 260 268 char szDriver[RTPATH_MAX]; 261 intrc = RTPathExecDir(szDriver, sizeof(szDriver) - sizeof("\\VBoxDrv.sys"));269 rc = RTPathExecDir(szDriver, sizeof(szDriver) - sizeof("\\VBoxDrv.sys")); 262 270 if (RT_SUCCESS(rc)) 263 271 { … … 272 280 szDriver, 273 281 NULL, NULL, NULL, NULL, NULL); 274 DWORD LastError = GetLastError(); NOREF(LastError); 275 AssertMsg(hService, ("CreateService failed! LastError=%Rwa szDriver=%s\n", LastError, szDriver)); 276 CloseServiceHandle(hService); 277 CloseServiceHandle(hSMgrCreate); 278 return hService ? 0 : -1; 282 dwErr = GetLastError(); 283 if (hService) 284 { 285 CloseServiceHandle(hService); 286 rc = VINF_SUCCESS; 287 } 288 else if (dwErr == ERROR_SERVICE_EXISTS) 289 rc = VWRN_ALREADY_EXISTS; 290 else 291 { 292 AssertMsgFailed(("CreateService failed! dwErr=%Rwa szDriver=%s\n", dwErr, szDriver)); 293 rc = RTErrConvertFromWin32(dwErr); 294 } 279 295 } 280 296 CloseServiceHandle(hSMgrCreate); 281 return rc; 282 } 283 return -1; 297 } 298 else 299 rc = RTErrConvertFromWin32(GetLastError()); 300 return rc; 284 301 } 285 302 … … 288 305 * Stops a possibly running service. 289 306 * 290 * @returns 0 on success. 291 * @returns -1 on failure. 307 * @returns VBox status code. 292 308 */ 293 309 static int suplibOsStopService(void) … … 296 312 * Assume it didn't exist, so we'll create the service. 297 313 */ 298 int rc = -1;314 int rc; 299 315 SC_HANDLE hSMgr = OpenSCManager(NULL, NULL, SERVICE_STOP | SERVICE_QUERY_STATUS); 300 DWORD LastError = GetLastError(); NOREF(LastError);301 AssertMsg(hSMgr, ("OpenSCManager(,,delete) failed rc=%d\n", LastError));316 DWORD dwErr = GetLastError(); 317 AssertMsg(hSMgr, ("OpenSCManager(,,delete) failed dwErr=%d\n", dwErr)); 302 318 if (hSMgr) 303 319 { … … 311 327 QueryServiceStatus(hService, &Status); 312 328 if (Status.dwCurrentState == SERVICE_STOPPED) 313 rc = 0;329 rc = VINF_SUCCESS; 314 330 else if (ControlService(hService, SERVICE_CONTROL_STOP, &Status)) 315 331 { … … 321 337 } 322 338 if (Status.dwCurrentState == SERVICE_STOPPED) 323 rc = 0;339 rc = VINF_SUCCESS; 324 340 else 325 AssertMsgFailed(("Failed to stop service. status=%d\n", Status.dwCurrentState)); 341 { 342 AssertMsgFailed(("Failed to stop service. status=%d\n", Status.dwCurrentState)); 343 rc = VERR_GENERAL_FAILURE; 344 } 326 345 } 327 346 else 328 347 { 329 DWORD LastError = GetLastError(); NOREF(LastError); 330 AssertMsgFailed(("ControlService failed with LastError=%Rwa. status=%d\n", LastError, Status.dwCurrentState)); 348 dwErr = GetLastError(); 349 AssertMsgFailed(("ControlService failed with dwErr=%Rwa. status=%d\n", dwErr, Status.dwCurrentState)); 350 rc = RTErrConvertFromWin32(dwErr); 331 351 } 332 352 CloseServiceHandle(hService); 333 353 } 334 else if (GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST)335 rc = 0;336 354 else 337 355 { 338 DWORD LastError = GetLastError(); NOREF(LastError); 339 AssertMsgFailed(("OpenService failed LastError=%Rwa\n", LastError)); 356 dwErr = GetLastError(); 357 if (GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST) 358 rc = VINF_SUCCESS; 359 else 360 { 361 AssertMsgFailed(("OpenService failed dwErr=%Rwa\n", dwErr)); 362 rc = RTErrConvertFromWin32(dwErr); 363 } 340 364 } 341 365 CloseServiceHandle(hSMgr); … … 348 372 * Deletes the service. 349 373 * 350 * @returns 0 on success. 351 * @returns -1 on failure. 374 * @returns VBox status code. 352 375 */ 353 376 int suplibOsDeleteService(void) … … 356 379 * Assume it didn't exist, so we'll create the service. 357 380 */ 358 int rc = -1;381 int rc; 359 382 SC_HANDLE hSMgr = OpenSCManager(NULL, NULL, SERVICE_CHANGE_CONFIG); 360 DWORD LastError = GetLastError(); NOREF(LastError);361 AssertMsg(hSMgr, ("OpenSCManager(,,delete) failed rc=%d\n", LastError));383 DWORD dwErr = GetLastError(); 384 AssertMsg(hSMgr, ("OpenSCManager(,,delete) failed rc=%d\n", dwErr)); 362 385 if (hSMgr) 363 386 { … … 369 392 */ 370 393 if (DeleteService(hService)) 371 rc = 0;394 rc = VINF_SUCCESS; 372 395 else 373 396 { 374 DWORD LastError = GetLastError(); NOREF(LastError); 375 AssertMsgFailed(("DeleteService failed LastError=%Rwa\n", LastError)); 397 dwErr = GetLastError(); 398 AssertMsgFailed(("DeleteService failed dwErr=%Rwa\n", dwErr)); 399 rc = RTErrConvertFromWin32(dwErr); 376 400 } 377 401 CloseServiceHandle(hService); 378 402 } 379 else if (GetLastError() == ERROR_SERVICE_DOES_NOT_EXIST)380 rc = 0;381 403 else 382 404 { 383 DWORD LastError = GetLastError(); NOREF(LastError); 384 AssertMsgFailed(("OpenService failed LastError=%Rwa\n", LastError)); 405 dwErr = GetLastError(); 406 if (dwErr == ERROR_SERVICE_DOES_NOT_EXIST) 407 rc = VINF_SUCCESS; 408 else 409 { 410 AssertMsgFailed(("OpenService failed dwErr=%Rwa\n", dwErr)); 411 rc = RTErrConvertFromWin32(dwErr); 412 } 385 413 } 386 414 CloseServiceHandle(hSMgr); … … 453 481 * Attempts to start the service, creating it if necessary. 454 482 * 455 * @returns 0 on success. 456 * @returns -1 on failure. 457 * @param fRetry Indicates retry call. 483 * @returns VBox status code. 458 484 */ 459 485 static int suplibOsStartService(void) … … 465 491 if (hSMgr == NULL) 466 492 { 467 AssertMsgFailed(("couldn't open service manager in SERVICE_QUERY_CONFIG | SERVICE_QUERY_STATUS mode!\n")); 468 return -1; 493 DWORD dwErr = GetLastError(); 494 AssertMsgFailed(("couldn't open service manager in SERVICE_QUERY_CONFIG | SERVICE_QUERY_STATUS mode! (dwErr=%d)\n", dwErr)); 495 return RTErrConvertFromWin32(dwErr); 469 496 } 470 497 … … 479 506 */ 480 507 int rc = suplibOsCreateService(); 481 if ( rc)508 if (RT_FAILURE(rc)) 482 509 return rc; 483 510 … … 491 518 * Check if open and on demand create succeeded. 492 519 */ 493 int rc = -1;520 int rc; 494 521 if (hService) 495 522 { … … 498 525 * Query service status to see if we need to start it or not. 499 526 */ 500 SERVICE_STATUS 527 SERVICE_STATUS Status; 501 528 BOOL fRc = QueryServiceStatus(hService, &Status); 502 529 Assert(fRc); 503 if ( Status.dwCurrentState != SERVICE_RUNNING 504 && Status.dwCurrentState != SERVICE_START_PENDING) 505 { 530 if (Status.dwCurrentState == SERVICE_RUNNING) 531 rc = VINF_ALREADY_INITIALIZED; 532 else 533 { 534 if (Status.dwCurrentState == SERVICE_START_PENDING) 535 rc = VINF_SUCCESS; 536 else 537 { 538 /* 539 * Start it. 540 */ 541 if (StartService(hService, 0, NULL)) 542 rc = VINF_SUCCESS; 543 else 544 { 545 DWORD dwErr = GetLastError(); 546 AssertMsg(fRc, ("StartService failed with dwErr=%Rwa\n", dwErr)); 547 rc = RTErrConvertFromWin32(dwErr); 548 } 549 } 550 506 551 /* 507 * Start it. 552 * Wait for the service to finish starting. 553 * We'll wait for 10 seconds then we'll give up. 508 554 */ 509 fRc = StartService(hService, 0, NULL); 510 DWORD LastError = GetLastError(); NOREF(LastError); 511 #ifndef DEBUG_bird 512 AssertMsg(fRc, ("StartService failed with LastError=%Rwa\n", LastError)); 513 #endif 514 } 515 516 /* 517 * Wait for the service to finish starting. 518 * We'll wait for 10 seconds then we'll give up. 519 */ 520 QueryServiceStatus(hService, &Status); 521 if (Status.dwCurrentState == SERVICE_START_PENDING) 522 { 523 int iWait; 524 for (iWait = 100; iWait > 0 && Status.dwCurrentState == SERVICE_START_PENDING; iWait--) 525 { 526 Sleep(100); 527 QueryServiceStatus(hService, &Status); 528 } 529 DWORD LastError = GetLastError(); NOREF(LastError); 530 AssertMsg(Status.dwCurrentState != SERVICE_RUNNING, 531 ("Failed to start. LastError=%Rwa iWait=%d status=%d\n", 532 LastError, iWait, Status.dwCurrentState)); 533 } 534 535 if (Status.dwCurrentState == SERVICE_RUNNING) 536 rc = 0; 555 QueryServiceStatus(hService, &Status); 556 if (Status.dwCurrentState == SERVICE_START_PENDING) 557 { 558 int iWait; 559 for (iWait = 100; iWait > 0 && Status.dwCurrentState == SERVICE_START_PENDING; iWait--) 560 { 561 Sleep(100); 562 QueryServiceStatus(hService, &Status); 563 } 564 DWORD dwErr = GetLastError(); NOREF(dwErr); 565 AssertMsg(Status.dwCurrentState != SERVICE_RUNNING, 566 ("Failed to start. dwErr=%Rwa iWait=%d status=%d\n", dwErr, iWait, Status.dwCurrentState)); 567 } 568 569 if (Status.dwCurrentState == SERVICE_RUNNING) 570 rc = VINF_SUCCESS; 571 else if (RT_SUCCESS_NP(rc)) 572 rc = VERR_GENERAL_FAILURE; 573 } 537 574 538 575 /* … … 543 580 else 544 581 { 545 DWORD LastError = GetLastError(); NOREF(LastError); 546 AssertMsgFailed(("OpenService failed! LastError=%Rwa\n", LastError)); 582 DWORD dwErr = GetLastError(); 583 AssertMsgFailed(("OpenService failed! LastError=%Rwa\n", dwErr)); 584 rc = RTErrConvertFromWin32(dwErr); 547 585 } 548 586 if (!CloseServiceHandle(hSMgr))
Note:
See TracChangeset
for help on using the changeset viewer.