VirtualBox

Changeset 28803 in vbox for trunk


Ignore:
Timestamp:
Apr 27, 2010 9:53:43 AM (15 years ago)
Author:
vboxsync
Message:

Guest Control: Update on error codes/handling in Main/VBoxManage.

Location:
trunk/src/VBox
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxManage/VBoxManageGuestCtrl.cpp

    r28800 r28803  
    342342                        || waitForStdErr)
    343343                    {
    344                         if (verbose) RTPrintf("Retrieving output data ...\n");
     344                        bool bFound = false;
    345345                        while (true)
    346346                        {
     
    352352                            if (cbOutputData == 0)
    353353                                break;
     354
     355                            if (!bFound && verbose)
     356                            {
     357                                RTPrintf("Retrieving output data ...\n");
     358                                bFound = true;
     359                            }
    354360
    355361                            /* aOutputData has a platform dependent line ending, standardize on
     
    372378                            RTStrmWrite(g_pStdOut, aOutputData.raw(), cbOutputDataPrint);
    373379                        }
     380                        if (!bFound && verbose)
     381                            RTPrintf("No output data available\n");
    374382                    }
    375383                }
  • trunk/src/VBox/Main/GuestImpl.cpp

    r28800 r28803  
    568568    int rc = VINF_SUCCESS;
    569569
    570     AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    571 
    572570    AssertPtr(pData);
    573571    CallbackListIter it = getCtrlCallbackContextByID(pData->hdr.u32ContextID);
     
    578576        AssertPtr(pCBData);
    579577
     578        AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     579
    580580        pCBData->u32PID = pData->u32PID;
    581581        pCBData->u32HandleId = pData->u32HandleId;
     
    586586        {
    587587            pCBData->pvData = RTMemAlloc(pData->cbData);
    588             AssertPtr(pCBData->pvData);
     588            AssertReturn(pCBData->pvData, VERR_NO_MEMORY);
    589589            memcpy(pCBData->pvData, pData->pvData, pData->cbData);
    590590            pCBData->cbData = pData->cbData;
     
    630630    LogFlowFuncEnter();
    631631    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
    632     if (it->cbData)
     632    if (it->pvData)
    633633    {
    634634        RTMemFree(it->pvData);
     635        it->pvData = NULL;
    635636        it->cbData = 0;
    636         it->pvData = NULL;
    637637
    638638        /* Notify outstanding waits for progress ... */
     
    734734            uNumArgs = args.size();
    735735            papszArgv = (char**)RTMemAlloc(sizeof(char*) * (uNumArgs + 1));
    736             AssertPtr(papszArgv);
     736            AssertReturn(papszArgv, VERR_NO_MEMORY);
    737737            for (unsigned i = 0; RT_SUCCESS(vrc) && i < uNumArgs; i++)
    738738                vrc = RTStrAPrintf(&papszArgv[i], "%s", Utf8Str(args[i]).raw());
     
    775775                {
    776776                    PHOSTEXECCALLBACKDATA pData = (HOSTEXECCALLBACKDATA*)RTMemAlloc(sizeof(HOSTEXECCALLBACKDATA));
    777                     AssertPtr(pData);
     777                    AssertReturn(pData, VBOX_E_IPRT_ERROR);
    778778                    uContextID = addCtrlCallbackContext(VBOXGUESTCTRLCALLBACKTYPE_EXEC_START,
    779779                                                        pData, sizeof(HOSTEXECCALLBACKDATA), progress);
     
    840840                            cMsWait = RT_MIN(1000, aTimeoutMS - (uint32_t)cMsElapsed);
    841841                        }
    842                         RTThreadSleep(100);
     842                        RTThreadYield();
    843843                    } while (!it->bCalled);
    844844                }
     
    972972    HRESULT rc = S_OK;
    973973
    974     /* Search for existing PID. */
    975     PHOSTEXECOUTCALLBACKDATA pData = (HOSTEXECOUTCALLBACKDATA*)RTMemAlloc(sizeof(HOSTEXECOUTCALLBACKDATA));
    976     uint32_t uContextID = addCtrlCallbackContext(VBOXGUESTCTRLCALLBACKTYPE_EXEC_OUTPUT,
    977                                                  pData, sizeof(HOSTEXECOUTCALLBACKDATA), NULL /* pProgress */);
    978     Assert(uContextID > 0);
    979 
    980     size_t cbData = (size_t)RT_MIN(aSize, _64K);
    981     com::SafeArray<BYTE> outputData(cbData);
    982 
    983     VBOXHGCMSVCPARM paParms[5];
    984     int i = 0;
    985     paParms[i++].setUInt32(uContextID);
    986     paParms[i++].setUInt32(aPID);
    987     paParms[i++].setUInt32(aFlags); /** @todo Should represent stdout and/or stderr. */
    988 
    989     int vrc = VINF_SUCCESS;
    990 
    991     {
    992         /* Make sure mParent is valid, so set the read lock while using. */
    993         AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    994 
    995         /* Forward the information to the VMM device. */
    996         AssertPtr(mParent);
    997         VMMDev *vmmDev = mParent->getVMMDev();
    998         if (vmmDev)
    999         {
    1000             LogFlowFunc(("hgcmHostCall numParms=%d\n", i));
    1001             vrc = vmmDev->hgcmHostCall("VBoxGuestControlSvc", HOST_EXEC_GET_OUTPUT,
    1002                                        i, paParms);
    1003         }
    1004     }
    1005 
    1006     if (RT_SUCCESS(vrc))
    1007     {
    1008         LogFlowFunc(("Waiting for HGCM callback (timeout=%ldms) ...\n", aTimeoutMS));
    1009 
    1010         /*
    1011          * Wait for the HGCM low level callback until the process
    1012          * has been started (or something went wrong). This is necessary to
    1013          * get the PID.
    1014          */
    1015         CallbackListIter it = getCtrlCallbackContextByID(uContextID);
    1016         if (it != mCallbackList.end())
    1017         {
    1018             uint64_t u64Started = RTTimeMilliTS();
    1019             do
     974    try
     975    {
     976        /* Search for existing PID. */
     977        PHOSTEXECOUTCALLBACKDATA pData = (HOSTEXECOUTCALLBACKDATA*)RTMemAlloc(sizeof(HOSTEXECOUTCALLBACKDATA));
     978        AssertReturn(pData, VBOX_E_IPRT_ERROR);
     979        uint32_t uContextID = addCtrlCallbackContext(VBOXGUESTCTRLCALLBACKTYPE_EXEC_OUTPUT,
     980                                                     pData, sizeof(HOSTEXECOUTCALLBACKDATA), NULL /* pProgress */);
     981        Assert(uContextID > 0);
     982   
     983        size_t cbData = (size_t)RT_MIN(aSize, _64K);
     984        com::SafeArray<BYTE> outputData(cbData);
     985   
     986        VBOXHGCMSVCPARM paParms[5];
     987        int i = 0;
     988        paParms[i++].setUInt32(uContextID);
     989        paParms[i++].setUInt32(aPID);
     990        paParms[i++].setUInt32(aFlags); /** @todo Should represent stdout and/or stderr. */
     991   
     992        int vrc = VINF_SUCCESS;
     993   
     994        {
     995            /* Make sure mParent is valid, so set the read lock while using. */
     996            AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     997   
     998            /* Forward the information to the VMM device. */
     999            AssertPtr(mParent);
     1000            VMMDev *vmmDev = mParent->getVMMDev();
     1001            if (vmmDev)
    10201002            {
    1021                 unsigned cMsWait;
    1022                 if (aTimeoutMS == RT_INDEFINITE_WAIT)
    1023                     cMsWait = 1000;
     1003                LogFlowFunc(("hgcmHostCall numParms=%d\n", i));
     1004                vrc = vmmDev->hgcmHostCall("VBoxGuestControlSvc", HOST_EXEC_GET_OUTPUT,
     1005                                           i, paParms);
     1006            }
     1007        }
     1008   
     1009        if (RT_SUCCESS(vrc))
     1010        {
     1011            LogFlowFunc(("Waiting for HGCM callback (timeout=%ldms) ...\n", aTimeoutMS));
     1012   
     1013            /*
     1014             * Wait for the HGCM low level callback until the process
     1015             * has been started (or something went wrong). This is necessary to
     1016             * get the PID.
     1017             */
     1018            CallbackListIter it = getCtrlCallbackContextByID(uContextID);
     1019            if (it != mCallbackList.end())
     1020            {
     1021                uint64_t u64Started = RTTimeMilliTS();
     1022                do
     1023                {
     1024                    unsigned cMsWait;
     1025                    if (aTimeoutMS == RT_INDEFINITE_WAIT)
     1026                        cMsWait = 1000;
     1027                    else
     1028                    {
     1029                        uint64_t cMsElapsed = RTTimeMilliTS() - u64Started;
     1030                        if (cMsElapsed >= aTimeoutMS)
     1031                            break; /* timed out */
     1032                        cMsWait = RT_MIN(1000, aTimeoutMS - (uint32_t)cMsElapsed);
     1033                    }
     1034                    RTThreadYield();
     1035                } while (!it->bCalled);
     1036   
     1037                AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     1038   
     1039                /* Did we get some output? */
     1040                pData = (HOSTEXECOUTCALLBACKDATA*)it->pvData;
     1041                Assert(it->cbData == sizeof(HOSTEXECOUTCALLBACKDATA));
     1042                AssertPtr(pData);
     1043   
     1044                if (   it->bCalled
     1045                    && pData->cbData
     1046                    && pData->pvData)
     1047                {
     1048                    /* Do we need to resize the array? */
     1049                    if (pData->cbData > cbData)
     1050                        outputData.resize(pData->cbData);
     1051   
     1052                    /* Fill output in supplied out buffer. */
     1053                    memcpy(outputData.raw(), pData->pvData, pData->cbData);
     1054                    outputData.resize(pData->cbData); /* Shrink to fit actual buffer size. */
     1055                }
    10241056                else
    1025                 {
    1026                     uint64_t cMsElapsed = RTTimeMilliTS() - u64Started;
    1027                     if (cMsElapsed >= aTimeoutMS)
    1028                         break; /* timed out */
    1029                     cMsWait = RT_MIN(1000, aTimeoutMS - (uint32_t)cMsElapsed);
    1030                 }
    1031                 RTThreadSleep(100);
    1032             } while (!it->bCalled);
    1033 
    1034             AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    1035 
    1036             /* Did we get some output? */
    1037             pData = (HOSTEXECOUTCALLBACKDATA*)it->pvData;
    1038             Assert(it->cbData == sizeof(HOSTEXECOUTCALLBACKDATA));
    1039             AssertPtr(pData);
    1040 
    1041             if (   it->bCalled
    1042                 && pData->cbData)
    1043             {
    1044                 /* Do we need to resize the array? */
    1045                 if (pData->cbData > cbData)
    1046                     outputData.resize(pData->cbData);
    1047 
    1048                 /* Fill output in supplied out buffer. */
    1049                 memcpy(outputData.raw(), pData->pvData, pData->cbData);
    1050                 outputData.resize(pData->cbData); /* Shrink to fit actual buffer size. */
     1057                    vrc = VERR_NO_DATA; /* This is not an error we want to report to COM. */
    10511058            }
    10521059            else
    1053                 vrc = VERR_NO_DATA; /* This is not an error we want to report to COM. */
    1054         }
    1055 
     1060                rc = setError(VBOX_E_IPRT_ERROR,
     1061                              tr("Process (PID %u) not found!"), aPID);   
     1062        }
     1063        else
     1064            rc = setError(E_UNEXPECTED,
     1065                          tr("The HGCM call failed with error %Rrc"), vrc);
     1066   
    10561067        /* If something failed (or there simply was no data, indicated by VERR_NO_DATA,
    10571068         * we return an empty array so that the frontend knows when to give up. */
     
    10601071        outputData.detachTo(ComSafeArrayOutArg(aData));
    10611072    }
     1073    catch (std::bad_alloc &)
     1074    {
     1075        rc = E_OUTOFMEMORY;
     1076    }
    10621077    return rc;
    10631078#endif
     
    10731088    HRESULT rc = S_OK;
    10741089
    1075     AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    1076 
    1077     GuestProcessIterConst it;
    1078     for (it = mGuestProcessList.begin(); it != mGuestProcessList.end(); it++)
    1079     {
    1080         if (it->mPID == aPID)
    1081             break;
    1082     }
    1083 
    1084     if (it != mGuestProcessList.end())
    1085     {
    1086         *aExitCode = it->mExitCode;
    1087         *aFlags = it->mFlags;
    1088         *aStatus = it->mStatus;
    1089     }
    1090     else
    1091         rc = setError(VBOX_E_IPRT_ERROR,
    1092                       tr("Process (PID %u) not found!"), aPID);
     1090    try
     1091    {
     1092        AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
     1093   
     1094        GuestProcessIterConst it;
     1095        for (it = mGuestProcessList.begin(); it != mGuestProcessList.end(); it++)
     1096        {
     1097            if (it->mPID == aPID)
     1098                break;
     1099        }
     1100   
     1101        if (it != mGuestProcessList.end())
     1102        {
     1103            *aExitCode = it->mExitCode;
     1104            *aFlags = it->mFlags;
     1105            *aStatus = it->mStatus;
     1106        }
     1107        else
     1108            rc = setError(VBOX_E_IPRT_ERROR,
     1109                          tr("Process (PID %u) not found!"), aPID);
     1110    }
     1111    catch (std::bad_alloc &)
     1112    {
     1113        rc = E_OUTOFMEMORY;
     1114    }
    10931115    return rc;
    10941116#endif
Note: See TracChangeset for help on using the changeset viewer.

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