VirtualBox

Ignore:
Timestamp:
Jan 23, 2012 6:38:18 PM (13 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
75849
Message:

GuestCtrl: Request (IPC) changes, bugfixes, fixed handle leaks.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxService/VBoxServiceControl.cpp

    r39659 r39843  
    187187        }
    188188        else if (RT_FAILURE(rc))
    189             VBoxServiceVerbose(3, "Control: Getting host message failed with %Rrc\n", rc); /* VERR_GEN_IO_FAILURE seems to be normal if ran  into timeout. */
     189            VBoxServiceVerbose(3, "Control: Getting host message failed with %Rrc\n", rc); /* VERR_GEN_IO_FAILURE seems to be normal if ran into timeout. */
    190190        if (RT_SUCCESS(rc))
    191191        {
     
    360360
    361361    int rc = VINF_SUCCESS;
    362 
    363     VBOXSERVICECTRLREQUEST ctrlRequest;
    364     ctrlRequest.uCID   = uCID;
    365     ctrlRequest.cbData = cbBuf;
    366     ctrlRequest.pvData = (uint8_t*)pvBuf;
    367 
     362    VBOXSERVICECTRLREQUESTTYPE reqType;
    368363    switch (uHandleId)
    369364    {
    370365        case OUTPUT_HANDLE_ID_STDERR:
    371             ctrlRequest.enmType = VBOXSERVICECTRLREQUEST_STDERR_READ;
     366            reqType = VBOXSERVICECTRLREQUEST_STDERR_READ;
    372367            break;
    373368
    374369        case OUTPUT_HANDLE_ID_STDOUT:
    375370        case OUTPUT_HANDLE_ID_STDOUT_DEPRECATED:
    376             ctrlRequest.enmType = VBOXSERVICECTRLREQUEST_STDOUT_READ;
     371            reqType = VBOXSERVICECTRLREQUEST_STDOUT_READ;
    377372            break;
    378373
     
    382377    }
    383378
     379    PVBOXSERVICECTRLREQUEST pRequest;
    384380    if (RT_SUCCESS(rc))
    385         rc = VBoxServiceControlThreadPerform(uPID, &ctrlRequest);
    386 
    387     if (RT_SUCCESS(rc))
    388     {
    389         if (pcbRead)
    390             *pcbRead = ctrlRequest.cbData;
    391     }
    392     else /* Something went wrong, nothing read. */
    393         *pcbRead = 0;
     381    {
     382        rc = VBoxServiceControlThreadRequestAllocEx(&pRequest, reqType,
     383                                                    pvBuf, cbBuf, uCID);
     384        if (RT_SUCCESS(rc))
     385            rc = VBoxServiceControlThreadPerform(uPID, pRequest);
     386
     387        if (RT_SUCCESS(rc))
     388        {
     389            if (pcbRead)
     390                *pcbRead = pRequest->cbData;
     391        }
     392
     393        VBoxServiceControlThreadRequestFree(pRequest);
     394    }
    394395
    395396    return rc;
     
    416417    /* pcbWritten is optional. */
    417418
    418     int rc = VINF_SUCCESS;
    419 
    420     VBOXSERVICECTRLREQUEST ctrlRequest;
    421     ctrlRequest.uCID    = uCID;
    422     ctrlRequest.cbData  = cbBuf;
    423     ctrlRequest.pvData  = pvBuf;
    424     ctrlRequest.enmType = fPendingClose
    425                         ? VBOXSERVICECTRLREQUEST_STDIN_WRITE_EOF : VBOXSERVICECTRLREQUEST_STDIN_WRITE;
     419    PVBOXSERVICECTRLREQUEST pRequest;
     420    int rc = VBoxServiceControlThreadRequestAllocEx(&pRequest,
     421                                                      fPendingClose
     422                                                    ? VBOXSERVICECTRLREQUEST_STDIN_WRITE_EOF
     423                                                    : VBOXSERVICECTRLREQUEST_STDIN_WRITE,
     424                                                    pvBuf, cbBuf, uCID);
    426425    if (RT_SUCCESS(rc))
    427         rc = VBoxServiceControlThreadPerform(uPID, &ctrlRequest);
    428 
    429     if (RT_SUCCESS(rc))
    430     {
    431         if (pcbWritten)
    432             *pcbWritten = ctrlRequest.cbData;
     426    {
     427        rc = VBoxServiceControlThreadPerform(uPID, pRequest);
     428        if (RT_SUCCESS(rc))
     429        {
     430            if (pcbWritten)
     431                *pcbWritten = pRequest->cbData;
     432        }
     433
     434        VBoxServiceControlThreadRequestFree(pRequest);
    433435    }
    434436
     
    559561    if (RT_SUCCESS(rc))
    560562    {
    561         uint32_t cbRead = 0;
    562563        uint8_t *pBuf = (uint8_t*)RTMemAlloc(_64K);
    563564        if (pBuf)
    564565        {
     566            uint32_t cbRead = 0;
    565567            rc = VBoxServiceControlExecGetOutput(uPID, uContextID, uHandleID, RT_INDEFINITE_WAIT /* Timeout */,
    566568                                                 pBuf, _64K /* cbSize */, &cbRead);
     569            VBoxServiceVerbose(3, "Control: Got output returned with rc=%Rrc (PID=%u, CID=%u, cbRead=%u, uHandle=%u, uFlags=%u)\n",
     570                               rc, uPID, uContextID, cbRead, uHandleID, uFlags);
    567571
    568572            /** Note: Don't convert/touch/modify/whatever the output data here! This might be binary
    569573             *        data which the host needs to work with -- so just pass through all data unfiltered! */
    570574
    571             if (RT_SUCCESS(rc))
    572                 VBoxServiceVerbose(2, "Control: Got output, PID=%u, CID=%u, cbRead=%u, uHandle=%u, uFlags=%u\n",
    573                                    uPID, uContextID, cbRead, uHandleID, uFlags);
    574             else if (rc == VERR_NOT_FOUND)
    575                 VBoxServiceVerbose(2, "Control: PID=%u not found, CID=%u, uHandle=%u\n",
    576                                    uPID, uContextID, uHandleID, rc);
    577             else
    578                 VBoxServiceError("Control: Failed to retrieve output for PID=%u, CID=%u, uHandle=%u, rc=%Rrc\n",
    579                                  uPID, uContextID, uHandleID, rc);
    580575            /* Note: Since the context ID is unique the request *has* to be completed here,
    581576             *       regardless whether we got data or not! Otherwise the progress object
    582577             *       on the host never will get completed! */
    583             /* cbRead now contains actual size. */
    584578            int rc2 = VbglR3GuestCtrlExecSendOut(idClient, uContextID, uPID, uHandleID, uFlags,
    585579                                                 pBuf, cbRead);
     
    656650
    657651#ifdef DEBUG
    658         PVBOXSERVICECTRLTHREAD pThreadCur;
    659         uint32_t cThreads = 0;
    660         RTListForEach(&g_GuestControlThreads, pThreadCur, VBOXSERVICECTRLTHREAD, Node)
    661             cThreads++;
    662         VBoxServiceVerbose(4, "Control: Guest process threads left=%u\n", cThreads);
     652    PVBOXSERVICECTRLTHREAD pThreadCur;
     653    uint32_t cThreads = 0;
     654    RTListForEach(&g_GuestControlThreads, pThreadCur, VBOXSERVICECTRLTHREAD, Node)
     655        cThreads++;
     656    VBoxServiceVerbose(4, "Control: Guest process threads left=%u\n", cThreads);
    663657#endif
    664658    AssertMsg(RTListIsEmpty(&g_GuestControlThreads),
     
    717711            RTListForEach(&g_GuestControlThreads, pThread, VBOXSERVICECTRLTHREAD, Node)
    718712            {
    719                 VBOXSERVICECTRLTHREADSTATUS enmStatus = VBoxServiceControlThreadGetStatus(pThread);
    720                 if (enmStatus == VBOXSERVICECTRLTHREADSTATUS_STARTED)
    721                     uProcsRunning++;
    722                 else if (enmStatus == VBOXSERVICECTRLTHREADSTATUS_STOPPED)
    723                     uProcsStopped++;
    724                 else
    725                     AssertMsgFailed(("Control: Guest process neither started nor stopped!?\n"));
     713                  VBoxServiceControlThreadActive(pThread)
     714                ? uProcsRunning++
     715                : uProcsStopped++;
    726716            }
    727717
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette