Changeset 39423 in vbox for trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlThread.cpp
- Timestamp:
- Nov 25, 2011 11:01:11 AM (13 years ago)
- svn:sync-xref-src-repo-rev:
- 75050
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControlThread.cpp
r39418 r39423 394 394 char abBuf[_64K]; 395 395 size_t cbRead; 396 intrc = RTPipeRead(*phPipeR, abBuf, sizeof(abBuf), &cbRead);396 rc = RTPipeRead(*phPipeR, abBuf, sizeof(abBuf), &cbRead); 397 397 if (RT_SUCCESS(rc) && cbRead) 398 398 { … … 434 434 AssertPtrReturn(phStdErrR, VERR_INVALID_POINTER); 435 435 436 /*int rc = RTCritSectEnter(&pThread->CritSect); 437 if (RT_SUCCESS(rc)) 438 {*/ 439 /* Drain the notification pipe. */ 440 uint8_t abBuf[8]; 441 size_t cbIgnore; 442 rc = RTPipeRead(pThread->hNotificationPipeR, abBuf, sizeof(abBuf), &cbIgnore); 443 if (RT_FAILURE(rc)) 444 VBoxServiceError("ControlThread: Draining IPC notification pipe failed with rc=%Rrc\n", rc); 445 446 int rcReq = VINF_SUCCESS; /* Actual request result. */ 447 448 PVBOXSERVICECTRLREQUEST pRequest = pThread->pRequest; 449 AssertPtr(pRequest); 450 451 switch (pRequest->enmType) 452 { 453 case VBOXSERVICECTRLREQUEST_QUIT: /* Main control asked us to quit. */ 436 /* Drain the notification pipe. */ 437 uint8_t abBuf[8]; 438 size_t cbIgnore; 439 int rc = RTPipeRead(pThread->hNotificationPipeR, abBuf, sizeof(abBuf), &cbIgnore); 440 if (RT_FAILURE(rc)) 441 VBoxServiceError("ControlThread: Draining IPC notification pipe failed with rc=%Rrc\n", rc); 442 443 int rcReq = VINF_SUCCESS; /* Actual request result. */ 444 445 PVBOXSERVICECTRLREQUEST pRequest = pThread->pRequest; 446 AssertPtr(pRequest); 447 448 switch (pRequest->enmType) 449 { 450 case VBOXSERVICECTRLREQUEST_QUIT: /* Main control asked us to quit. */ 451 { 452 /** @todo Check for some conditions to check to 453 * veto quitting. */ 454 pThread->fShutdown = true; 455 rcReq = VINF_SUCCESS; 456 break; 457 } 458 459 case VBOXSERVICECTRLREQUEST_STDIN_WRITE: 460 /* Fall through is intentional. */ 461 case VBOXSERVICECTRLREQUEST_STDIN_WRITE_EOF: 462 { 463 AssertPtrReturn(pRequest->pvData, VERR_INVALID_POINTER); 464 AssertReturn(pRequest->cbData, VERR_INVALID_PARAMETER); 465 466 size_t cbWritten = 0; 467 if (*phStdInW != NIL_RTPIPE) 454 468 { 455 /** @todo Check for some conditions to check to 456 * veto quitting. */ 457 pThread->fShutdown = true; 458 rcReq = VINF_SUCCESS; 459 break; 469 rcReq = RTPipeWrite(*phStdInW, 470 pRequest->pvData, pRequest->cbData, &cbWritten); 460 471 } 461 462 case VBOXSERVICECTRLREQUEST_STDIN_WRITE: 463 /* Fall through is intentional. */ 464 case VBOXSERVICECTRLREQUEST_STDIN_WRITE_EOF: 472 else 473 rcReq = VINF_EOF; 474 475 /* If this is the last write we need to close the stdin pipe on our 476 * end and remove it from the poll set. */ 477 if (VBOXSERVICECTRLREQUEST_STDIN_WRITE_EOF == pRequest->enmType) 478 rc = VBoxServiceControlThreadCloseStdIn(hPollSet, phStdInW); 479 480 /* Reqport back actual data written (if any). */ 481 pRequest->cbData = cbWritten; 482 break; 483 } 484 485 case VBOXSERVICECTRLREQUEST_STDOUT_READ: 486 /* Fall through is intentional. */ 487 case VBOXSERVICECTRLREQUEST_STDERR_READ: 488 { 489 AssertPtrReturn(pRequest->pvData, VERR_INVALID_POINTER); 490 AssertReturn(pRequest->cbData, VERR_INVALID_PARAMETER); 491 492 PRTPIPE pPipeR = pRequest->enmType == VBOXSERVICECTRLREQUEST_STDERR_READ 493 ? phStdErrR : phStdOutR; 494 AssertPtr(pPipeR); 495 496 size_t cbRead = 0; 497 if (*pPipeR != NIL_RTPIPE) 465 498 { 466 AssertPtrReturn(pRequest->pvData, VERR_INVALID_POINTER); 467 AssertReturn(pRequest->cbData, VERR_INVALID_PARAMETER); 468 469 size_t cbWritten = 0; 470 if (*phStdInW != NIL_RTPIPE) 471 { 472 rcReq = RTPipeWrite(*phStdInW, 473 pRequest->pvData, pRequest->cbData, &cbWritten); 474 } 475 else 499 rcReq = RTPipeRead(*pPipeR, 500 pRequest->pvData, pRequest->cbData, &cbRead); 501 if (rcReq == VERR_BROKEN_PIPE) 476 502 rcReq = VINF_EOF; 477 478 /* If this is the last write we need to close the stdin pipe on our479 * end and remove it from the poll set. */480 if (VBOXSERVICECTRLREQUEST_STDIN_WRITE_EOF == pRequest->enmType)481 rc = VBoxServiceControlThreadCloseStdIn(hPollSet, phStdInW);482 483 /* Reqport back actual data written (if any). */484 pRequest->cbData = cbWritten;485 break;486 503 } 487 488 case VBOXSERVICECTRLREQUEST_STDOUT_READ: 489 /* Fall through is intentional. */ 490 case VBOXSERVICECTRLREQUEST_STDERR_READ: 491 { 492 AssertPtrReturn(pRequest->pvData, VERR_INVALID_POINTER); 493 AssertReturn(pRequest->cbData, VERR_INVALID_PARAMETER); 494 495 PRTPIPE pPipeR = pRequest->enmType == VBOXSERVICECTRLREQUEST_STDERR_READ 496 ? phStdErrR : phStdOutR; 497 AssertPtr(pPipeR); 498 499 size_t cbRead = 0; 500 if (*pPipeR != NIL_RTPIPE) 501 { 502 rcReq = RTPipeRead(*pPipeR, 503 pRequest->pvData, pRequest->cbData, &cbRead); 504 if (rcReq == VERR_BROKEN_PIPE) 505 rcReq = VINF_EOF; 506 } 507 else 508 rcReq = VINF_EOF; 509 510 /* Report back actual data read (if any). */ 511 pRequest->cbData = cbRead; 512 break; 513 } 514 515 default: 516 rcReq = VERR_NOT_IMPLEMENTED; 517 break; 518 } 519 520 /* Assign overall result. */ 521 pRequest->rc = RT_SUCCESS(rc) 522 ? rcReq : rc; 523 524 VBoxServiceVerbose(2, "ControlThread: [PID %u]: Handled req=%u, CID=%u, rcReq=%Rrc, cbData=%u\n", 525 pThread->uPID, pRequest->enmType, pRequest->uCID, rcReq, pRequest->cbData); 526 527 /* In any case, regardless of the result, we notify 528 * the main guest control to unblock it. */ 529 int rc2 = RTSemEventMultiSignal(pThread->RequestEvent); 530 AssertRC(rc2); 531 /* No access to pRequest here anymore -- could be out of scope 532 * or modified already! */ 533 534 /*rc2 = RTCritSectLeave(&pThread->CritSect); 535 AssertRC(rc2); 536 }*/ 504 else 505 rcReq = VINF_EOF; 506 507 /* Report back actual data read (if any). */ 508 pRequest->cbData = cbRead; 509 break; 510 } 511 512 default: 513 rcReq = VERR_NOT_IMPLEMENTED; 514 break; 515 } 516 517 /* Assign overall result. */ 518 pRequest->rc = RT_SUCCESS(rc) 519 ? rcReq : rc; 520 521 VBoxServiceVerbose(2, "ControlThread: [PID %u]: Handled req=%u, CID=%u, rcReq=%Rrc, cbData=%u\n", 522 pThread->uPID, pRequest->enmType, pRequest->uCID, rcReq, pRequest->cbData); 523 524 /* In any case, regardless of the result, we notify 525 * the main guest control to unblock it. */ 526 int rc2 = RTSemEventMultiSignal(pThread->RequestEvent); 527 AssertRC(rc2); 528 /* No access to pRequest here anymore -- could be out of scope 529 * or modified already! */ 537 530 538 531 return rc;
Note:
See TracChangeset
for help on using the changeset viewer.