VirtualBox

Changeset 42897 in vbox for trunk/src/VBox/Main


Ignore:
Timestamp:
Aug 21, 2012 10:03:52 AM (12 years ago)
Author:
vboxsync
Message:

Guest Control 2.0: Bugfixes.

Location:
trunk/src/VBox/Main
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Main/include/GuestCtrlImplPrivate.h

    r42693 r42897  
    3737#endif
    3838
    39 #ifdef LOG_GROUP
    40  #undef LOG_GROUP
    41 #endif
    42 #define LOG_GROUP LOG_GROUP_GUEST_CONTROL
    43 #include <VBox/log.h>
    44 
    4539/** Maximum number of guest sessions a VM can have. */
    4640#define VBOX_GUESTCTRL_MAX_SESSIONS     255
    47 /** Maximum of guest processes a guest session can have. */
    48 #define VBOX_GUESTCTRL_MAX_PROCESSES    255
     41/** Maximum number of guest objects (processes, files, ...)
     42 *  a guest session can have. */
     43#define VBOX_GUESTCTRL_MAX_OBJECTS      255
    4944/** Maximum of callback contexts a guest process can have. */
    5045#define VBOX_GUESTCTRL_MAX_CONTEXTS     _64K - 1
    5146
    52 /** Builds a context ID out of the session ID, process ID and an
     47/** Builds a context ID out of the session ID, object ID and an
    5348 *  increasing count. */
    54 #define VBOX_GUESTCTRL_CONTEXTID_MAKE(uSession, uProcess, uCount) \
     49#define VBOX_GUESTCTRL_CONTEXTID_MAKE(uSession, uObject, uCount) \
    5550    (  (uint32_t)((uSession) &   0xff) << 24 \
    56      | (uint32_t)((uProcess) &   0xff) << 16 \
     51     | (uint32_t)((uObject) &   0xff) << 16 \
    5752     | (uint32_t)((uCount)   & 0xffff)       \
    5853    )
     
    6156    ((uContextID) >> 24)
    6257/** Gets the process ID out of a context ID. */
    63 #define VBOX_GUESTCTRL_CONTEXTID_GET_PROCESS(uContextID) \
     58#define VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(uContextID) \
    6459    (((uContextID) >> 16) & 0xff)
    6560/** Gets the conext count of a process out of a context ID. */
  • trunk/src/VBox/Main/include/GuestDirectoryImpl.h

    r42673 r42897  
    7373    struct Data
    7474    {
    75         GuestSession              *mParent;
     75        GuestSession              *mSession;
    7676        Utf8Str                    mName;
    7777        Utf8Str                    mFilter;
     
    8383        /** The guest process which is responsible for
    8484         *  getting the stdout stream. */
    85         ComObjPtr<GuestProcess>    mProcess;
     85        GuestProcess              *mProcess;
    8686    } mData;
    8787};
  • trunk/src/VBox/Main/include/GuestFileImpl.h

    r42818 r42897  
    8383    {
    8484        /** The associate session this file belongs to. */
    85         ComObjPtr<GuestSession> mSession;
    86         /** The process object this file is bound to. */
    87         ComObjPtr<GuestProcess> mProcess;
     85        GuestSession           *mSession;
    8886        uint32_t                mCreationMode;
    8987        uint32_t                mDisposition;
  • trunk/src/VBox/Main/include/GuestImpl.h

    r42864 r42897  
    139139    uint32_t    getAdditionsVersion(void) { return mData.mAdditionsVersionFull; }
    140140    Console    *getConsole(void) { return mParent; }
    141     int         sessionClose(ComObjPtr<GuestSession> pSession);
     141    int         sessionRemove(GuestSession *pSession);
    142142    int         sessionCreate(const Utf8Str &strUser, const Utf8Str &strPassword, const Utf8Str &strDomain,
    143143                              const Utf8Str &strSessionName, ComObjPtr<GuestSession> &pGuestSession);
  • trunk/src/VBox/Main/include/GuestProcessImpl.h

    r42818 r42897  
    7575    inline bool callbackExists(uint32_t uContextID);
    7676    inline int checkPID(uint32_t uPID);
    77     void close(void);
    7877    Utf8Str errorMsg(void) { return mData.mErrorMsg; }
    7978    bool isReady(void);
    80     ULONG getPID(void) { return mData.mPID; }
    8179    ULONG getProcessID(void) { return mData.mProcessID; }
    8280    int rc(void) { return mData.mRC; }
     
    113111    struct Data
    114112    {
    115         /** Pointer to parent session. */
     113        /** Pointer to parent session. Per definition
     114         *  this objects *always* lives shorter than the
     115         *  parent. */
    116116        GuestSession            *mParent;
    117117        /** Pointer to the console object. Needed
  • trunk/src/VBox/Main/src-client/GuestCtrlImpl.cpp

    r42864 r42897  
    4141
    4242#include <memory>
     43
     44#ifdef LOG_GROUP
     45 #undef LOG_GROUP
     46#endif
     47#define LOG_GROUP LOG_GROUP_GUEST_CONTROL
     48#include <VBox/log.h>
     49
    4350
    4451// public methods only for internal purposes
     
    8491
    8592#ifdef DEBUG
    86     LogFlowFunc(("CID=%RU32, uSession=%RU32, uProcess=%RU32, uCount=%RU32\n",
     93    LogFlowFunc(("CID=%RU32, uSession=%RU32, uObject=%RU32, uCount=%RU32\n",
    8794                 pHeader->u32ContextID,
    8895                 VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(pHeader->u32ContextID),
    89                  VBOX_GUESTCTRL_CONTEXTID_GET_PROCESS(pHeader->u32ContextID),
     96                 VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pHeader->u32ContextID),
    9097                 VBOX_GUESTCTRL_CONTEXTID_GET_COUNT(pHeader->u32ContextID)));
    9198#endif
     
    240247}
    241248
    242 int Guest::sessionClose(ComObjPtr<GuestSession> pSession)
    243 {
     249int Guest::sessionRemove(GuestSession *pSession)
     250{
     251    LogFlowThisFuncEnter();
     252
    244253    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     254
     255    int rc = VERR_NOT_FOUND;
     256
     257    LogFlowFunc(("Closing session (ID=%RU32) ...\n", pSession->getId()));
    245258
    246259    for (GuestSessions::iterator itSessions = mData.mGuestSessions.begin();
     
    249262        if (pSession == itSessions->second)
    250263        {
     264            LogFlowFunc(("Removing session (pSession=%p, ID=%RU32) (now total %ld sessions)\n",
     265                         itSessions->second, itSessions->second->getId(), mData.mGuestSessions.size() - 1));
     266
    251267            mData.mGuestSessions.erase(itSessions);
    252             return VINF_SUCCESS;
    253         }
    254     }
    255 
    256     return VERR_NOT_FOUND;
     268
     269            rc = VINF_SUCCESS;
     270            break;
     271        }
     272    }
     273
     274    LogFlowFuncLeaveRC(rc);
     275    return rc;
    257276}
    258277
     
    299318        mData.mGuestSessions[uNewSessionID] = pGuestSession;
    300319
    301         LogFlowFunc(("Added new session with session ID=%RU32 (now %ld sessions total)\n",
    302                      uNewSessionID, mData.mGuestSessions.size()));
     320        LogFlowFunc(("Added new session (pSession=%p, ID=%RU32), now %ld sessions total\n",
     321                     pGuestSession, uNewSessionID, mData.mGuestSessions.size()));
    303322    }
    304323    catch (int rc2)
  • trunk/src/VBox/Main/src-client/GuestCtrlPrivate.cpp

    r42716 r42897  
    2727# include <iprt/file.h>
    2828#endif /* DEBUG */
     29
     30#ifdef LOG_GROUP
     31 #undef LOG_GROUP
     32#endif
     33#define LOG_GROUP LOG_GROUP_GUEST_CONTROL
     34#include <VBox/log.h>
    2935
    3036/******************************************************************************
  • trunk/src/VBox/Main/src-client/GuestDirectoryImpl.cpp

    r42846 r42897  
    3030#include <VBox/com/array.h>
    3131
     32#ifdef LOG_GROUP
     33 #undef LOG_GROUP
     34#endif
     35#define LOG_GROUP LOG_GROUP_GUEST_CONTROL
     36#include <VBox/log.h>
     37
    3238
    3339// constructor / destructor
     
    6369    AssertReturn(autoInitSpan.isOk(), E_FAIL);
    6470
    65     mData.mParent = aSession;
    66     mData.mName   = strPath;
    67     mData.mFilter = strFilter;
    68     mData.mFlags  = uFlags;
     71    mData.mSession = aSession;
     72    mData.mName    = strPath;
     73    mData.mFilter  = strFilter;
     74    mData.mFlags   = uFlags;
    6975
    7076    /* Start the directory process on the guest. */
     
    8995     * it later in subsequent read() calls.
    9096     */
    91     int rc = mData.mParent->processCreateExInteral(procInfo, mData.mProcess);
     97    ComObjPtr<GuestProcess> pProcess;
     98    int rc = mData.mSession->processCreateExInteral(procInfo, pProcess);
    9299    if (RT_SUCCESS(rc))
    93         rc = mData.mProcess->startProcessAsync();
     100        rc = pProcess->startProcessAsync();
    94101
    95102    LogFlowThisFunc(("rc=%Rrc\n", rc));
     
    97104    if (RT_SUCCESS(rc))
    98105    {
     106        mData.mProcess = pProcess;
     107
    99108        /* Confirm a successful initialization when it's the case. */
    100109        autoInitSpan.setSucceeded();
     
    119128        return;
    120129
    121     if (!mData.mProcess.isNull())
    122         mData.mProcess->uninit();
     130    LogFlowThisFuncLeave();
    123131}
    124132
     
    181189}
    182190
    183 
    184191// implementation of public methods
    185192/////////////////////////////////////////////////////////////////////////////
     
    192199    LogFlowThisFuncEnter();
    193200
     201    AutoCaller autoCaller(this);
     202    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     203
     204    AssertPtr(mData.mSession);
     205    int rc = mData.mSession->directoryRemoveFromList(this);
     206    if (mData.mProcess)
     207    {
     208        int rc2 = mData.mSession->processRemoveFromList(mData.mProcess);
     209        if (RT_SUCCESS(rc))
     210            rc = rc2;
     211    }
     212
     213    /*
     214     * Release autocaller before calling uninit.
     215     */
     216    autoCaller.release();
     217
    194218    uninit();
    195219
    196     LogFlowThisFuncLeave();
     220    LogFlowFuncLeaveRC(rc);
    197221    return S_OK;
    198222#endif /* VBOX_WITH_GUEST_CONTROL */
  • trunk/src/VBox/Main/src-client/GuestFileImpl.cpp

    r42848 r42897  
    3030#include <VBox/com/array.h>
    3131
     32#ifdef LOG_GROUP
     33 #undef LOG_GROUP
     34#endif
     35#define LOG_GROUP LOG_GROUP_GUEST_CONTROL
     36#include <VBox/log.h>
     37
    3238
    3339// constructor / destructor
     
    3642DEFINE_EMPTY_CTOR_DTOR(GuestFile)
    3743
    38 HRESULT GuestFile::FinalConstruct()
     44HRESULT GuestFile::FinalConstruct(void)
    3945{
    4046    LogFlowThisFunc(("\n"));
     
    9096        return;
    9197
    92     mData.mSession->fileClose(this);
     98    LogFlowThisFuncLeave();
    9399}
    94100
     
    229235    LogFlowThisFuncEnter();
    230236
     237    AutoCaller autoCaller(this);
     238    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     239
     240    AssertPtr(mData.mSession);
     241    int rc = mData.mSession->fileRemoveFromList(this);
     242
     243    /*
     244     * Release autocaller before calling uninit.
     245     */
     246    autoCaller.release();
     247
    231248    uninit();
    232249
    233     LogFlowThisFuncLeave();
     250    LogFlowFuncLeaveRC(rc);
    234251    return S_OK;
    235252#endif /* VBOX_WITH_GUEST_CONTROL */
  • trunk/src/VBox/Main/src-client/GuestFsObjInfoImpl.cpp

    r42673 r42897  
    2929#include <VBox/com/array.h>
    3030
     31#ifdef LOG_GROUP
     32 #undef LOG_GROUP
     33#endif
     34#define LOG_GROUP LOG_GROUP_GUEST_CONTROL
     35#include <VBox/log.h>
     36
    3137
    3238// constructor / destructor
  • trunk/src/VBox/Main/src-client/GuestImpl.cpp

    r42867 r42897  
    139139
    140140#ifdef VBOX_WITH_GUEST_CONTROL
     141    LogFlowThisFunc(("Closing sessions (%RU64 total)\n",
     142                     mData.mGuestSessions.size()));
    141143    GuestSessions::iterator itSessions = mData.mGuestSessions.begin();
    142144    while (itSessions != mData.mGuestSessions.end())
    143145    {
    144         if (!itSessions->second.isNull())
    145             itSessions->second->uninit();
     146#ifdef DEBUG
     147        ULONG cRefs = itSessions->second->AddRef();
     148        LogFlowThisFunc(("pSession=%p, cRefs=%RU32\n", itSessions->second, cRefs > 0 ? cRefs - 1 : 0));
     149        itSessions->second->Release();
     150#endif
     151        itSessions->second->uninit();
    146152        itSessions++;
    147153    }
     
    158164
    159165    unconst(mParent) = NULL;
     166
     167    LogFlowFuncLeave();
    160168}
    161169
  • trunk/src/VBox/Main/src-client/GuestProcessImpl.cpp

    r42846 r42897  
    4545#include <VBox/com/array.h>
    4646
    47 
    48 struct GuestProcessTask
    49 {
     47#ifdef LOG_GROUP
     48 #undef LOG_GROUP
     49#endif
     50#define LOG_GROUP LOG_GROUP_GUEST_CONTROL
     51#include <VBox/log.h>
     52
     53
     54class GuestProcessTask
     55{
     56public:
     57
    5058    GuestProcessTask(GuestProcess *pProcess)
    5159        : mProcess(pProcess),
     
    5563
    5664    int rc(void) const { return mRC; }
    57     bool isOk(void) const { return RT_SUCCESS(rc()); }
     65    bool isOk(void) const { return RT_SUCCESS(mRC); }
     66    const ComObjPtr<GuestProcess> &Process(void) const { return mProcess; }
     67
     68protected:
    5869
    5970    const ComObjPtr<GuestProcess>    mProcess;
    60 
    61 private:
    6271    int                              mRC;
    6372};
    6473
    65 struct GuestProcessStartTask : public GuestProcessTask
    66 {
     74class GuestProcessStartTask : public GuestProcessTask
     75{
     76public:
     77
    6778    GuestProcessStartTask(GuestProcess *pProcess)
    6879        : GuestProcessTask(pProcess) { }
     
    133144void GuestProcess::uninit(void)
    134145{
    135     LogFlowThisFunc(("\n"));
     146    LogFlowThisFunc(("mCmd=%s, PID=%RU32\n",
     147                     mData.mProcess.mCommand.c_str(), mData.mPID));
    136148
    137149    /* Enclose the state transition Ready->InUninit->NotReady. */
     
    140152        return;
    141153
    142 #ifndef VBOX_WITH_GUEST_CONTROL
     154    int vrc = VINF_SUCCESS;
     155
     156#ifdef VBOX_WITH_GUEST_CONTROL
    143157    /*
    144158     * Cancel all callbacks + waiters.
     
    151165        AssertPtr(pCallback);
    152166        int rc2 = pCallback->Cancel();
    153         AssertRC(rc2);
     167        if (RT_SUCCESS(vrc))
     168            vrc = rc2;
    154169    }
    155170    mData.mCallbacks.clear();
     
    158173    {
    159174        int rc2 = mData.mWaitEvent->Cancel();
    160         AssertRC(rc2);
     175        if (RT_SUCCESS(vrc))
     176            vrc = rc2;
    161177    }
    162178
    163179    mData.mStatus = ProcessStatus_Down; /** @todo Correct? */
    164 
    165     /* Remove the reference from the session's process list. */
    166     AssertPtr(mData.mParent);
    167     mData.mParent->processClose(this);
    168180#endif
    169181
    170     LogFlowThisFuncLeave();
     182    LogFlowFuncLeaveRC(vrc);
    171183}
    172184
     
    531543
    532544    return VINF_SUCCESS;
    533 }
    534 
    535 /* Do not hold any locks here because the lock validator will be unhappy
    536  * when being in uninit(). */
    537 void GuestProcess::close(void)
    538 {
    539     LogFlowThisFuncEnter();
    540 
    541     uninit();
    542 
    543     LogFlowThisFuncLeave();
    544545}
    545546
     
    11661167    LogFlowThisFuncEnter();
    11671168
    1168     /* Asynchronously start the process on the guest by kicking off a
    1169      * worker thread. */
    1170     std::auto_ptr<GuestProcessStartTask> pTask(new GuestProcessStartTask(this));
    1171     AssertReturn(pTask->isOk(), pTask->rc());
    1172 
    1173     int vrc = RTThreadCreate(NULL, GuestProcess::startProcessThread,
    1174                             (void *)pTask.get(), 0,
    1175                             RTTHREADTYPE_MAIN_WORKER, 0,
    1176                             "gctlPrcStart");
    1177     if (RT_SUCCESS(vrc))
    1178     {
    1179         /* pTask is now owned by startProcessThread(), so release it. */
    1180         pTask.release();
     1169    int vrc;
     1170
     1171    try
     1172    {
     1173        /* Asynchronously start the process on the guest by kicking off a
     1174         * worker thread. */
     1175        std::auto_ptr<GuestProcessStartTask> pTask(new GuestProcessStartTask(this));
     1176        AssertReturn(pTask->isOk(), pTask->rc());
     1177
     1178        vrc = RTThreadCreate(NULL, GuestProcess::startProcessThread,
     1179                             (void *)pTask.get(), 0,
     1180                             RTTHREADTYPE_MAIN_WORKER, 0,
     1181                             "gctlPrcStart");
     1182        if (RT_SUCCESS(vrc))
     1183        {
     1184            /* pTask is now owned by startProcessThread(), so release it. */
     1185            pTask.release();
     1186        }
     1187    }
     1188    catch(std::bad_alloc &)
     1189    {
     1190        vrc = VERR_NO_MEMORY;
    11811191    }
    11821192
     
    11851195}
    11861196
     1197/* static */
    11871198DECLCALLBACK(int) GuestProcess::startProcessThread(RTTHREAD Thread, void *pvUser)
    11881199{
     
    11921203    AssertPtr(pTask.get());
    11931204
    1194     const ComObjPtr<GuestProcess> pProcess(pTask->mProcess);
     1205    const ComObjPtr<GuestProcess> pProcess(pTask->Process());
    11951206    Assert(!pProcess.isNull());
    11961207
     
    12741285                /* Filter out waits which are *not* supported using
    12751286                 * older guest control Guest Additions. */
    1276                 AssertPtr(mData.mParent);
    12771287                if (mData.mParent->getProtocolVersion() < 2)
    12781288                {
     
    13551365    int vrc = mData.mWaitEvent->Wait(uTimeoutMS);
    13561366    if (RT_SUCCESS(vrc))
     1367    {
    13571368        waitRes = mData.mWaitEvent->GetResult();
     1369    }
     1370    else if (vrc == VERR_TIMEOUT)
     1371    {
     1372        waitRes.mRC = VINF_SUCCESS;
     1373        waitRes.mResult = ProcessWaitResult_Timeout;
     1374
     1375        vrc = VINF_SUCCESS;
     1376    }
    13581377
    13591378    alock.acquire(); /* Get the lock again. */
     
    15701589    }
    15711590
     1591    AssertPtr(mData.mParent);
     1592    mData.mParent->processRemoveFromList(this);
     1593
     1594    /*
     1595     * Release autocaller before calling uninit.
     1596     */
     1597    autoCaller.release();
     1598
     1599    uninit();
     1600
    15721601    LogFlowFuncLeaveRC(vrc);
    15731602    return hr;
     
    16011630    else
    16021631    {
    1603         if (vrc == VERR_TIMEOUT)
    1604             hr = setError(VBOX_E_IPRT_ERROR,
    1605                           tr("Process \"%s\" (PID %RU32) did not respond within time (%RU32ms)"),
    1606                           mData.mProcess.mCommand.c_str(), mData.mPID, aTimeoutMS);
    1607         else
    1608             hr = setError(VBOX_E_IPRT_ERROR,
    1609                           tr("Waiting for process \"%s\" (PID %RU32) failed with vrc=%Rrc"),
    1610                           mData.mProcess.mCommand.c_str(), mData.mPID, vrc);
     1632        hr = setError(VBOX_E_IPRT_ERROR,
     1633                      tr("Waiting for process \"%s\" (PID %RU32) failed with vrc=%Rrc"),
     1634                      mData.mProcess.mCommand.c_str(), mData.mPID, vrc);
    16111635    }
    16121636    LogFlowFuncLeaveRC(vrc);
  • trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp

    r42846 r42897  
    3737#include <VBox/version.h>
    3838
    39 
    40 /*
    41  * If the following define is enabled the Guest Additions update code also
    42  * checks for locations which were not supposed to happen due to not resolving
    43  * environment variables in VBoxService toolbox arguments. So a file copied
    44  * to "%TEMP%\foo.exe" became "C:\Windows\EMPfoo.exe".
    45  */
    46 #define VBOX_SERVICE_ENVARG_BUG
     39#ifdef LOG_GROUP
     40 #undef LOG_GROUP
     41#endif
     42#define LOG_GROUP LOG_GROUP_GUEST_CONTROL
     43#include <VBox/log.h>
     44
    4745
    4846// constructor / destructor
     
    8785    mData.mCredentials.mDomain = aDomain;
    8886    mData.mName = aName;
     87    mData.mNumObjects = 0;
    8988
    9089    /* Confirm a successful initialization when it's the case. */
     
    108107        return;
    109108
    110 #ifdef VBOX_WITH_GUEST_CONTROL
     109    int rc = VINF_SUCCESS;
     110
     111#ifndef VBOX_WITH_GUEST_CONTROL
     112    LogFlowThisFunc(("Closing directories (%RU64 total)\n",
     113                     mData.mDirectories.size()));
    111114    for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
    112115         itDirs != mData.mDirectories.end(); ++itDirs)
    113116    {
     117#ifdef DEBUG
     118        ULONG cRefs = (*itDirs)->AddRef();
     119        LogFlowThisFunc(("pFile=%p, cRefs=%RU32\n", (*itDirs), cRefs));
     120        (*itDirs)->Release();
     121#endif
    114122        (*itDirs)->uninit();
    115         (*itDirs).setNull();
    116123    }
    117124    mData.mDirectories.clear();
    118125
     126    LogFlowThisFunc(("Closing files (%RU64 total)\n",
     127                     mData.mFiles.size()));
    119128    for (SessionFiles::iterator itFiles = mData.mFiles.begin();
    120129         itFiles != mData.mFiles.end(); ++itFiles)
    121130    {
     131#ifdef DEBUG
     132        ULONG cRefs = (*itFiles)->AddRef();
     133        LogFlowThisFunc(("pFile=%p, cRefs=%RU32\n", (*itFiles), cRefs));
     134        (*itFiles)->Release();
     135#endif
    122136        (*itFiles)->uninit();
    123         (*itFiles).setNull();
    124137    }
    125138    mData.mFiles.clear();
    126139
     140    LogFlowThisFunc(("Closing processes (%RU64 total)\n",
     141                     mData.mProcesses.size()));
    127142    for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
    128143         itProcs != mData.mProcesses.end(); ++itProcs)
    129144    {
    130         itProcs->second->close();
    131     }
    132 
    133     for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
    134          itProcs != mData.mProcesses.end(); ++itProcs)
    135     {
     145#ifdef DEBUG
     146        ULONG cRefs = itProcs->second->AddRef();
     147        LogFlowThisFunc(("pProcess=%p, cRefs=%RU32\n", itProcs->second, cRefs));
     148        itProcs->second->Release();
     149#endif
    136150        itProcs->second->uninit();
    137         itProcs->second.setNull();
    138151    }
    139152    mData.mProcesses.clear();
    140153
    141     mData.mParent->sessionClose(this);
    142 
    143     LogFlowThisFuncLeave();
     154    LogFlowThisFunc(("mNumObjects=%RU32\n", mData.mNumObjects));
    144155#endif
     156    LogFlowFuncLeaveRC(rc);
    145157}
    146158
     
    399411/////////////////////////////////////////////////////////////////////////////
    400412
    401 int GuestSession::directoryClose(ComObjPtr<GuestDirectory> pDirectory)
     413int GuestSession::directoryRemoveFromList(GuestDirectory *pDirectory)
    402414{
    403415    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    408420        if (pDirectory == (*itDirs))
    409421        {
     422            Bstr strName;
     423            HRESULT hr = (*itDirs)->COMGETTER(DirectoryName)(strName.asOutParam());
     424            ComAssertComRC(hr);
     425
     426            Assert(mData.mDirectories.size());
     427            LogFlowFunc(("Removing directory \"%s\" (Session: %RU32) (now total %ld directories)\n",
     428                         Utf8Str(strName).c_str(), mData.mNumObjects - 1));
     429
    410430            mData.mDirectories.erase(itDirs);
    411431            return VINF_SUCCESS;
     
    629649    AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
    630650
    631     uint32_t uProcessID = VBOX_GUESTCTRL_CONTEXTID_GET_PROCESS(uContextID);
     651    uint32_t uProcessID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(uContextID);
    632652#ifdef DEBUG
    633653    LogFlowFunc(("uProcessID=%RU32 (%RU32 total)\n",
     
    652672}
    653673
    654 int GuestSession::fileClose(ComObjPtr<GuestFile> pFile)
     674int GuestSession::fileRemoveFromList(GuestFile *pFile)
    655675{
    656676    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     
    661681        if (pFile == (*itFiles))
    662682        {
     683            Bstr strName;
     684            HRESULT hr = (*itFiles)->COMGETTER(FileName)(strName.asOutParam());
     685            ComAssertComRC(hr);
     686
     687            Assert(mData.mNumObjects);
     688            LogFlowThisFunc(("Removing file \"%s\" (Session: %RU32) (now total %ld files, %ld objects)\n",
     689                             Utf8Str(strName).c_str(), mData.mId, mData.mFiles.size() - 1, mData.mNumObjects - 1));
     690#ifdef DEBUG
     691            ULONG cRefs = pFile->AddRef();
     692            LogFlowThisFunc(("pObject=%p, cRefs=%RU32\n", pFile, cRefs));
     693            pFile->Release();
     694#endif
    663695            mData.mFiles.erase(itFiles);
     696            mData.mNumObjects--;
    664697            return VINF_SUCCESS;
    665698        }
     
    772805    /* Add the created directory to our vector. */
    773806    mData.mFiles.push_back(pFile);
    774 
    775     LogFlowFunc(("Added new file \"%s\" (Session: %RU32\n",
    776                  strPath.c_str(), mData.mId));
     807    mData.mNumObjects++;
     808    Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
     809
     810    LogFlowFunc(("Added new file \"%s\" (Session: %RU32) (now total %ld files, %ld objects)\n",
     811                 strPath.c_str(), mData.mId, mData.mProcesses.size(), mData.mNumObjects));
    777812
    778813    LogFlowFuncLeaveRC(rc);
     
    900935}
    901936
    902 int GuestSession::processClose(ComObjPtr<GuestProcess> pProcess)
    903 {
     937int GuestSession::processRemoveFromList(GuestProcess *pProcess)
     938{
     939    LogFlowThisFuncEnter();
     940
    904941    AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
     942
     943    int rc = VERR_NOT_FOUND;
     944
     945    ULONG uPID;
     946    HRESULT hr = pProcess->COMGETTER(PID)(&uPID);
     947
     948    LogFlowFunc(("Closing process (PID=%RU32) ...\n", uPID));
    905949
    906950    for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
     
    909953        if (pProcess == itProcs->second)
    910954        {
    911             LogFlowFunc(("Removing process (Session: %RU32) with process ID=%RU32, guest PID=%RU32 (now total %ld processes)\n",
    912                          mData.mId, itProcs->second->getProcessID(), itProcs->second->getPID(), mData.mProcesses.size() - 1));
     955            GuestProcess *pCurProc = itProcs->second;
     956            AssertPtr(pCurProc);
     957
     958            hr = pCurProc->COMGETTER(PID)(&uPID);
     959            ComAssertComRC(hr);
     960
     961            Assert(mData.mNumObjects);
     962            LogFlowFunc(("Removing process (Session: %RU32) with process ID=%RU32, guest PID=%RU32 (now total %ld processes, %ld objects)\n",
     963                         mData.mId, pCurProc->getProcessID(), uPID, mData.mProcesses.size() - 1, mData.mNumObjects - 1));
    913964
    914965            mData.mProcesses.erase(itProcs);
    915             return VINF_SUCCESS;
    916         }
    917     }
    918 
    919     return VERR_NOT_FOUND;
     966            mData.mNumObjects--;
     967
     968            rc = VINF_SUCCESS;
     969            break;
     970        }
     971    }
     972
     973    LogFlowFuncLeaveRC(rc);
     974    return rc;
    920975}
    921976
     
    9701025
    9711026    int rc = VERR_MAX_PROCS_REACHED;
    972     if (mData.mProcesses.size() >= VBOX_GUESTCTRL_MAX_PROCESSES)
     1027    if (mData.mNumObjects >= VBOX_GUESTCTRL_MAX_OBJECTS)
    9731028        return rc;
    9741029
     
    9891044        }
    9901045        uNewProcessID++;
    991         if (uNewProcessID == VBOX_GUESTCTRL_MAX_PROCESSES)
     1046        if (uNewProcessID == VBOX_GUESTCTRL_MAX_OBJECTS)
    9921047            uNewProcessID = 0;
    9931048
     
    10111066    /* Add the created process to our map. */
    10121067    mData.mProcesses[uNewProcessID] = pProcess;
    1013 
    1014     LogFlowFunc(("Added new process (Session: %RU32) with process ID=%RU32 (now total %ld processes)\n",
    1015                  mData.mId, uNewProcessID, mData.mProcesses.size()));
     1068    mData.mNumObjects++;
     1069    Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
     1070
     1071    LogFlowFunc(("Added new process (Session: %RU32) with process ID=%RU32 (now total %ld processes, %ld objects)\n",
     1072                 mData.mId, uNewProcessID, mData.mProcesses.size(), mData.mNumObjects));
    10161073
    10171074    return rc;
     
    10351092    /* pProcess is optional. */
    10361093
    1037     SessionProcesses::iterator it = mData.mProcesses.begin();
    1038     for (; it != mData.mProcesses.end(); it++)
    1039     {
    1040         ComObjPtr<GuestProcess> pCurProc = it->second;
     1094    SessionProcesses::iterator itProcs = mData.mProcesses.begin();
     1095    for (; itProcs != mData.mProcesses.end(); itProcs++)
     1096    {
     1097        ComObjPtr<GuestProcess> pCurProc = itProcs->second;
    10411098        AutoCaller procCaller(pCurProc);
    10421099        if (procCaller.rc())
    10431100            return VERR_COM_INVALID_OBJECT_STATE;
    10441101
    1045         if (it->second->getPID() == uPID)
     1102        ULONG uCurPID;
     1103        HRESULT hr = pCurProc->COMGETTER(PID)(&uCurPID);
     1104        ComAssertComRC(hr);
     1105
     1106        if (uCurPID == uPID)
    10461107        {
    10471108            if (pProcess)
     
    11321193    LogFlowThisFuncEnter();
    11331194
     1195    AutoCaller autoCaller(this);
     1196    if (FAILED(autoCaller.rc())) return autoCaller.rc();
     1197
     1198    /* Remove ourselves from the session list. */
     1199    mData.mParent->sessionRemove(this);
     1200
     1201    /*
     1202     * Release autocaller before calling uninit.
     1203     */
     1204    autoCaller.release();
     1205
    11341206    uninit();
    11351207
    1136     LogFlowFuncLeaveRC(S_OK);
     1208    LogFlowFuncLeave();
    11371209    return S_OK;
    11381210#endif /* VBOX_WITH_GUEST_CONTROL */
     
    13511423
    13521424    GuestFsObjData objData;
    1353     int rc = fileQueryInfoInternal(Utf8Str(aPath), objData);
     1425    int rc = directoryQueryInfoInternal(Utf8Str(aPath), objData);
    13541426    if (RT_SUCCESS(rc))
    13551427    {
     
    14131485        else
    14141486        {
    1415             rc = directoryClose(pDirectory);
     1487            rc = directoryRemoveFromList(pDirectory);
    14161488            if (RT_FAILURE(rc))
    14171489                hr = setError(VBOX_E_IPRT_ERROR, tr("Unable to close directory object, rc=%Rrc"), rc);
     
    19872059        {
    19882060            case VERR_MAX_PROCS_REACHED:
    1989                 hr = setError(VBOX_E_IPRT_ERROR, tr("Maximum number of guest processes per session (%ld) reached"),
    1990                               VBOX_GUESTCTRL_MAX_PROCESSES);
     2061                hr = setError(VBOX_E_IPRT_ERROR, tr("Maximum number of guest objects per session (%ld) reached"),
     2062                                                    VBOX_GUESTCTRL_MAX_OBJECTS);
    19912063                break;
    19922064
  • trunk/src/VBox/Main/src-client/GuestSessionImplTasks.cpp

    r42810 r42897  
    3333#include <iprt/env.h>
    3434#include <iprt/file.h> /* For CopyTo/From. */
     35
     36#ifdef LOG_GROUP
     37 #undef LOG_GROUP
     38#endif
     39#define LOG_GROUP LOG_GROUP_GUEST_CONTROL
     40#include <VBox/log.h>
    3541
    3642
     
    400406        }
    401407
    402         pProcess->close();
     408        if (!pProcess.isNull())
     409            pProcess->uninit();
    403410    } /* processCreateExInteral */
    404411
     
    632639                }
    633640
    634                 pProcess->close();
     641                if (!pProcess.isNull())
     642                    pProcess->uninit();
    635643            }
    636644
     
    844852
    845853    if (!pProcess.isNull())
    846         pProcess->close();
     854        pProcess->uninit();
    847855
    848856    return rc;
  • trunk/src/VBox/Main/testcase/tstGuestCtrlContextID.cpp

    r42215 r42897  
    5959    {
    6060        uint32_t s = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_SESSIONS);
    61         uint32_t p = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_PROCESSES);
     61        uint32_t p = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_OBJECTS);
    6262        uint32_t c = RTRandU32Ex(0, VBOX_GUESTCTRL_MAX_CONTEXTS);
    6363
     
    6969                         s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_SESSION(uContextID), s, uContextID);
    7070        }
    71         else if (p != VBOX_GUESTCTRL_CONTEXTID_GET_PROCESS(uContextID))
     71        else if (p != VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(uContextID))
    7272        {
    73             RTTestFailed(hTest, "%d,%d,%d: Process is %d, expected %d -> %RU64\n",
    74                          s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_PROCESS(uContextID), p, uContextID);
     73            RTTestFailed(hTest, "%d,%d,%d: Object is %d, expected %d -> %RU64\n",
     74                         s, p, c, VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(uContextID), p, uContextID);
    7575        }
    7676        if (c != VBOX_GUESTCTRL_CONTEXTID_GET_COUNT(uContextID))
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