[42084] | 1 | /* $Id: GuestSessionImpl.cpp 69500 2017-10-28 15:14:05Z vboxsync $ */
|
---|
| 2 | /** @file
|
---|
[44863] | 3 | * VirtualBox Main - Guest session handling.
|
---|
[42084] | 4 | */
|
---|
| 5 |
|
---|
| 6 | /*
|
---|
[69500] | 7 | * Copyright (C) 2012-2017 Oracle Corporation
|
---|
[42084] | 8 | *
|
---|
| 9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
| 12 | * General Public License (GPL) as published by the Free Software
|
---|
| 13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
| 16 | */
|
---|
| 17 |
|
---|
| 18 |
|
---|
[57358] | 19 | /*********************************************************************************************************************************
|
---|
| 20 | * Header Files *
|
---|
| 21 | *********************************************************************************************************************************/
|
---|
[67914] | 22 | #define LOG_GROUP LOG_GROUP_GUEST_CONTROL //LOG_GROUP_MAIN_GUESTSESSION
|
---|
| 23 | #include "LoggingNew.h"
|
---|
| 24 |
|
---|
[42105] | 25 | #include "GuestImpl.h"
|
---|
[55645] | 26 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 27 | # error "VBOX_WITH_GUEST_CONTROL must defined in this file"
|
---|
| 28 | #endif
|
---|
[42084] | 29 | #include "GuestSessionImpl.h"
|
---|
[42478] | 30 | #include "GuestCtrlImplPrivate.h"
|
---|
[45805] | 31 | #include "VirtualBoxErrorInfoImpl.h"
|
---|
[42084] | 32 |
|
---|
| 33 | #include "Global.h"
|
---|
| 34 | #include "AutoCaller.h"
|
---|
[42566] | 35 | #include "ProgressImpl.h"
|
---|
[45415] | 36 | #include "VBoxEvents.h"
|
---|
[44863] | 37 | #include "VMMDev.h"
|
---|
[58521] | 38 | #include "ThreadTask.h"
|
---|
[42084] | 39 |
|
---|
[42567] | 40 | #include <memory> /* For auto_ptr. */
|
---|
| 41 |
|
---|
[45415] | 42 | #include <iprt/cpp/utils.h> /* For unconst(). */
|
---|
[42171] | 43 | #include <iprt/env.h>
|
---|
[42573] | 44 | #include <iprt/file.h> /* For CopyTo/From. */
|
---|
[42171] | 45 |
|
---|
[42084] | 46 | #include <VBox/com/array.h>
|
---|
[45415] | 47 | #include <VBox/com/listeners.h>
|
---|
[42461] | 48 | #include <VBox/version.h>
|
---|
[42084] | 49 |
|
---|
| 50 |
|
---|
[44935] | 51 | /**
|
---|
| 52 | * Base class representing an internal
|
---|
| 53 | * asynchronous session task.
|
---|
| 54 | */
|
---|
[58521] | 55 | class GuestSessionTaskInternal : public ThreadTask
|
---|
[44935] | 56 | {
|
---|
| 57 | public:
|
---|
| 58 |
|
---|
| 59 | GuestSessionTaskInternal(GuestSession *pSession)
|
---|
[58521] | 60 | : ThreadTask("GenericGuestSessionTaskInternal")
|
---|
| 61 | , mSession(pSession)
|
---|
| 62 | , mRC(VINF_SUCCESS) { }
|
---|
[44935] | 63 |
|
---|
| 64 | virtual ~GuestSessionTaskInternal(void) { }
|
---|
| 65 |
|
---|
| 66 | int rc(void) const { return mRC; }
|
---|
| 67 | bool isOk(void) const { return RT_SUCCESS(mRC); }
|
---|
| 68 | const ComObjPtr<GuestSession> &Session(void) const { return mSession; }
|
---|
| 69 |
|
---|
| 70 | protected:
|
---|
| 71 |
|
---|
| 72 | const ComObjPtr<GuestSession> mSession;
|
---|
| 73 | int mRC;
|
---|
| 74 | };
|
---|
| 75 |
|
---|
| 76 | /**
|
---|
| 77 | * Class for asynchronously opening a guest session.
|
---|
| 78 | */
|
---|
| 79 | class GuestSessionTaskInternalOpen : public GuestSessionTaskInternal
|
---|
| 80 | {
|
---|
| 81 | public:
|
---|
| 82 |
|
---|
| 83 | GuestSessionTaskInternalOpen(GuestSession *pSession)
|
---|
[58521] | 84 | : GuestSessionTaskInternal(pSession)
|
---|
| 85 | {
|
---|
| 86 | m_strTaskName = "gctlSesStart";
|
---|
| 87 | }
|
---|
| 88 |
|
---|
| 89 | void handler()
|
---|
| 90 | {
|
---|
[63186] | 91 | GuestSession::i_startSessionThreadTask(this);
|
---|
[58521] | 92 | }
|
---|
[44935] | 93 | };
|
---|
| 94 |
|
---|
[45780] | 95 | /**
|
---|
| 96 | * Internal listener class to serve events in an
|
---|
| 97 | * active manner, e.g. without polling delays.
|
---|
| 98 | */
|
---|
| 99 | class GuestSessionListener
|
---|
| 100 | {
|
---|
| 101 | public:
|
---|
| 102 |
|
---|
| 103 | GuestSessionListener(void)
|
---|
| 104 | {
|
---|
| 105 | }
|
---|
| 106 |
|
---|
[62157] | 107 | virtual ~GuestSessionListener(void)
|
---|
| 108 | {
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[45780] | 111 | HRESULT init(GuestSession *pSession)
|
---|
| 112 | {
|
---|
[49610] | 113 | AssertPtrReturn(pSession, E_POINTER);
|
---|
[45780] | 114 | mSession = pSession;
|
---|
| 115 | return S_OK;
|
---|
| 116 | }
|
---|
| 117 |
|
---|
| 118 | void uninit(void)
|
---|
| 119 | {
|
---|
[49610] | 120 | mSession = NULL;
|
---|
[45780] | 121 | }
|
---|
| 122 |
|
---|
| 123 | STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent *aEvent)
|
---|
| 124 | {
|
---|
| 125 | switch (aType)
|
---|
| 126 | {
|
---|
| 127 | case VBoxEventType_OnGuestSessionStateChanged:
|
---|
| 128 | {
|
---|
[49610] | 129 | AssertPtrReturn(mSession, E_POINTER);
|
---|
[49349] | 130 | int rc2 = mSession->signalWaitEvent(aType, aEvent);
|
---|
[63249] | 131 | RT_NOREF(rc2);
|
---|
[45780] | 132 | #ifdef DEBUG_andy
|
---|
[49504] | 133 | LogFlowFunc(("Signalling events of type=%RU32, session=%p resulted in rc=%Rrc\n",
|
---|
[45780] | 134 | aType, mSession, rc2));
|
---|
| 135 | #endif
|
---|
| 136 | break;
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | default:
|
---|
[49504] | 140 | AssertMsgFailed(("Unhandled event %RU32\n", aType));
|
---|
[45780] | 141 | break;
|
---|
| 142 | }
|
---|
| 143 |
|
---|
| 144 | return S_OK;
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | private:
|
---|
| 148 |
|
---|
[49610] | 149 | GuestSession *mSession;
|
---|
[45780] | 150 | };
|
---|
| 151 | typedef ListenerImpl<GuestSessionListener, GuestSession*> GuestSessionListenerImpl;
|
---|
| 152 |
|
---|
[45782] | 153 | VBOX_LISTENER_DECLARE(GuestSessionListenerImpl)
|
---|
[45780] | 154 |
|
---|
[42084] | 155 | // constructor / destructor
|
---|
| 156 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 157 |
|
---|
| 158 | DEFINE_EMPTY_CTOR_DTOR(GuestSession)
|
---|
| 159 |
|
---|
| 160 | HRESULT GuestSession::FinalConstruct(void)
|
---|
| 161 | {
|
---|
[49389] | 162 | LogFlowThisFuncEnter();
|
---|
[42084] | 163 | return BaseFinalConstruct();
|
---|
| 164 | }
|
---|
| 165 |
|
---|
| 166 | void GuestSession::FinalRelease(void)
|
---|
| 167 | {
|
---|
| 168 | LogFlowThisFuncEnter();
|
---|
| 169 | uninit();
|
---|
| 170 | BaseFinalRelease();
|
---|
| 171 | LogFlowThisFuncLeave();
|
---|
| 172 | }
|
---|
| 173 |
|
---|
| 174 | // public initializer/uninitializer for internal purposes only
|
---|
| 175 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 176 |
|
---|
[44863] | 177 | /**
|
---|
| 178 | * Initializes a guest session but does *not* open in on the guest side
|
---|
[44935] | 179 | * yet. This needs to be done via the openSession() / openSessionAsync calls.
|
---|
[44863] | 180 | *
|
---|
| 181 | * @return IPRT status code.
|
---|
[44935] | 182 | ** @todo Docs!
|
---|
[44863] | 183 | */
|
---|
[44935] | 184 | int GuestSession::init(Guest *pGuest, const GuestSessionStartupInfo &ssInfo,
|
---|
| 185 | const GuestCredentials &guestCreds)
|
---|
[42084] | 186 | {
|
---|
[44935] | 187 | LogFlowThisFunc(("pGuest=%p, ssInfo=%p, guestCreds=%p\n",
|
---|
| 188 | pGuest, &ssInfo, &guestCreds));
|
---|
[42194] | 189 |
|
---|
[42084] | 190 | /* Enclose the state transition NotReady->InInit->Ready. */
|
---|
| 191 | AutoInitSpan autoInitSpan(this);
|
---|
[42105] | 192 | AssertReturn(autoInitSpan.isOk(), VERR_OBJECT_DESTROYED);
|
---|
[42084] | 193 |
|
---|
[45426] | 194 | AssertPtrReturn(pGuest, VERR_INVALID_POINTER);
|
---|
| 195 |
|
---|
[55588] | 196 | /*
|
---|
| 197 | * Initialize our data members from the input.
|
---|
| 198 | */
|
---|
[45415] | 199 | mParent = pGuest;
|
---|
[42084] | 200 |
|
---|
[44935] | 201 | /* Copy over startup info. */
|
---|
| 202 | /** @todo Use an overloaded copy operator. Later. */
|
---|
| 203 | mData.mSession.mID = ssInfo.mID;
|
---|
| 204 | mData.mSession.mIsInternal = ssInfo.mIsInternal;
|
---|
| 205 | mData.mSession.mName = ssInfo.mName;
|
---|
| 206 | mData.mSession.mOpenFlags = ssInfo.mOpenFlags;
|
---|
| 207 | mData.mSession.mOpenTimeoutMS = ssInfo.mOpenTimeoutMS;
|
---|
| 208 |
|
---|
| 209 | /** @todo Use an overloaded copy operator. Later. */
|
---|
| 210 | mData.mCredentials.mUser = guestCreds.mUser;
|
---|
| 211 | mData.mCredentials.mPassword = guestCreds.mPassword;
|
---|
| 212 | mData.mCredentials.mDomain = guestCreds.mDomain;
|
---|
| 213 |
|
---|
[55588] | 214 | /* Initialize the remainder of the data. */
|
---|
[45426] | 215 | mData.mRC = VINF_SUCCESS;
|
---|
[44935] | 216 | mData.mStatus = GuestSessionStatus_Undefined;
|
---|
[42897] | 217 | mData.mNumObjects = 0;
|
---|
[55591] | 218 | mData.mpBaseEnvironment = NULL;
|
---|
| 219 | int rc = mData.mEnvironmentChanges.initChangeRecord();
|
---|
[44935] | 220 | if (RT_SUCCESS(rc))
|
---|
| 221 | {
|
---|
[55588] | 222 | rc = RTCritSectInit(&mWaitEventCritSect);
|
---|
| 223 | AssertRC(rc);
|
---|
[45415] | 224 | }
|
---|
| 225 | if (RT_SUCCESS(rc))
|
---|
[55588] | 226 | rc = i_determineProtocolVersion();
|
---|
| 227 | if (RT_SUCCESS(rc))
|
---|
[45415] | 228 | {
|
---|
[55588] | 229 | /*
|
---|
| 230 | * <Replace this if you figure out what the code is doing.>
|
---|
| 231 | */
|
---|
| 232 | HRESULT hr = unconst(mEventSource).createObject();
|
---|
| 233 | if (SUCCEEDED(hr))
|
---|
| 234 | hr = mEventSource->init();
|
---|
| 235 | if (SUCCEEDED(hr))
|
---|
[45780] | 236 | {
|
---|
[55588] | 237 | try
|
---|
[45780] | 238 | {
|
---|
[55588] | 239 | GuestSessionListener *pListener = new GuestSessionListener();
|
---|
| 240 | ComObjPtr<GuestSessionListenerImpl> thisListener;
|
---|
| 241 | hr = thisListener.createObject();
|
---|
[45780] | 242 | if (SUCCEEDED(hr))
|
---|
[55588] | 243 | hr = thisListener->init(pListener, this);
|
---|
| 244 | if (SUCCEEDED(hr))
|
---|
[45780] | 245 | {
|
---|
[55588] | 246 | com::SafeArray <VBoxEventType_T> eventTypes;
|
---|
| 247 | eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
|
---|
| 248 | hr = mEventSource->RegisterListener(thisListener,
|
---|
| 249 | ComSafeArrayAsInParam(eventTypes),
|
---|
| 250 | TRUE /* Active listener */);
|
---|
| 251 | if (SUCCEEDED(hr))
|
---|
| 252 | {
|
---|
| 253 | mLocalListener = thisListener;
|
---|
[47469] | 254 |
|
---|
[55588] | 255 | /*
|
---|
| 256 | * Mark this object as operational and return success.
|
---|
| 257 | */
|
---|
| 258 | autoInitSpan.setSucceeded();
|
---|
| 259 | LogFlowThisFunc(("mName=%s mID=%RU32 mIsInternal=%RTbool rc=VINF_SUCCESS\n",
|
---|
| 260 | mData.mSession.mName.c_str(), mData.mSession.mID, mData.mSession.mIsInternal));
|
---|
| 261 | return VINF_SUCCESS;
|
---|
| 262 | }
|
---|
[45780] | 263 | }
|
---|
| 264 | }
|
---|
[55588] | 265 | catch (std::bad_alloc &)
|
---|
| 266 | {
|
---|
| 267 | hr = E_OUTOFMEMORY;
|
---|
| 268 | }
|
---|
[45780] | 269 | }
|
---|
[55588] | 270 | rc = Global::vboxStatusCodeFromCOM(hr);
|
---|
[45780] | 271 | }
|
---|
| 272 |
|
---|
[55588] | 273 | autoInitSpan.setFailed();
|
---|
| 274 | LogThisFunc(("Failed! mName=%s mID=%RU32 mIsInternal=%RTbool => rc=%Rrc\n",
|
---|
| 275 | mData.mSession.mName.c_str(), mData.mSession.mID, mData.mSession.mIsInternal, rc));
|
---|
[44935] | 276 | return rc;
|
---|
[42084] | 277 | }
|
---|
| 278 |
|
---|
| 279 | /**
|
---|
| 280 | * Uninitializes the instance.
|
---|
| 281 | * Called from FinalRelease().
|
---|
| 282 | */
|
---|
| 283 | void GuestSession::uninit(void)
|
---|
| 284 | {
|
---|
| 285 | /* Enclose the state transition Ready->InUninit->NotReady. */
|
---|
| 286 | AutoUninitSpan autoUninitSpan(this);
|
---|
| 287 | if (autoUninitSpan.uninitDone())
|
---|
| 288 | return;
|
---|
[42090] | 289 |
|
---|
[49504] | 290 | LogFlowThisFuncEnter();
|
---|
| 291 |
|
---|
[49570] | 292 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[49504] | 293 |
|
---|
| 294 | LogFlowThisFunc(("Closing directories (%zu total)\n",
|
---|
[42897] | 295 | mData.mDirectories.size()));
|
---|
[42105] | 296 | for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
|
---|
| 297 | itDirs != mData.mDirectories.end(); ++itDirs)
|
---|
[42090] | 298 | {
|
---|
[49504] | 299 | Assert(mData.mNumObjects);
|
---|
| 300 | mData.mNumObjects--;
|
---|
[50618] | 301 | itDirs->second->i_onRemove();
|
---|
[49504] | 302 | itDirs->second->uninit();
|
---|
[42090] | 303 | }
|
---|
[42105] | 304 | mData.mDirectories.clear();
|
---|
[42090] | 305 |
|
---|
[49504] | 306 | LogFlowThisFunc(("Closing files (%zu total)\n",
|
---|
[42897] | 307 | mData.mFiles.size()));
|
---|
[42105] | 308 | for (SessionFiles::iterator itFiles = mData.mFiles.begin();
|
---|
| 309 | itFiles != mData.mFiles.end(); ++itFiles)
|
---|
[42090] | 310 | {
|
---|
[49504] | 311 | Assert(mData.mNumObjects);
|
---|
| 312 | mData.mNumObjects--;
|
---|
[50618] | 313 | itFiles->second->i_onRemove();
|
---|
[49504] | 314 | itFiles->second->uninit();
|
---|
[42090] | 315 | }
|
---|
[42105] | 316 | mData.mFiles.clear();
|
---|
[42090] | 317 |
|
---|
[49504] | 318 | LogFlowThisFunc(("Closing processes (%zu total)\n",
|
---|
[42897] | 319 | mData.mProcesses.size()));
|
---|
[42105] | 320 | for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
|
---|
[42090] | 321 | itProcs != mData.mProcesses.end(); ++itProcs)
|
---|
| 322 | {
|
---|
[49504] | 323 | Assert(mData.mNumObjects);
|
---|
| 324 | mData.mNumObjects--;
|
---|
[50618] | 325 | itProcs->second->i_onRemove();
|
---|
[49504] | 326 | itProcs->second->uninit();
|
---|
[42090] | 327 | }
|
---|
[42105] | 328 | mData.mProcesses.clear();
|
---|
| 329 |
|
---|
[55591] | 330 | mData.mEnvironmentChanges.reset();
|
---|
[55588] | 331 |
|
---|
[55591] | 332 | if (mData.mpBaseEnvironment)
|
---|
| 333 | {
|
---|
[55592] | 334 | mData.mpBaseEnvironment->releaseConst();
|
---|
[55591] | 335 | mData.mpBaseEnvironment = NULL;
|
---|
| 336 | }
|
---|
| 337 |
|
---|
[49570] | 338 | AssertMsg(mData.mNumObjects == 0,
|
---|
[49504] | 339 | ("mNumObjects=%RU32 when it should be 0\n", mData.mNumObjects));
|
---|
[45415] | 340 |
|
---|
[47469] | 341 | baseUninit();
|
---|
[55645] | 342 |
|
---|
[62379] | 343 | LogFlowFuncLeave();
|
---|
[42084] | 344 | }
|
---|
| 345 |
|
---|
| 346 | // implementation of public getters/setters for attributes
|
---|
| 347 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 348 |
|
---|
[50727] | 349 | HRESULT GuestSession::getUser(com::Utf8Str &aUser)
|
---|
[42084] | 350 | {
|
---|
[42194] | 351 | LogFlowThisFuncEnter();
|
---|
| 352 |
|
---|
[42084] | 353 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 354 |
|
---|
[50727] | 355 | aUser = mData.mCredentials.mUser;
|
---|
[42084] | 356 |
|
---|
[47627] | 357 | LogFlowThisFuncLeave();
|
---|
[42084] | 358 | return S_OK;
|
---|
| 359 | }
|
---|
| 360 |
|
---|
[50727] | 361 | HRESULT GuestSession::getDomain(com::Utf8Str &aDomain)
|
---|
[42084] | 362 | {
|
---|
[42194] | 363 | LogFlowThisFuncEnter();
|
---|
| 364 |
|
---|
[42084] | 365 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 366 |
|
---|
[50727] | 367 | aDomain = mData.mCredentials.mDomain;
|
---|
[42084] | 368 |
|
---|
[47627] | 369 | LogFlowThisFuncLeave();
|
---|
[42084] | 370 | return S_OK;
|
---|
| 371 | }
|
---|
| 372 |
|
---|
[50727] | 373 | HRESULT GuestSession::getName(com::Utf8Str &aName)
|
---|
[42084] | 374 | {
|
---|
[42194] | 375 | LogFlowThisFuncEnter();
|
---|
| 376 |
|
---|
[42084] | 377 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 378 |
|
---|
[50727] | 379 | aName = mData.mSession.mName;
|
---|
[42084] | 380 |
|
---|
[47627] | 381 | LogFlowThisFuncLeave();
|
---|
[42084] | 382 | return S_OK;
|
---|
| 383 | }
|
---|
| 384 |
|
---|
[50727] | 385 | HRESULT GuestSession::getId(ULONG *aId)
|
---|
[42084] | 386 | {
|
---|
[42194] | 387 | LogFlowThisFuncEnter();
|
---|
| 388 |
|
---|
[42084] | 389 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 390 |
|
---|
[44935] | 391 | *aId = mData.mSession.mID;
|
---|
[42084] | 392 |
|
---|
[47627] | 393 | LogFlowThisFuncLeave();
|
---|
[42084] | 394 | return S_OK;
|
---|
| 395 | }
|
---|
| 396 |
|
---|
[50727] | 397 | HRESULT GuestSession::getStatus(GuestSessionStatus_T *aStatus)
|
---|
[44935] | 398 | {
|
---|
| 399 | LogFlowThisFuncEnter();
|
---|
| 400 |
|
---|
| 401 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 402 |
|
---|
| 403 | *aStatus = mData.mStatus;
|
---|
| 404 |
|
---|
[47627] | 405 | LogFlowThisFuncLeave();
|
---|
[44935] | 406 | return S_OK;
|
---|
| 407 | }
|
---|
| 408 |
|
---|
[50727] | 409 | HRESULT GuestSession::getTimeout(ULONG *aTimeout)
|
---|
[42084] | 410 | {
|
---|
[42194] | 411 | LogFlowThisFuncEnter();
|
---|
| 412 |
|
---|
[42084] | 413 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 414 |
|
---|
| 415 | *aTimeout = mData.mTimeout;
|
---|
| 416 |
|
---|
[47627] | 417 | LogFlowThisFuncLeave();
|
---|
[42084] | 418 | return S_OK;
|
---|
| 419 | }
|
---|
| 420 |
|
---|
[50727] | 421 | HRESULT GuestSession::setTimeout(ULONG aTimeout)
|
---|
[42411] | 422 | {
|
---|
| 423 | LogFlowThisFuncEnter();
|
---|
| 424 |
|
---|
| 425 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 426 |
|
---|
| 427 | mData.mTimeout = aTimeout;
|
---|
| 428 |
|
---|
[47627] | 429 | LogFlowThisFuncLeave();
|
---|
[42411] | 430 | return S_OK;
|
---|
| 431 | }
|
---|
| 432 |
|
---|
[50727] | 433 | HRESULT GuestSession::getProtocolVersion(ULONG *aProtocolVersion)
|
---|
[47469] | 434 | {
|
---|
| 435 | LogFlowThisFuncEnter();
|
---|
| 436 |
|
---|
| 437 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 438 |
|
---|
[50727] | 439 | *aProtocolVersion = mData.mProtocolVersion;
|
---|
[47469] | 440 |
|
---|
[47627] | 441 | LogFlowThisFuncLeave();
|
---|
[47469] | 442 | return S_OK;
|
---|
| 443 | }
|
---|
| 444 |
|
---|
[55591] | 445 | HRESULT GuestSession::getEnvironmentChanges(std::vector<com::Utf8Str> &aEnvironmentChanges)
|
---|
[42084] | 446 | {
|
---|
[42194] | 447 | LogFlowThisFuncEnter();
|
---|
| 448 |
|
---|
[42084] | 449 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 450 |
|
---|
[55591] | 451 | int vrc = mData.mEnvironmentChanges.queryPutEnvArray(&aEnvironmentChanges);
|
---|
[50764] | 452 |
|
---|
[55588] | 453 | LogFlowFuncLeaveRC(vrc);
|
---|
| 454 | return Global::vboxStatusCodeToCOM(vrc);
|
---|
[42084] | 455 | }
|
---|
| 456 |
|
---|
[55591] | 457 | HRESULT GuestSession::setEnvironmentChanges(const std::vector<com::Utf8Str> &aEnvironmentChanges)
|
---|
[42551] | 458 | {
|
---|
| 459 | LogFlowThisFuncEnter();
|
---|
| 460 |
|
---|
| 461 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 462 |
|
---|
[55591] | 463 | mData.mEnvironmentChanges.reset();
|
---|
| 464 | int vrc = mData.mEnvironmentChanges.applyPutEnvArray(aEnvironmentChanges);
|
---|
[42551] | 465 |
|
---|
[55588] | 466 | LogFlowFuncLeaveRC(vrc);
|
---|
| 467 | return Global::vboxStatusCodeToCOM(vrc);
|
---|
[42551] | 468 | }
|
---|
| 469 |
|
---|
[55591] | 470 | HRESULT GuestSession::getEnvironmentBase(std::vector<com::Utf8Str> &aEnvironmentBase)
|
---|
| 471 | {
|
---|
| 472 | LogFlowThisFuncEnter();
|
---|
| 473 |
|
---|
| 474 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 475 | HRESULT hrc;
|
---|
| 476 | if (mData.mpBaseEnvironment)
|
---|
| 477 | {
|
---|
| 478 | int vrc = mData.mpBaseEnvironment->queryPutEnvArray(&aEnvironmentBase);
|
---|
| 479 | hrc = Global::vboxStatusCodeToCOM(vrc);
|
---|
| 480 | }
|
---|
| 481 | else if (mData.mProtocolVersion < 99999)
|
---|
| 482 | hrc = setError(VBOX_E_NOT_SUPPORTED, tr("The base environment feature is not supported by the guest additions"));
|
---|
| 483 | else
|
---|
| 484 | hrc = setError(VBOX_E_INVALID_OBJECT_STATE, tr("The base environment has not yet been reported by the guest"));
|
---|
| 485 |
|
---|
| 486 | LogFlowFuncLeave();
|
---|
| 487 | return hrc;
|
---|
| 488 | }
|
---|
| 489 |
|
---|
[50727] | 490 | HRESULT GuestSession::getProcesses(std::vector<ComPtr<IGuestProcess> > &aProcesses)
|
---|
[42084] | 491 | {
|
---|
[42194] | 492 | LogFlowThisFuncEnter();
|
---|
| 493 |
|
---|
[42084] | 494 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[50764] | 495 |
|
---|
[50727] | 496 | aProcesses.resize(mData.mProcesses.size());
|
---|
| 497 | size_t i = 0;
|
---|
[50764] | 498 | for(SessionProcesses::iterator it = mData.mProcesses.begin();
|
---|
| 499 | it != mData.mProcesses.end();
|
---|
| 500 | ++it, ++i)
|
---|
| 501 | {
|
---|
[50727] | 502 | it->second.queryInterfaceTo(aProcesses[i].asOutParam());
|
---|
[50764] | 503 | }
|
---|
[42084] | 504 |
|
---|
[50727] | 505 | LogFlowFunc(("mProcesses=%zu\n", aProcesses.size()));
|
---|
[42084] | 506 | return S_OK;
|
---|
| 507 | }
|
---|
| 508 |
|
---|
[55613] | 509 | HRESULT GuestSession::getPathStyle(PathStyle_T *aPathStyle)
|
---|
| 510 | {
|
---|
| 511 | VBOXOSTYPE enmOsType = mParent->i_getGuestOSType();
|
---|
| 512 | if ( enmOsType < VBOXOSTYPE_DOS)
|
---|
| 513 | {
|
---|
| 514 | *aPathStyle = PathStyle_Unknown;
|
---|
| 515 | LogFlowFunc(("returns PathStyle_Unknown\n"));
|
---|
| 516 | }
|
---|
| 517 | else if (enmOsType < VBOXOSTYPE_Linux)
|
---|
| 518 | {
|
---|
| 519 | *aPathStyle = PathStyle_DOS;
|
---|
| 520 | LogFlowFunc(("returns PathStyle_DOS\n"));
|
---|
| 521 | }
|
---|
| 522 | else
|
---|
| 523 | {
|
---|
| 524 | *aPathStyle = PathStyle_UNIX;
|
---|
| 525 | LogFlowFunc(("returns PathStyle_UNIX\n"));
|
---|
| 526 | }
|
---|
| 527 | return S_OK;
|
---|
| 528 | }
|
---|
| 529 |
|
---|
[55631] | 530 | HRESULT GuestSession::getCurrentDirectory(com::Utf8Str &aCurrentDirectory)
|
---|
| 531 | {
|
---|
[63249] | 532 | RT_NOREF(aCurrentDirectory);
|
---|
[55631] | 533 | ReturnComNotImplemented();
|
---|
| 534 | }
|
---|
| 535 |
|
---|
| 536 | HRESULT GuestSession::setCurrentDirectory(const com::Utf8Str &aCurrentDirectory)
|
---|
| 537 | {
|
---|
[63249] | 538 | RT_NOREF(aCurrentDirectory);
|
---|
[55631] | 539 | ReturnComNotImplemented();
|
---|
| 540 | }
|
---|
| 541 |
|
---|
[50727] | 542 | HRESULT GuestSession::getDirectories(std::vector<ComPtr<IGuestDirectory> > &aDirectories)
|
---|
[42084] | 543 | {
|
---|
[42194] | 544 | LogFlowThisFuncEnter();
|
---|
| 545 |
|
---|
[42084] | 546 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[50764] | 547 |
|
---|
[50727] | 548 | aDirectories.resize(mData.mDirectories.size());
|
---|
| 549 | size_t i = 0;
|
---|
[50764] | 550 | for(SessionDirectories::iterator it = mData.mDirectories.begin();
|
---|
| 551 | it != mData.mDirectories.end();
|
---|
| 552 | ++it, ++i)
|
---|
| 553 | {
|
---|
[50727] | 554 | it->second.queryInterfaceTo(aDirectories[i].asOutParam());
|
---|
[50764] | 555 | }
|
---|
[42084] | 556 |
|
---|
[50727] | 557 | LogFlowFunc(("mDirectories=%zu\n", aDirectories.size()));
|
---|
[42084] | 558 | return S_OK;
|
---|
| 559 | }
|
---|
| 560 |
|
---|
[50727] | 561 | HRESULT GuestSession::getFiles(std::vector<ComPtr<IGuestFile> > &aFiles)
|
---|
[42084] | 562 | {
|
---|
[42194] | 563 | LogFlowThisFuncEnter();
|
---|
| 564 |
|
---|
[50727] | 565 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[42084] | 566 |
|
---|
[50727] | 567 | aFiles.resize(mData.mFiles.size());
|
---|
| 568 | size_t i = 0;
|
---|
| 569 | for(SessionFiles::iterator it = mData.mFiles.begin(); it != mData.mFiles.end(); ++it, ++i)
|
---|
| 570 | it->second.queryInterfaceTo(aFiles[i].asOutParam());
|
---|
[42084] | 571 |
|
---|
[50727] | 572 | LogFlowFunc(("mDirectories=%zu\n", aFiles.size()));
|
---|
[42084] | 573 |
|
---|
| 574 | return S_OK;
|
---|
| 575 | }
|
---|
| 576 |
|
---|
[50727] | 577 | HRESULT GuestSession::getEventSource(ComPtr<IEventSource> &aEventSource)
|
---|
[45415] | 578 | {
|
---|
[45426] | 579 | LogFlowThisFuncEnter();
|
---|
| 580 |
|
---|
[45415] | 581 | // no need to lock - lifetime constant
|
---|
[50727] | 582 | mEventSource.queryInterfaceTo(aEventSource.asOutParam());
|
---|
[45415] | 583 |
|
---|
[47627] | 584 | LogFlowThisFuncLeave();
|
---|
[45415] | 585 | return S_OK;
|
---|
| 586 | }
|
---|
| 587 |
|
---|
[42105] | 588 | // private methods
|
---|
[44863] | 589 | ///////////////////////////////////////////////////////////////////////////////
|
---|
[42105] | 590 |
|
---|
[50727] | 591 | int GuestSession::i_closeSession(uint32_t uFlags, uint32_t uTimeoutMS, int *pGuestRc)
|
---|
[44863] | 592 | {
|
---|
[60622] | 593 | AssertPtrReturn(pGuestRc, VERR_INVALID_POINTER);
|
---|
| 594 |
|
---|
[44863] | 595 | LogFlowThisFunc(("uFlags=%x, uTimeoutMS=%RU32\n", uFlags, uTimeoutMS));
|
---|
| 596 |
|
---|
[45415] | 597 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 598 |
|
---|
[47469] | 599 | /* Guest Additions < 4.3 don't support closing dedicated
|
---|
| 600 | guest sessions, skip. */
|
---|
[44863] | 601 | if (mData.mProtocolVersion < 2)
|
---|
| 602 | {
|
---|
[44935] | 603 | LogFlowThisFunc(("Installed Guest Additions don't support closing dedicated sessions, skipping\n"));
|
---|
[44863] | 604 | return VINF_SUCCESS;
|
---|
| 605 | }
|
---|
| 606 |
|
---|
[44935] | 607 | /** @todo uFlags validation. */
|
---|
| 608 |
|
---|
[45415] | 609 | if (mData.mStatus != GuestSessionStatus_Started)
|
---|
[47698] | 610 | {
|
---|
[49504] | 611 | LogFlowThisFunc(("Session ID=%RU32 not started (anymore), status now is: %RU32\n",
|
---|
[47698] | 612 | mData.mSession.mID, mData.mStatus));
|
---|
[45415] | 613 | return VINF_SUCCESS;
|
---|
[47698] | 614 | }
|
---|
[44863] | 615 |
|
---|
[45780] | 616 | int vrc;
|
---|
| 617 |
|
---|
| 618 | GuestWaitEvent *pEvent = NULL;
|
---|
[49349] | 619 | GuestEventTypes eventTypes;
|
---|
[45780] | 620 | try
|
---|
[44863] | 621 | {
|
---|
[45780] | 622 | eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
|
---|
[44863] | 623 |
|
---|
[47469] | 624 | vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
|
---|
| 625 | eventTypes, &pEvent);
|
---|
[45780] | 626 | }
|
---|
| 627 | catch (std::bad_alloc)
|
---|
| 628 | {
|
---|
| 629 | vrc = VERR_NO_MEMORY;
|
---|
| 630 | }
|
---|
[44863] | 631 |
|
---|
[45780] | 632 | if (RT_FAILURE(vrc))
|
---|
| 633 | return vrc;
|
---|
[44863] | 634 |
|
---|
[45780] | 635 | LogFlowThisFunc(("Sending closing request to guest session ID=%RU32, uFlags=%x\n",
|
---|
| 636 | mData.mSession.mID, uFlags));
|
---|
[44935] | 637 |
|
---|
[45780] | 638 | VBOXHGCMSVCPARM paParms[4];
|
---|
| 639 | int i = 0;
|
---|
| 640 | paParms[i++].setUInt32(pEvent->ContextID());
|
---|
| 641 | paParms[i++].setUInt32(uFlags);
|
---|
| 642 |
|
---|
[47627] | 643 | alock.release(); /* Drop the write lock before waiting. */
|
---|
| 644 |
|
---|
[50727] | 645 | vrc = i_sendCommand(HOST_SESSION_CLOSE, i, paParms);
|
---|
[45780] | 646 | if (RT_SUCCESS(vrc))
|
---|
[50727] | 647 | vrc = i_waitForStatusChange(pEvent, GuestSessionWaitForFlag_Terminate, uTimeoutMS,
|
---|
[45780] | 648 | NULL /* Session status */, pGuestRc);
|
---|
[44863] | 649 |
|
---|
[47469] | 650 | unregisterWaitEvent(pEvent);
|
---|
[45780] | 651 |
|
---|
[44863] | 652 | LogFlowFuncLeaveRC(vrc);
|
---|
| 653 | return vrc;
|
---|
| 654 | }
|
---|
| 655 |
|
---|
[50727] | 656 | int GuestSession::i_directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode,
|
---|
[60622] | 657 | uint32_t uFlags, int *pGuestRc)
|
---|
[49349] | 658 | {
|
---|
[60622] | 659 | AssertPtrReturn(pGuestRc, VERR_INVALID_POINTER);
|
---|
[49349] | 660 |
|
---|
[60622] | 661 | LogFlowThisFunc(("strPath=%s, uMode=%x, uFlags=%x\n", strPath.c_str(), uMode, uFlags));
|
---|
| 662 |
|
---|
[49349] | 663 | int vrc = VINF_SUCCESS;
|
---|
| 664 |
|
---|
| 665 | GuestProcessStartupInfo procInfo;
|
---|
[56709] | 666 | procInfo.mFlags = ProcessCreateFlag_Hidden;
|
---|
[55535] | 667 | procInfo.mExecutable = Utf8Str(VBOXSERVICE_TOOL_MKDIR);
|
---|
[49349] | 668 |
|
---|
| 669 | try
|
---|
| 670 | {
|
---|
[61792] | 671 | procInfo.mArguments.push_back(procInfo.mExecutable); /* Set argv0. */
|
---|
| 672 |
|
---|
[49349] | 673 | /* Construct arguments. */
|
---|
[49504] | 674 | if (uFlags)
|
---|
| 675 | {
|
---|
| 676 | if (uFlags & DirectoryCreateFlag_Parents)
|
---|
| 677 | procInfo.mArguments.push_back(Utf8Str("--parents")); /* We also want to create the parent directories. */
|
---|
| 678 | else
|
---|
| 679 | vrc = VERR_INVALID_PARAMETER;
|
---|
| 680 | }
|
---|
[49570] | 681 |
|
---|
[49349] | 682 | if (uMode)
|
---|
| 683 | {
|
---|
| 684 | procInfo.mArguments.push_back(Utf8Str("--mode")); /* Set the creation mode. */
|
---|
| 685 |
|
---|
| 686 | char szMode[16];
|
---|
| 687 | if (RTStrPrintf(szMode, sizeof(szMode), "%o", uMode))
|
---|
| 688 | {
|
---|
| 689 | procInfo.mArguments.push_back(Utf8Str(szMode));
|
---|
| 690 | }
|
---|
| 691 | else
|
---|
| 692 | vrc = VERR_BUFFER_OVERFLOW;
|
---|
| 693 | }
|
---|
[55614] | 694 | procInfo.mArguments.push_back("--"); /* '--version' is a valid directory name. */
|
---|
[49349] | 695 | procInfo.mArguments.push_back(strPath); /* The directory we want to create. */
|
---|
| 696 | }
|
---|
| 697 | catch (std::bad_alloc)
|
---|
| 698 | {
|
---|
| 699 | vrc = VERR_NO_MEMORY;
|
---|
| 700 | }
|
---|
| 701 |
|
---|
| 702 | if (RT_SUCCESS(vrc))
|
---|
[50709] | 703 | vrc = GuestProcessTool::i_run(this, procInfo, pGuestRc);
|
---|
[49349] | 704 |
|
---|
| 705 | LogFlowFuncLeaveRC(vrc);
|
---|
| 706 | return vrc;
|
---|
| 707 | }
|
---|
| 708 |
|
---|
[50727] | 709 | inline bool GuestSession::i_directoryExists(uint32_t uDirID, ComObjPtr<GuestDirectory> *pDir)
|
---|
[49349] | 710 | {
|
---|
| 711 | SessionDirectories::const_iterator it = mData.mDirectories.find(uDirID);
|
---|
| 712 | if (it != mData.mDirectories.end())
|
---|
| 713 | {
|
---|
| 714 | if (pDir)
|
---|
| 715 | *pDir = it->second;
|
---|
| 716 | return true;
|
---|
| 717 | }
|
---|
| 718 | return false;
|
---|
| 719 | }
|
---|
| 720 |
|
---|
[55613] | 721 | int GuestSession::i_directoryQueryInfoInternal(const Utf8Str &strPath, bool fFollowSymlinks,
|
---|
| 722 | GuestFsObjData &objData, int *pGuestRc)
|
---|
[49349] | 723 | {
|
---|
[60622] | 724 | AssertPtrReturn(pGuestRc, VERR_INVALID_POINTER);
|
---|
[49349] | 725 |
|
---|
[60622] | 726 | LogFlowThisFunc(("strPath=%s, fFollowSymlinks=%RTbool\n", strPath.c_str(), fFollowSymlinks));
|
---|
| 727 |
|
---|
[55613] | 728 | int vrc = i_fsQueryInfoInternal(strPath, fFollowSymlinks, objData, pGuestRc);
|
---|
[49349] | 729 | if (RT_SUCCESS(vrc))
|
---|
| 730 | {
|
---|
| 731 | vrc = objData.mType == FsObjType_Directory
|
---|
| 732 | ? VINF_SUCCESS : VERR_NOT_A_DIRECTORY;
|
---|
| 733 | }
|
---|
| 734 |
|
---|
| 735 | LogFlowFuncLeaveRC(vrc);
|
---|
| 736 | return vrc;
|
---|
| 737 | }
|
---|
| 738 |
|
---|
[50727] | 739 | int GuestSession::i_directoryRemoveFromList(GuestDirectory *pDirectory)
|
---|
[42105] | 740 | {
|
---|
[60622] | 741 | AssertPtrReturn(pDirectory, VERR_INVALID_POINTER);
|
---|
| 742 |
|
---|
[42105] | 743 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 744 |
|
---|
[49504] | 745 | int rc = VERR_NOT_FOUND;
|
---|
| 746 |
|
---|
| 747 | SessionDirectories::iterator itDirs = mData.mDirectories.begin();
|
---|
| 748 | while (itDirs != mData.mDirectories.end())
|
---|
[42105] | 749 | {
|
---|
[49349] | 750 | if (pDirectory == itDirs->second)
|
---|
[42105] | 751 | {
|
---|
[49504] | 752 | /* Make sure to consume the pointer before the one of the
|
---|
| 753 | * iterator gets released. */
|
---|
| 754 | ComObjPtr<GuestDirectory> pDir = pDirectory;
|
---|
| 755 |
|
---|
[42897] | 756 | Bstr strName;
|
---|
[49349] | 757 | HRESULT hr = itDirs->second->COMGETTER(DirectoryName)(strName.asOutParam());
|
---|
[42897] | 758 | ComAssertComRC(hr);
|
---|
| 759 |
|
---|
| 760 | Assert(mData.mDirectories.size());
|
---|
[49504] | 761 | Assert(mData.mNumObjects);
|
---|
[49619] | 762 | LogFlowFunc(("Removing directory \"%s\" (Session: %RU32) (now total %zu processes, %RU32 objects)\n",
|
---|
[49504] | 763 | Utf8Str(strName).c_str(), mData.mSession.mID, mData.mDirectories.size() - 1, mData.mNumObjects - 1));
|
---|
[49570] | 764 |
|
---|
[50618] | 765 | rc = pDirectory->i_onRemove();
|
---|
[49504] | 766 | mData.mDirectories.erase(itDirs);
|
---|
| 767 | mData.mNumObjects--;
|
---|
[42897] | 768 |
|
---|
[49504] | 769 | pDir.setNull();
|
---|
| 770 | break;
|
---|
[42105] | 771 | }
|
---|
[49504] | 772 |
|
---|
[56030] | 773 | ++itDirs;
|
---|
[42105] | 774 | }
|
---|
| 775 |
|
---|
[49504] | 776 | LogFlowFuncLeaveRC(rc);
|
---|
| 777 | return rc;
|
---|
[42105] | 778 | }
|
---|
| 779 |
|
---|
[50727] | 780 | int GuestSession::i_directoryRemoveInternal(const Utf8Str &strPath, uint32_t uFlags,
|
---|
| 781 | int *pGuestRc)
|
---|
[42525] | 782 | {
|
---|
[49349] | 783 | AssertReturn(!(uFlags & ~DIRREMOVE_FLAG_VALID_MASK), VERR_INVALID_PARAMETER);
|
---|
[60622] | 784 | AssertPtrReturn(pGuestRc, VERR_INVALID_POINTER);
|
---|
[45078] | 785 |
|
---|
[49349] | 786 | LogFlowThisFunc(("strPath=%s, uFlags=0x%x\n", strPath.c_str(), uFlags));
|
---|
[42525] | 787 |
|
---|
[49349] | 788 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[42525] | 789 |
|
---|
[49349] | 790 | GuestWaitEvent *pEvent = NULL;
|
---|
| 791 | int vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
|
---|
| 792 | &pEvent);
|
---|
| 793 | if (RT_FAILURE(vrc))
|
---|
| 794 | return vrc;
|
---|
[42525] | 795 |
|
---|
[49349] | 796 | /* Prepare HGCM call. */
|
---|
| 797 | VBOXHGCMSVCPARM paParms[8];
|
---|
| 798 | int i = 0;
|
---|
| 799 | paParms[i++].setUInt32(pEvent->ContextID());
|
---|
| 800 | paParms[i++].setPointer((void*)strPath.c_str(),
|
---|
| 801 | (ULONG)strPath.length() + 1);
|
---|
| 802 | paParms[i++].setUInt32(uFlags);
|
---|
[42525] | 803 |
|
---|
[49349] | 804 | alock.release(); /* Drop write lock before sending. */
|
---|
[42525] | 805 |
|
---|
[50727] | 806 | vrc = i_sendCommand(HOST_DIR_REMOVE, i, paParms);
|
---|
[43162] | 807 | if (RT_SUCCESS(vrc))
|
---|
[42525] | 808 | {
|
---|
[49349] | 809 | vrc = pEvent->Wait(30 * 1000);
|
---|
[45078] | 810 | if ( vrc == VERR_GSTCTL_GUEST_ERROR
|
---|
| 811 | && pGuestRc)
|
---|
[49349] | 812 | *pGuestRc = pEvent->GuestResult();
|
---|
[42525] | 813 | }
|
---|
| 814 |
|
---|
[49349] | 815 | unregisterWaitEvent(pEvent);
|
---|
[42525] | 816 |
|
---|
[43162] | 817 | LogFlowFuncLeaveRC(vrc);
|
---|
| 818 | return vrc;
|
---|
[42525] | 819 | }
|
---|
| 820 |
|
---|
[50727] | 821 | int GuestSession::i_objectCreateTempInternal(const Utf8Str &strTemplate, const Utf8Str &strPath,
|
---|
| 822 | bool fDirectory, Utf8Str &strName, int *pGuestRc)
|
---|
[42783] | 823 | {
|
---|
[60622] | 824 | AssertPtrReturn(pGuestRc, VERR_INVALID_POINTER);
|
---|
| 825 |
|
---|
[49948] | 826 | LogFlowThisFunc(("strTemplate=%s, strPath=%s, fDirectory=%RTbool\n",
|
---|
| 827 | strTemplate.c_str(), strPath.c_str(), fDirectory));
|
---|
[49349] | 828 |
|
---|
[42783] | 829 | GuestProcessStartupInfo procInfo;
|
---|
[63156] | 830 | procInfo.mFlags = ProcessCreateFlag_WaitForStdOut;
|
---|
[49349] | 831 | try
|
---|
[42783] | 832 | {
|
---|
[63156] | 833 | procInfo.mExecutable = Utf8Str(VBOXSERVICE_TOOL_MKTEMP);
|
---|
[61792] | 834 | procInfo.mArguments.push_back(procInfo.mExecutable); /* Set argv0. */
|
---|
[49349] | 835 | procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
|
---|
| 836 | if (fDirectory)
|
---|
| 837 | procInfo.mArguments.push_back(Utf8Str("-d"));
|
---|
| 838 | if (strPath.length()) /* Otherwise use /tmp or equivalent. */
|
---|
| 839 | {
|
---|
| 840 | procInfo.mArguments.push_back(Utf8Str("-t"));
|
---|
| 841 | procInfo.mArguments.push_back(strPath);
|
---|
| 842 | }
|
---|
[55614] | 843 | procInfo.mArguments.push_back("--"); /* strTemplate could be '--help'. */
|
---|
[49349] | 844 | procInfo.mArguments.push_back(strTemplate);
|
---|
[42783] | 845 | }
|
---|
[49349] | 846 | catch (std::bad_alloc)
|
---|
[42783] | 847 | {
|
---|
[63156] | 848 | Log(("Out of memory!\n"));
|
---|
| 849 | return VERR_NO_MEMORY;
|
---|
[43162] | 850 | }
|
---|
[42783] | 851 |
|
---|
[49948] | 852 | /** @todo Use an internal HGCM command for this operation, since
|
---|
| 853 | * we now can run in a user-dedicated session. */
|
---|
[63156] | 854 | int vrcGuest = VERR_IPE_UNINITIALIZED_STATUS;
|
---|
[61792] | 855 | GuestCtrlStreamObjects stdOut;
|
---|
[63156] | 856 | int vrc = GuestProcessTool::i_runEx(this, procInfo,
|
---|
[50709] | 857 | &stdOut, 1 /* cStrmOutObjects */,
|
---|
[63156] | 858 | &vrcGuest);
|
---|
[61792] | 859 | if (!GuestProcess::i_isGuestError(vrc))
|
---|
[49948] | 860 | {
|
---|
| 861 | GuestFsObjData objData;
|
---|
| 862 | if (!stdOut.empty())
|
---|
| 863 | {
|
---|
| 864 | vrc = objData.FromMkTemp(stdOut.at(0));
|
---|
| 865 | if (RT_FAILURE(vrc))
|
---|
| 866 | {
|
---|
[63157] | 867 | vrcGuest = vrc;
|
---|
[63156] | 868 | if (pGuestRc)
|
---|
| 869 | *pGuestRc = vrc;
|
---|
[49948] | 870 | vrc = VERR_GSTCTL_GUEST_ERROR;
|
---|
| 871 | }
|
---|
| 872 | }
|
---|
| 873 | else
|
---|
[61792] | 874 | vrc = VERR_BROKEN_PIPE;
|
---|
[42783] | 875 |
|
---|
[49948] | 876 | if (RT_SUCCESS(vrc))
|
---|
| 877 | strName = objData.mName;
|
---|
| 878 | }
|
---|
[61792] | 879 | else if (pGuestRc)
|
---|
[63156] | 880 | *pGuestRc = vrcGuest;
|
---|
[49948] | 881 |
|
---|
[63157] | 882 | LogFlowThisFunc(("Returning vrc=%Rrc, vrcGuest=%Rrc\n", vrc, vrcGuest));
|
---|
[44863] | 883 | return vrc;
|
---|
[42783] | 884 | }
|
---|
| 885 |
|
---|
[50727] | 886 | int GuestSession::i_directoryOpenInternal(const GuestDirectoryOpenInfo &openInfo,
|
---|
| 887 | ComObjPtr<GuestDirectory> &pDirectory, int *pGuestRc)
|
---|
[42673] | 888 | {
|
---|
[60622] | 889 | AssertPtrReturn(pGuestRc, VERR_INVALID_POINTER);
|
---|
| 890 |
|
---|
[42673] | 891 | LogFlowThisFunc(("strPath=%s, strPath=%s, uFlags=%x\n",
|
---|
[49349] | 892 | openInfo.mPath.c_str(), openInfo.mFilter.c_str(), openInfo.mFlags));
|
---|
[42673] | 893 |
|
---|
[42693] | 894 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[42673] | 895 |
|
---|
[49349] | 896 | int rc = VERR_MAX_PROCS_REACHED;
|
---|
| 897 | if (mData.mNumObjects >= VBOX_GUESTCTRL_MAX_OBJECTS)
|
---|
| 898 | return rc;
|
---|
| 899 |
|
---|
| 900 | /* Create a new (host-based) directory ID and assign it. */
|
---|
| 901 | uint32_t uNewDirID = 0;
|
---|
| 902 | ULONG uTries = 0;
|
---|
| 903 |
|
---|
| 904 | for (;;)
|
---|
| 905 | {
|
---|
| 906 | /* Is the directory ID already used? */
|
---|
[50727] | 907 | if (!i_directoryExists(uNewDirID, NULL /* pDirectory */))
|
---|
[49349] | 908 | {
|
---|
| 909 | /* Callback with context ID was not found. This means
|
---|
| 910 | * we can use this context ID for our new callback we want
|
---|
| 911 | * to add below. */
|
---|
| 912 | rc = VINF_SUCCESS;
|
---|
| 913 | break;
|
---|
| 914 | }
|
---|
| 915 | uNewDirID++;
|
---|
| 916 | if (uNewDirID == VBOX_GUESTCTRL_MAX_OBJECTS)
|
---|
| 917 | uNewDirID = 0;
|
---|
| 918 |
|
---|
| 919 | if (++uTries == UINT32_MAX)
|
---|
| 920 | break; /* Don't try too hard. */
|
---|
| 921 | }
|
---|
| 922 |
|
---|
| 923 | if (RT_FAILURE(rc))
|
---|
| 924 | return rc;
|
---|
| 925 |
|
---|
[42693] | 926 | /* Create the directory object. */
|
---|
| 927 | HRESULT hr = pDirectory.createObject();
|
---|
| 928 | if (FAILED(hr))
|
---|
| 929 | return VERR_COM_UNEXPECTED;
|
---|
[42673] | 930 |
|
---|
[52082] | 931 | Console *pConsole = mParent->i_getConsole();
|
---|
[49349] | 932 | AssertPtr(pConsole);
|
---|
| 933 |
|
---|
| 934 | int vrc = pDirectory->init(pConsole, this /* Parent */,
|
---|
| 935 | uNewDirID, openInfo);
|
---|
[43162] | 936 | if (RT_FAILURE(vrc))
|
---|
| 937 | return vrc;
|
---|
[42673] | 938 |
|
---|
[49349] | 939 | /*
|
---|
| 940 | * Since this is a synchronous guest call we have to
|
---|
| 941 | * register the file object first, releasing the session's
|
---|
| 942 | * lock and then proceed with the actual opening command
|
---|
| 943 | * -- otherwise the file's opening callback would hang
|
---|
| 944 | * because the session's lock still is in place.
|
---|
| 945 | */
|
---|
| 946 | try
|
---|
| 947 | {
|
---|
| 948 | /* Add the created directory to our map. */
|
---|
| 949 | mData.mDirectories[uNewDirID] = pDirectory;
|
---|
| 950 | mData.mNumObjects++;
|
---|
| 951 | Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
|
---|
[42673] | 952 |
|
---|
[49619] | 953 | LogFlowFunc(("Added new guest directory \"%s\" (Session: %RU32) (now total %zu dirs, %RU32 objects)\n",
|
---|
[49349] | 954 | openInfo.mPath.c_str(), mData.mSession.mID, mData.mFiles.size(), mData.mNumObjects));
|
---|
[42673] | 955 |
|
---|
[49349] | 956 | alock.release(); /* Release lock before firing off event. */
|
---|
| 957 |
|
---|
| 958 | /** @todo Fire off a VBoxEventType_OnGuestDirectoryRegistered event? */
|
---|
| 959 | }
|
---|
| 960 | catch (std::bad_alloc &)
|
---|
| 961 | {
|
---|
| 962 | rc = VERR_NO_MEMORY;
|
---|
| 963 | }
|
---|
| 964 |
|
---|
| 965 | if (RT_SUCCESS(rc))
|
---|
| 966 | {
|
---|
| 967 | /* Nothing further to do here yet. */
|
---|
| 968 | if (pGuestRc)
|
---|
| 969 | *pGuestRc = VINF_SUCCESS;
|
---|
| 970 | }
|
---|
| 971 |
|
---|
[43162] | 972 | LogFlowFuncLeaveRC(vrc);
|
---|
| 973 | return vrc;
|
---|
[42673] | 974 | }
|
---|
| 975 |
|
---|
[50727] | 976 | int GuestSession::i_dispatchToDirectory(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
|
---|
[49349] | 977 | {
|
---|
| 978 | LogFlowFunc(("pCtxCb=%p, pSvcCb=%p\n", pCtxCb, pSvcCb));
|
---|
| 979 |
|
---|
| 980 | AssertPtrReturn(pCtxCb, VERR_INVALID_POINTER);
|
---|
| 981 | AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
|
---|
| 982 |
|
---|
| 983 | if (pSvcCb->mParms < 3)
|
---|
| 984 | return VERR_INVALID_PARAMETER;
|
---|
| 985 |
|
---|
| 986 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 987 |
|
---|
| 988 | uint32_t uDirID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCtxCb->uContextID);
|
---|
| 989 | #ifdef DEBUG
|
---|
[49619] | 990 | LogFlowFunc(("uDirID=%RU32 (%zu total)\n",
|
---|
[49349] | 991 | uDirID, mData.mFiles.size()));
|
---|
| 992 | #endif
|
---|
| 993 | int rc;
|
---|
| 994 | SessionDirectories::const_iterator itDir
|
---|
| 995 | = mData.mDirectories.find(uDirID);
|
---|
| 996 | if (itDir != mData.mDirectories.end())
|
---|
| 997 | {
|
---|
| 998 | ComObjPtr<GuestDirectory> pDirectory(itDir->second);
|
---|
| 999 | Assert(!pDirectory.isNull());
|
---|
| 1000 |
|
---|
| 1001 | alock.release();
|
---|
| 1002 |
|
---|
[50618] | 1003 | rc = pDirectory->i_callbackDispatcher(pCtxCb, pSvcCb);
|
---|
[49349] | 1004 | }
|
---|
| 1005 | else
|
---|
| 1006 | rc = VERR_NOT_FOUND;
|
---|
| 1007 |
|
---|
| 1008 | LogFlowFuncLeaveRC(rc);
|
---|
| 1009 | return rc;
|
---|
| 1010 | }
|
---|
| 1011 |
|
---|
[50727] | 1012 | int GuestSession::i_dispatchToFile(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
|
---|
[42214] | 1013 | {
|
---|
[44863] | 1014 | LogFlowFunc(("pCtxCb=%p, pSvcCb=%p\n", pCtxCb, pSvcCb));
|
---|
[42272] | 1015 |
|
---|
[44863] | 1016 | AssertPtrReturn(pCtxCb, VERR_INVALID_POINTER);
|
---|
| 1017 | AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
|
---|
| 1018 |
|
---|
[42214] | 1019 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1020 |
|
---|
[44863] | 1021 | uint32_t uFileID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCtxCb->uContextID);
|
---|
[42436] | 1022 | #ifdef DEBUG
|
---|
[49619] | 1023 | LogFlowFunc(("uFileID=%RU32 (%zu total)\n",
|
---|
[44863] | 1024 | uFileID, mData.mFiles.size()));
|
---|
| 1025 | #endif
|
---|
| 1026 | int rc;
|
---|
| 1027 | SessionFiles::const_iterator itFile
|
---|
| 1028 | = mData.mFiles.find(uFileID);
|
---|
| 1029 | if (itFile != mData.mFiles.end())
|
---|
| 1030 | {
|
---|
| 1031 | ComObjPtr<GuestFile> pFile(itFile->second);
|
---|
| 1032 | Assert(!pFile.isNull());
|
---|
| 1033 |
|
---|
| 1034 | alock.release();
|
---|
| 1035 |
|
---|
[50618] | 1036 | rc = pFile->i_callbackDispatcher(pCtxCb, pSvcCb);
|
---|
[44863] | 1037 | }
|
---|
| 1038 | else
|
---|
| 1039 | rc = VERR_NOT_FOUND;
|
---|
| 1040 |
|
---|
| 1041 | LogFlowFuncLeaveRC(rc);
|
---|
| 1042 | return rc;
|
---|
| 1043 | }
|
---|
| 1044 |
|
---|
[50727] | 1045 | int GuestSession::i_dispatchToObject(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
|
---|
[49349] | 1046 | {
|
---|
| 1047 | LogFlowFunc(("pCtxCb=%p, pSvcCb=%p\n", pCtxCb, pSvcCb));
|
---|
| 1048 |
|
---|
| 1049 | AssertPtrReturn(pCtxCb, VERR_INVALID_POINTER);
|
---|
| 1050 | AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
|
---|
| 1051 |
|
---|
| 1052 | int rc;
|
---|
| 1053 | uint32_t uObjectID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCtxCb->uContextID);
|
---|
| 1054 |
|
---|
| 1055 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1056 |
|
---|
| 1057 | /* Since we don't know which type the object is, we need to through all
|
---|
| 1058 | * all objects. */
|
---|
| 1059 | /** @todo Speed this up by adding an object type to the callback context! */
|
---|
| 1060 | SessionProcesses::const_iterator itProc = mData.mProcesses.find(uObjectID);
|
---|
| 1061 | if (itProc == mData.mProcesses.end())
|
---|
| 1062 | {
|
---|
| 1063 | SessionFiles::const_iterator itFile = mData.mFiles.find(uObjectID);
|
---|
| 1064 | if (itFile != mData.mFiles.end())
|
---|
| 1065 | {
|
---|
| 1066 | alock.release();
|
---|
| 1067 |
|
---|
[50727] | 1068 | rc = i_dispatchToFile(pCtxCb, pSvcCb);
|
---|
[49349] | 1069 | }
|
---|
| 1070 | else
|
---|
| 1071 | {
|
---|
| 1072 | SessionDirectories::const_iterator itDir = mData.mDirectories.find(uObjectID);
|
---|
| 1073 | if (itDir != mData.mDirectories.end())
|
---|
| 1074 | {
|
---|
| 1075 | alock.release();
|
---|
| 1076 |
|
---|
[50727] | 1077 | rc = i_dispatchToDirectory(pCtxCb, pSvcCb);
|
---|
[49349] | 1078 | }
|
---|
| 1079 | else
|
---|
| 1080 | rc = VERR_NOT_FOUND;
|
---|
| 1081 | }
|
---|
| 1082 | }
|
---|
| 1083 | else
|
---|
| 1084 | {
|
---|
| 1085 | alock.release();
|
---|
| 1086 |
|
---|
[50727] | 1087 | rc = i_dispatchToProcess(pCtxCb, pSvcCb);
|
---|
[49349] | 1088 | }
|
---|
| 1089 |
|
---|
| 1090 | LogFlowFuncLeaveRC(rc);
|
---|
| 1091 | return rc;
|
---|
| 1092 | }
|
---|
| 1093 |
|
---|
[50727] | 1094 | int GuestSession::i_dispatchToProcess(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
|
---|
[44863] | 1095 | {
|
---|
| 1096 | LogFlowFunc(("pCtxCb=%p, pSvcCb=%p\n", pCtxCb, pSvcCb));
|
---|
| 1097 |
|
---|
| 1098 | AssertPtrReturn(pCtxCb, VERR_INVALID_POINTER);
|
---|
| 1099 | AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
|
---|
| 1100 |
|
---|
| 1101 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1102 |
|
---|
| 1103 | uint32_t uProcessID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCtxCb->uContextID);
|
---|
| 1104 | #ifdef DEBUG
|
---|
[49619] | 1105 | LogFlowFunc(("uProcessID=%RU32 (%zu total)\n",
|
---|
[42436] | 1106 | uProcessID, mData.mProcesses.size()));
|
---|
| 1107 | #endif
|
---|
[42272] | 1108 | int rc;
|
---|
[42214] | 1109 | SessionProcesses::const_iterator itProc
|
---|
[42436] | 1110 | = mData.mProcesses.find(uProcessID);
|
---|
[42214] | 1111 | if (itProc != mData.mProcesses.end())
|
---|
| 1112 | {
|
---|
[49630] | 1113 | #ifdef DEBUG_andy
|
---|
| 1114 | ULONG cRefs = itProc->second->AddRef();
|
---|
| 1115 | Assert(cRefs >= 2);
|
---|
| 1116 | LogFlowFunc(("pProcess=%p, cRefs=%RU32\n", &itProc->second, cRefs - 1));
|
---|
| 1117 | itProc->second->Release();
|
---|
| 1118 | #endif
|
---|
[42214] | 1119 | ComObjPtr<GuestProcess> pProcess(itProc->second);
|
---|
| 1120 | Assert(!pProcess.isNull());
|
---|
| 1121 |
|
---|
[44863] | 1122 | /* Set protocol version so that pSvcCb can
|
---|
| 1123 | * be interpreted right. */
|
---|
| 1124 | pCtxCb->uProtocol = mData.mProtocolVersion;
|
---|
| 1125 |
|
---|
[42214] | 1126 | alock.release();
|
---|
[50618] | 1127 | rc = pProcess->i_callbackDispatcher(pCtxCb, pSvcCb);
|
---|
[42214] | 1128 | }
|
---|
[42272] | 1129 | else
|
---|
| 1130 | rc = VERR_NOT_FOUND;
|
---|
| 1131 |
|
---|
| 1132 | LogFlowFuncLeaveRC(rc);
|
---|
| 1133 | return rc;
|
---|
[42214] | 1134 | }
|
---|
| 1135 |
|
---|
[50727] | 1136 | int GuestSession::i_dispatchToThis(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
|
---|
[44863] | 1137 | {
|
---|
| 1138 | AssertPtrReturn(pCbCtx, VERR_INVALID_POINTER);
|
---|
| 1139 | AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
|
---|
| 1140 |
|
---|
| 1141 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1142 |
|
---|
| 1143 | #ifdef DEBUG
|
---|
[45415] | 1144 | LogFlowThisFunc(("sessionID=%RU32, CID=%RU32, uFunction=%RU32, pSvcCb=%p\n",
|
---|
[44935] | 1145 | mData.mSession.mID, pCbCtx->uContextID, pCbCtx->uFunction, pSvcCb));
|
---|
[44863] | 1146 | #endif
|
---|
| 1147 |
|
---|
[49349] | 1148 | int rc;
|
---|
[44863] | 1149 | switch (pCbCtx->uFunction)
|
---|
| 1150 | {
|
---|
[44935] | 1151 | case GUEST_DISCONNECTED:
|
---|
[45415] | 1152 | /** @todo Handle closing all guest objects. */
|
---|
[49359] | 1153 | rc = VERR_INTERNAL_ERROR;
|
---|
[44935] | 1154 | break;
|
---|
| 1155 |
|
---|
[49349] | 1156 | case GUEST_SESSION_NOTIFY: /* Guest Additions >= 4.3.0. */
|
---|
[44863] | 1157 | {
|
---|
[50727] | 1158 | rc = i_onSessionStatusChange(pCbCtx, pSvcCb);
|
---|
[44863] | 1159 | break;
|
---|
| 1160 | }
|
---|
| 1161 |
|
---|
| 1162 | default:
|
---|
| 1163 | /* Silently skip unknown callbacks. */
|
---|
[44935] | 1164 | rc = VERR_NOT_SUPPORTED;
|
---|
[44863] | 1165 | break;
|
---|
| 1166 | }
|
---|
| 1167 |
|
---|
| 1168 | LogFlowFuncLeaveRC(rc);
|
---|
| 1169 | return rc;
|
---|
| 1170 | }
|
---|
| 1171 |
|
---|
[50727] | 1172 | inline bool GuestSession::i_fileExists(uint32_t uFileID, ComObjPtr<GuestFile> *pFile)
|
---|
[44863] | 1173 | {
|
---|
| 1174 | SessionFiles::const_iterator it = mData.mFiles.find(uFileID);
|
---|
| 1175 | if (it != mData.mFiles.end())
|
---|
| 1176 | {
|
---|
| 1177 | if (pFile)
|
---|
| 1178 | *pFile = it->second;
|
---|
| 1179 | return true;
|
---|
| 1180 | }
|
---|
| 1181 | return false;
|
---|
| 1182 | }
|
---|
| 1183 |
|
---|
[50727] | 1184 | int GuestSession::i_fileRemoveFromList(GuestFile *pFile)
|
---|
[42105] | 1185 | {
|
---|
| 1186 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1187 |
|
---|
[49570] | 1188 | int rc = VERR_NOT_FOUND;
|
---|
[49504] | 1189 |
|
---|
| 1190 | SessionFiles::iterator itFiles = mData.mFiles.begin();
|
---|
| 1191 | while (itFiles != mData.mFiles.end())
|
---|
[42105] | 1192 | {
|
---|
[44863] | 1193 | if (pFile == itFiles->second)
|
---|
[42105] | 1194 | {
|
---|
[47627] | 1195 | /* Make sure to consume the pointer before the one of thfe
|
---|
| 1196 | * iterator gets released. */
|
---|
| 1197 | ComObjPtr<GuestFile> pCurFile = pFile;
|
---|
[44863] | 1198 |
|
---|
[42897] | 1199 | Bstr strName;
|
---|
[47627] | 1200 | HRESULT hr = pCurFile->COMGETTER(FileName)(strName.asOutParam());
|
---|
[42897] | 1201 | ComAssertComRC(hr);
|
---|
| 1202 |
|
---|
| 1203 | Assert(mData.mNumObjects);
|
---|
[49619] | 1204 | LogFlowThisFunc(("Removing guest file \"%s\" (Session: %RU32) (now total %zu files, %RU32 objects)\n",
|
---|
[44935] | 1205 | Utf8Str(strName).c_str(), mData.mSession.mID, mData.mFiles.size() - 1, mData.mNumObjects - 1));
|
---|
[45434] | 1206 |
|
---|
[50618] | 1207 | rc = pFile->i_onRemove();
|
---|
[42160] | 1208 | mData.mFiles.erase(itFiles);
|
---|
[42897] | 1209 | mData.mNumObjects--;
|
---|
[45434] | 1210 |
|
---|
[47627] | 1211 | alock.release(); /* Release lock before firing off event. */
|
---|
| 1212 |
|
---|
| 1213 | fireGuestFileRegisteredEvent(mEventSource, this, pCurFile,
|
---|
[45434] | 1214 | false /* Unregistered */);
|
---|
[49570] | 1215 | pCurFile.setNull();
|
---|
[49504] | 1216 | break;
|
---|
[42105] | 1217 | }
|
---|
[49504] | 1218 |
|
---|
[56030] | 1219 | ++itFiles;
|
---|
[42105] | 1220 | }
|
---|
| 1221 |
|
---|
[49504] | 1222 | LogFlowFuncLeaveRC(rc);
|
---|
[49570] | 1223 | return rc;
|
---|
[42105] | 1224 | }
|
---|
| 1225 |
|
---|
[50727] | 1226 | int GuestSession::i_fileRemoveInternal(const Utf8Str &strPath, int *pGuestRc)
|
---|
[42691] | 1227 | {
|
---|
[49349] | 1228 | LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
|
---|
| 1229 |
|
---|
| 1230 | int vrc = VINF_SUCCESS;
|
---|
| 1231 |
|
---|
[42691] | 1232 | GuestProcessStartupInfo procInfo;
|
---|
| 1233 | GuestProcessStream streamOut;
|
---|
| 1234 |
|
---|
[56709] | 1235 | procInfo.mFlags = ProcessCreateFlag_WaitForStdOut;
|
---|
[55535] | 1236 | procInfo.mExecutable = Utf8Str(VBOXSERVICE_TOOL_RM);
|
---|
[42691] | 1237 |
|
---|
[49349] | 1238 | try
|
---|
[42691] | 1239 | {
|
---|
[61792] | 1240 | procInfo.mArguments.push_back(procInfo.mExecutable); /* Set argv0. */
|
---|
[49349] | 1241 | procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
|
---|
[55614] | 1242 | procInfo.mArguments.push_back("--"); /* strPath could be '--help', which is a valid filename. */
|
---|
[49349] | 1243 | procInfo.mArguments.push_back(strPath); /* The file we want to remove. */
|
---|
[43162] | 1244 | }
|
---|
[49349] | 1245 | catch (std::bad_alloc)
|
---|
[45078] | 1246 | {
|
---|
[49349] | 1247 | vrc = VERR_NO_MEMORY;
|
---|
[45078] | 1248 | }
|
---|
[42691] | 1249 |
|
---|
[49349] | 1250 | if (RT_SUCCESS(vrc))
|
---|
[50709] | 1251 | vrc = GuestProcessTool::i_run(this, procInfo, pGuestRc);
|
---|
[49349] | 1252 |
|
---|
[44863] | 1253 | LogFlowFuncLeaveRC(vrc);
|
---|
| 1254 | return vrc;
|
---|
[42691] | 1255 | }
|
---|
| 1256 |
|
---|
[50727] | 1257 | int GuestSession::i_fileOpenInternal(const GuestFileOpenInfo &openInfo,
|
---|
| 1258 | ComObjPtr<GuestFile> &pFile, int *pGuestRc)
|
---|
[42611] | 1259 | {
|
---|
[55668] | 1260 | LogFlowThisFunc(("strFile=%s, enmAccessMode=%d (%s) enmOpenAction=%d (%s) uCreationMode=%RU32 mfOpenEx=%RU32\n",
|
---|
[55631] | 1261 | openInfo.mFileName.c_str(), openInfo.mAccessMode, openInfo.mpszAccessMode,
|
---|
[55668] | 1262 | openInfo.mOpenAction, openInfo.mpszOpenAction, openInfo.mCreationMode, openInfo.mfOpenEx));
|
---|
[42611] | 1263 |
|
---|
[44863] | 1264 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1265 |
|
---|
[47781] | 1266 | /* Guest Additions < 4.3 don't support handling
|
---|
| 1267 | guest files, skip. */
|
---|
| 1268 | if (mData.mProtocolVersion < 2)
|
---|
| 1269 | {
|
---|
| 1270 | LogFlowThisFunc(("Installed Guest Additions don't support handling guest files, skipping\n"));
|
---|
| 1271 | return VERR_NOT_SUPPORTED;
|
---|
| 1272 | }
|
---|
| 1273 |
|
---|
[44863] | 1274 | int rc = VERR_MAX_PROCS_REACHED;
|
---|
| 1275 | if (mData.mNumObjects >= VBOX_GUESTCTRL_MAX_OBJECTS)
|
---|
| 1276 | return rc;
|
---|
| 1277 |
|
---|
| 1278 | /* Create a new (host-based) file ID and assign it. */
|
---|
| 1279 | uint32_t uNewFileID = 0;
|
---|
| 1280 | ULONG uTries = 0;
|
---|
| 1281 |
|
---|
| 1282 | for (;;)
|
---|
| 1283 | {
|
---|
| 1284 | /* Is the file ID already used? */
|
---|
[50727] | 1285 | if (!i_fileExists(uNewFileID, NULL /* pFile */))
|
---|
[44863] | 1286 | {
|
---|
| 1287 | /* Callback with context ID was not found. This means
|
---|
| 1288 | * we can use this context ID for our new callback we want
|
---|
| 1289 | * to add below. */
|
---|
| 1290 | rc = VINF_SUCCESS;
|
---|
| 1291 | break;
|
---|
| 1292 | }
|
---|
| 1293 | uNewFileID++;
|
---|
| 1294 | if (uNewFileID == VBOX_GUESTCTRL_MAX_OBJECTS)
|
---|
| 1295 | uNewFileID = 0;
|
---|
| 1296 |
|
---|
| 1297 | if (++uTries == UINT32_MAX)
|
---|
| 1298 | break; /* Don't try too hard. */
|
---|
| 1299 | }
|
---|
| 1300 |
|
---|
| 1301 | if (RT_FAILURE(rc))
|
---|
| 1302 | return rc;
|
---|
| 1303 |
|
---|
[42693] | 1304 | /* Create the directory object. */
|
---|
| 1305 | HRESULT hr = pFile.createObject();
|
---|
| 1306 | if (FAILED(hr))
|
---|
| 1307 | return VERR_COM_UNEXPECTED;
|
---|
[42611] | 1308 |
|
---|
[52082] | 1309 | Console *pConsole = mParent->i_getConsole();
|
---|
[44863] | 1310 | AssertPtr(pConsole);
|
---|
[42611] | 1311 |
|
---|
[44863] | 1312 | rc = pFile->init(pConsole, this /* GuestSession */,
|
---|
| 1313 | uNewFileID, openInfo);
|
---|
| 1314 | if (RT_FAILURE(rc))
|
---|
| 1315 | return rc;
|
---|
| 1316 |
|
---|
[47817] | 1317 | /*
|
---|
| 1318 | * Since this is a synchronous guest call we have to
|
---|
| 1319 | * register the file object first, releasing the session's
|
---|
| 1320 | * lock and then proceed with the actual opening command
|
---|
| 1321 | * -- otherwise the file's opening callback would hang
|
---|
| 1322 | * because the session's lock still is in place.
|
---|
| 1323 | */
|
---|
| 1324 | try
|
---|
[45109] | 1325 | {
|
---|
[47817] | 1326 | /* Add the created file to our vector. */
|
---|
| 1327 | mData.mFiles[uNewFileID] = pFile;
|
---|
| 1328 | mData.mNumObjects++;
|
---|
| 1329 | Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
|
---|
[42611] | 1330 |
|
---|
[49619] | 1331 | LogFlowFunc(("Added new guest file \"%s\" (Session: %RU32) (now total %zu files, %RU32 objects)\n",
|
---|
[47817] | 1332 | openInfo.mFileName.c_str(), mData.mSession.mID, mData.mFiles.size(), mData.mNumObjects));
|
---|
[45434] | 1333 |
|
---|
[47817] | 1334 | alock.release(); /* Release lock before firing off event. */
|
---|
[47627] | 1335 |
|
---|
[47817] | 1336 | fireGuestFileRegisteredEvent(mEventSource, this, pFile,
|
---|
| 1337 | true /* Registered */);
|
---|
| 1338 | }
|
---|
| 1339 | catch (std::bad_alloc &)
|
---|
| 1340 | {
|
---|
| 1341 | rc = VERR_NO_MEMORY;
|
---|
| 1342 | }
|
---|
| 1343 |
|
---|
| 1344 | if (RT_SUCCESS(rc))
|
---|
| 1345 | {
|
---|
| 1346 | int guestRc;
|
---|
[50618] | 1347 | rc = pFile->i_openFile(30 * 1000 /* 30s timeout */, &guestRc);
|
---|
[47817] | 1348 | if ( rc == VERR_GSTCTL_GUEST_ERROR
|
---|
| 1349 | && pGuestRc)
|
---|
[47781] | 1350 | {
|
---|
[47817] | 1351 | *pGuestRc = guestRc;
|
---|
[47781] | 1352 | }
|
---|
[45109] | 1353 | }
|
---|
[42611] | 1354 |
|
---|
[44863] | 1355 | LogFlowFuncLeaveRC(rc);
|
---|
| 1356 | return rc;
|
---|
[42611] | 1357 | }
|
---|
| 1358 |
|
---|
[55613] | 1359 | int GuestSession::i_fileQueryInfoInternal(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pGuestRc)
|
---|
[42530] | 1360 | {
|
---|
[55613] | 1361 | LogFlowThisFunc(("strPath=%s fFollowSymlinks=%RTbool\n", strPath.c_str(), fFollowSymlinks));
|
---|
[42530] | 1362 |
|
---|
[55613] | 1363 | int vrc = i_fsQueryInfoInternal(strPath, fFollowSymlinks, objData, pGuestRc);
|
---|
[43162] | 1364 | if (RT_SUCCESS(vrc))
|
---|
[42808] | 1365 | {
|
---|
[43162] | 1366 | vrc = objData.mType == FsObjType_File
|
---|
| 1367 | ? VINF_SUCCESS : VERR_NOT_A_FILE;
|
---|
[42808] | 1368 | }
|
---|
| 1369 |
|
---|
[43162] | 1370 | LogFlowFuncLeaveRC(vrc);
|
---|
| 1371 | return vrc;
|
---|
[42808] | 1372 | }
|
---|
| 1373 |
|
---|
[55631] | 1374 | int GuestSession::i_fileQuerySizeInternal(const Utf8Str &strPath, bool fFollowSymlinks, int64_t *pllSize, int *pGuestRc)
|
---|
[42808] | 1375 | {
|
---|
| 1376 | AssertPtrReturn(pllSize, VERR_INVALID_POINTER);
|
---|
| 1377 |
|
---|
| 1378 | GuestFsObjData objData;
|
---|
[55631] | 1379 | int vrc = i_fileQueryInfoInternal(strPath, fFollowSymlinks, objData, pGuestRc);
|
---|
[43162] | 1380 | if (RT_SUCCESS(vrc))
|
---|
| 1381 | *pllSize = objData.mObjectSize;
|
---|
[42808] | 1382 |
|
---|
[43162] | 1383 | return vrc;
|
---|
[42808] | 1384 | }
|
---|
| 1385 |
|
---|
[55613] | 1386 | /**
|
---|
[61792] | 1387 | * Queries information of a file system object (file, directory, ...).
|
---|
[55613] | 1388 | *
|
---|
[61792] | 1389 | * @return IPRT status code.
|
---|
| 1390 | * @param strPath Path to file system object to query information for.
|
---|
| 1391 | * @param fFollowSymlinks Whether to follow symbolic links or not.
|
---|
| 1392 | * @param objData Where to return the file system object data, if found.
|
---|
| 1393 | * @param pGuestRc Guest rc, when returning VERR_GSTCTL_GUEST_ERROR.
|
---|
| 1394 | * Any other return code indicates some host side error.
|
---|
[55613] | 1395 | */
|
---|
| 1396 | int GuestSession::i_fsQueryInfoInternal(const Utf8Str &strPath, bool fFollowSymlinks, GuestFsObjData &objData, int *pGuestRc)
|
---|
[42808] | 1397 | {
|
---|
| 1398 | LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
|
---|
| 1399 |
|
---|
[42846] | 1400 | /** @todo Merge this with IGuestFile::queryInfo(). */
|
---|
[42611] | 1401 | GuestProcessStartupInfo procInfo;
|
---|
[56709] | 1402 | procInfo.mFlags = ProcessCreateFlag_WaitForStdOut;
|
---|
[49349] | 1403 | try
|
---|
[42530] | 1404 | {
|
---|
[63156] | 1405 | procInfo.mExecutable = Utf8Str(VBOXSERVICE_TOOL_STAT);
|
---|
[61792] | 1406 | procInfo.mArguments.push_back(procInfo.mExecutable); /* Set argv0. */
|
---|
[49349] | 1407 | procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
|
---|
[55614] | 1408 | if (fFollowSymlinks)
|
---|
| 1409 | procInfo.mArguments.push_back(Utf8Str("-L"));
|
---|
| 1410 | procInfo.mArguments.push_back("--"); /* strPath could be '--help', which is a valid filename. */
|
---|
[49349] | 1411 | procInfo.mArguments.push_back(strPath);
|
---|
[42530] | 1412 | }
|
---|
[49349] | 1413 | catch (std::bad_alloc)
|
---|
| 1414 | {
|
---|
[63156] | 1415 | Log(("Out of memory!\n"));
|
---|
| 1416 | return VERR_NO_MEMORY;
|
---|
[49349] | 1417 | }
|
---|
[42530] | 1418 |
|
---|
[63156] | 1419 | int vrcGuest = VERR_IPE_UNINITIALIZED_STATUS;
|
---|
[55613] | 1420 | GuestCtrlStreamObjects stdOut;
|
---|
[63156] | 1421 | int vrc = GuestProcessTool::i_runEx(this, procInfo,
|
---|
[50709] | 1422 | &stdOut, 1 /* cStrmOutObjects */,
|
---|
[63156] | 1423 | &vrcGuest);
|
---|
[61792] | 1424 | if (!GuestProcess::i_isGuestError(vrc))
|
---|
[45078] | 1425 | {
|
---|
[49349] | 1426 | if (!stdOut.empty())
|
---|
[61792] | 1427 | {
|
---|
[49349] | 1428 | vrc = objData.FromStat(stdOut.at(0));
|
---|
[61792] | 1429 | if (RT_FAILURE(vrc))
|
---|
| 1430 | {
|
---|
[63157] | 1431 | vrcGuest = vrc;
|
---|
[63156] | 1432 | if (pGuestRc)
|
---|
| 1433 | *pGuestRc = vrc;
|
---|
[61792] | 1434 | vrc = VERR_GSTCTL_GUEST_ERROR;
|
---|
| 1435 | }
|
---|
| 1436 | }
|
---|
[49349] | 1437 | else
|
---|
[61792] | 1438 | vrc = VERR_BROKEN_PIPE;
|
---|
[45078] | 1439 | }
|
---|
[61792] | 1440 | else if (pGuestRc)
|
---|
[63156] | 1441 | *pGuestRc = vrcGuest;
|
---|
[49631] | 1442 |
|
---|
[63157] | 1443 | LogFlowThisFunc(("Returning vrc=%Rrc, vrcGuest=%Rrc\n", vrc, vrcGuest));
|
---|
[44863] | 1444 | return vrc;
|
---|
[42530] | 1445 | }
|
---|
| 1446 |
|
---|
[50727] | 1447 | const GuestCredentials& GuestSession::i_getCredentials(void)
|
---|
[42160] | 1448 | {
|
---|
| 1449 | return mData.mCredentials;
|
---|
| 1450 | }
|
---|
| 1451 |
|
---|
[50727] | 1452 | Utf8Str GuestSession::i_getName(void)
|
---|
[42546] | 1453 | {
|
---|
[44935] | 1454 | return mData.mSession.mName;
|
---|
[42546] | 1455 | }
|
---|
| 1456 |
|
---|
[44935] | 1457 | /* static */
|
---|
[50727] | 1458 | Utf8Str GuestSession::i_guestErrorToString(int guestRc)
|
---|
[44935] | 1459 | {
|
---|
| 1460 | Utf8Str strError;
|
---|
| 1461 |
|
---|
| 1462 | /** @todo pData->u32Flags: int vs. uint32 -- IPRT errors are *negative* !!! */
|
---|
| 1463 | switch (guestRc)
|
---|
| 1464 | {
|
---|
| 1465 | case VERR_INVALID_VM_HANDLE:
|
---|
| 1466 | strError += Utf8StrFmt(tr("VMM device is not available (is the VM running?)"));
|
---|
| 1467 | break;
|
---|
| 1468 |
|
---|
| 1469 | case VERR_HGCM_SERVICE_NOT_FOUND:
|
---|
| 1470 | strError += Utf8StrFmt(tr("The guest execution service is not available"));
|
---|
| 1471 | break;
|
---|
| 1472 |
|
---|
[60242] | 1473 | case VERR_ACCOUNT_RESTRICTED:
|
---|
| 1474 | strError += Utf8StrFmt(tr("The specified user account on the guest is restricted and can't be used to logon"));
|
---|
| 1475 | break;
|
---|
| 1476 |
|
---|
[44935] | 1477 | case VERR_AUTHENTICATION_FAILURE:
|
---|
| 1478 | strError += Utf8StrFmt(tr("The specified user was not able to logon on guest"));
|
---|
| 1479 | break;
|
---|
| 1480 |
|
---|
| 1481 | case VERR_TIMEOUT:
|
---|
| 1482 | strError += Utf8StrFmt(tr("The guest did not respond within time"));
|
---|
| 1483 | break;
|
---|
| 1484 |
|
---|
| 1485 | case VERR_CANCELLED:
|
---|
| 1486 | strError += Utf8StrFmt(tr("The session operation was canceled"));
|
---|
| 1487 | break;
|
---|
| 1488 |
|
---|
[57948] | 1489 | case VERR_PERMISSION_DENIED: /** @todo r=bird: This is probably completely and utterly misleading. VERR_AUTHENTICATION_FAILURE could have this message. */
|
---|
[44935] | 1490 | strError += Utf8StrFmt(tr("Invalid user/password credentials"));
|
---|
| 1491 | break;
|
---|
| 1492 |
|
---|
| 1493 | case VERR_MAX_PROCS_REACHED:
|
---|
[45415] | 1494 | strError += Utf8StrFmt(tr("Maximum number of concurrent guest processes has been reached"));
|
---|
[44935] | 1495 | break;
|
---|
| 1496 |
|
---|
| 1497 | case VERR_NOT_FOUND:
|
---|
| 1498 | strError += Utf8StrFmt(tr("The guest execution service is not ready (yet)"));
|
---|
| 1499 | break;
|
---|
| 1500 |
|
---|
| 1501 | default:
|
---|
| 1502 | strError += Utf8StrFmt("%Rrc", guestRc);
|
---|
| 1503 | break;
|
---|
| 1504 | }
|
---|
| 1505 |
|
---|
| 1506 | return strError;
|
---|
| 1507 | }
|
---|
| 1508 |
|
---|
[45415] | 1509 | /**
|
---|
| 1510 | * Checks if this session is ready state where it can handle
|
---|
| 1511 | * all session-bound actions (like guest processes, guest files).
|
---|
| 1512 | * Only used by official API methods. Will set an external
|
---|
| 1513 | * error when not ready.
|
---|
| 1514 | */
|
---|
[50727] | 1515 | HRESULT GuestSession::i_isReadyExternal(void)
|
---|
[45415] | 1516 | {
|
---|
| 1517 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1518 |
|
---|
| 1519 | /** @todo Be a bit more informative. */
|
---|
| 1520 | if (mData.mStatus != GuestSessionStatus_Started)
|
---|
| 1521 | return setError(E_UNEXPECTED, tr("Session is not in started state"));
|
---|
| 1522 |
|
---|
| 1523 | return S_OK;
|
---|
| 1524 | }
|
---|
| 1525 |
|
---|
[49504] | 1526 | /**
|
---|
[49570] | 1527 | * Called by IGuest right before this session gets removed from
|
---|
| 1528 | * the public session list.
|
---|
[49504] | 1529 | */
|
---|
[50727] | 1530 | int GuestSession::i_onRemove(void)
|
---|
[49504] | 1531 | {
|
---|
| 1532 | LogFlowThisFuncEnter();
|
---|
| 1533 |
|
---|
| 1534 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1535 |
|
---|
| 1536 | int vrc = VINF_SUCCESS;
|
---|
| 1537 |
|
---|
[49570] | 1538 | /*
|
---|
[49504] | 1539 | * Note: The event source stuff holds references to this object,
|
---|
| 1540 | * so make sure that this is cleaned up *before* calling uninit.
|
---|
| 1541 | */
|
---|
| 1542 | if (!mEventSource.isNull())
|
---|
| 1543 | {
|
---|
| 1544 | mEventSource->UnregisterListener(mLocalListener);
|
---|
| 1545 |
|
---|
| 1546 | mLocalListener.setNull();
|
---|
| 1547 | unconst(mEventSource).setNull();
|
---|
| 1548 | }
|
---|
| 1549 |
|
---|
| 1550 | LogFlowFuncLeaveRC(vrc);
|
---|
| 1551 | return vrc;
|
---|
| 1552 | }
|
---|
| 1553 |
|
---|
[44863] | 1554 | /** No locking! */
|
---|
[50727] | 1555 | int GuestSession::i_onSessionStatusChange(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData)
|
---|
[44863] | 1556 | {
|
---|
[45415] | 1557 | AssertPtrReturn(pCbCtx, VERR_INVALID_POINTER);
|
---|
[44863] | 1558 | /* pCallback is optional. */
|
---|
| 1559 | AssertPtrReturn(pSvcCbData, VERR_INVALID_POINTER);
|
---|
| 1560 |
|
---|
| 1561 | if (pSvcCbData->mParms < 3)
|
---|
| 1562 | return VERR_INVALID_PARAMETER;
|
---|
| 1563 |
|
---|
| 1564 | CALLBACKDATA_SESSION_NOTIFY dataCb;
|
---|
| 1565 | /* pSvcCb->mpaParms[0] always contains the context ID. */
|
---|
[48342] | 1566 | int vrc = pSvcCbData->mpaParms[1].getUInt32(&dataCb.uType);
|
---|
| 1567 | AssertRCReturn(vrc, vrc);
|
---|
| 1568 | vrc = pSvcCbData->mpaParms[2].getUInt32(&dataCb.uResult);
|
---|
| 1569 | AssertRCReturn(vrc, vrc);
|
---|
[44863] | 1570 |
|
---|
[45415] | 1571 | LogFlowThisFunc(("ID=%RU32, uType=%RU32, guestRc=%Rrc\n",
|
---|
| 1572 | mData.mSession.mID, dataCb.uType, dataCb.uResult));
|
---|
[44863] | 1573 |
|
---|
[45415] | 1574 | GuestSessionStatus_T sessionStatus = GuestSessionStatus_Undefined;
|
---|
| 1575 |
|
---|
[44935] | 1576 | int guestRc = dataCb.uResult; /** @todo uint32_t vs. int. */
|
---|
| 1577 | switch (dataCb.uType)
|
---|
| 1578 | {
|
---|
| 1579 | case GUEST_SESSION_NOTIFYTYPE_ERROR:
|
---|
[45415] | 1580 | sessionStatus = GuestSessionStatus_Error;
|
---|
[44935] | 1581 | break;
|
---|
| 1582 |
|
---|
[45010] | 1583 | case GUEST_SESSION_NOTIFYTYPE_STARTED:
|
---|
[45415] | 1584 | sessionStatus = GuestSessionStatus_Started;
|
---|
[55592] | 1585 | #if 0 /** @todo If we get some environment stuff along with this kind notification: */
|
---|
| 1586 | const char *pszzEnvBlock = ...;
|
---|
| 1587 | uint32_t cbEnvBlock = ...;
|
---|
| 1588 | if (!mData.mpBaseEnvironment)
|
---|
| 1589 | {
|
---|
| 1590 | GuestEnvironment *pBaseEnv;
|
---|
| 1591 | try { pBaseEnv = new GuestEnvironment(); } catch (std::bad_alloc &) { pBaseEnv = NULL; }
|
---|
| 1592 | if (pBaseEnv)
|
---|
| 1593 | {
|
---|
| 1594 | int vrc = pBaseEnv->initNormal();
|
---|
| 1595 | if (RT_SUCCESS(vrc))
|
---|
| 1596 | vrc = pBaseEnv->copyUtf8Block(pszzEnvBlock, cbEnvBlock);
|
---|
| 1597 | if (RT_SUCCESS(vrc))
|
---|
| 1598 | mData.mpBaseEnvironment = pBaseEnv;
|
---|
| 1599 | else
|
---|
| 1600 | pBaseEnv->release();
|
---|
| 1601 | }
|
---|
| 1602 | }
|
---|
| 1603 | #endif
|
---|
[44935] | 1604 | break;
|
---|
| 1605 |
|
---|
[45010] | 1606 | case GUEST_SESSION_NOTIFYTYPE_TEN:
|
---|
| 1607 | case GUEST_SESSION_NOTIFYTYPE_TES:
|
---|
| 1608 | case GUEST_SESSION_NOTIFYTYPE_TEA:
|
---|
[45415] | 1609 | sessionStatus = GuestSessionStatus_Terminated;
|
---|
[44935] | 1610 | break;
|
---|
| 1611 |
|
---|
[45010] | 1612 | case GUEST_SESSION_NOTIFYTYPE_TOK:
|
---|
[45415] | 1613 | sessionStatus = GuestSessionStatus_TimedOutKilled;
|
---|
[45010] | 1614 | break;
|
---|
| 1615 |
|
---|
| 1616 | case GUEST_SESSION_NOTIFYTYPE_TOA:
|
---|
[45415] | 1617 | sessionStatus = GuestSessionStatus_TimedOutAbnormally;
|
---|
[45010] | 1618 | break;
|
---|
| 1619 |
|
---|
| 1620 | case GUEST_SESSION_NOTIFYTYPE_DWN:
|
---|
[45415] | 1621 | sessionStatus = GuestSessionStatus_Down;
|
---|
[45010] | 1622 | break;
|
---|
| 1623 |
|
---|
[45415] | 1624 | case GUEST_SESSION_NOTIFYTYPE_UNDEFINED:
|
---|
[44935] | 1625 | default:
|
---|
| 1626 | vrc = VERR_NOT_SUPPORTED;
|
---|
| 1627 | break;
|
---|
| 1628 | }
|
---|
| 1629 |
|
---|
| 1630 | if (RT_SUCCESS(vrc))
|
---|
| 1631 | {
|
---|
| 1632 | if (RT_FAILURE(guestRc))
|
---|
[45415] | 1633 | sessionStatus = GuestSessionStatus_Error;
|
---|
[44935] | 1634 | }
|
---|
| 1635 |
|
---|
[45415] | 1636 | /* Set the session status. */
|
---|
[47627] | 1637 | if (RT_SUCCESS(vrc))
|
---|
[50727] | 1638 | vrc = i_setSessionStatus(sessionStatus, guestRc);
|
---|
[44863] | 1639 |
|
---|
[45415] | 1640 | LogFlowThisFunc(("ID=%RU32, guestRc=%Rrc\n", mData.mSession.mID, guestRc));
|
---|
[44935] | 1641 |
|
---|
[44863] | 1642 | LogFlowFuncLeaveRC(vrc);
|
---|
| 1643 | return vrc;
|
---|
| 1644 | }
|
---|
| 1645 |
|
---|
[50727] | 1646 | int GuestSession::i_startSessionInternal(int *pGuestRc)
|
---|
[44863] | 1647 | {
|
---|
| 1648 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1649 |
|
---|
[45415] | 1650 | LogFlowThisFunc(("mID=%RU32, mName=%s, uProtocolVersion=%RU32, openFlags=%x, openTimeoutMS=%RU32\n",
|
---|
| 1651 | mData.mSession.mID, mData.mSession.mName.c_str(), mData.mProtocolVersion,
|
---|
| 1652 | mData.mSession.mOpenFlags, mData.mSession.mOpenTimeoutMS));
|
---|
[44863] | 1653 |
|
---|
[47469] | 1654 | /* Guest Additions < 4.3 don't support opening dedicated
|
---|
[44935] | 1655 | guest sessions. Simply return success here. */
|
---|
[44863] | 1656 | if (mData.mProtocolVersion < 2)
|
---|
| 1657 | {
|
---|
[44935] | 1658 | mData.mStatus = GuestSessionStatus_Started;
|
---|
| 1659 |
|
---|
| 1660 | LogFlowThisFunc(("Installed Guest Additions don't support opening dedicated sessions, skipping\n"));
|
---|
[44863] | 1661 | return VINF_SUCCESS;
|
---|
| 1662 | }
|
---|
| 1663 |
|
---|
[45415] | 1664 | if (mData.mStatus != GuestSessionStatus_Undefined)
|
---|
| 1665 | return VINF_SUCCESS;
|
---|
| 1666 |
|
---|
[44935] | 1667 | /** @todo mData.mSession.uFlags validation. */
|
---|
[44863] | 1668 |
|
---|
[44935] | 1669 | /* Set current session status. */
|
---|
| 1670 | mData.mStatus = GuestSessionStatus_Starting;
|
---|
[49349] | 1671 | mData.mRC = VINF_SUCCESS; /* Clear previous error, if any. */
|
---|
[44935] | 1672 |
|
---|
[45780] | 1673 | int vrc;
|
---|
| 1674 |
|
---|
| 1675 | GuestWaitEvent *pEvent = NULL;
|
---|
[49349] | 1676 | GuestEventTypes eventTypes;
|
---|
[45780] | 1677 | try
|
---|
[44863] | 1678 | {
|
---|
[45780] | 1679 | eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
|
---|
[44863] | 1680 |
|
---|
[47469] | 1681 | vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
|
---|
| 1682 | eventTypes, &pEvent);
|
---|
[44863] | 1683 | }
|
---|
[45780] | 1684 | catch (std::bad_alloc)
|
---|
| 1685 | {
|
---|
| 1686 | vrc = VERR_NO_MEMORY;
|
---|
| 1687 | }
|
---|
[44863] | 1688 |
|
---|
[45780] | 1689 | if (RT_FAILURE(vrc))
|
---|
| 1690 | return vrc;
|
---|
| 1691 |
|
---|
| 1692 | VBOXHGCMSVCPARM paParms[8];
|
---|
| 1693 |
|
---|
| 1694 | int i = 0;
|
---|
| 1695 | paParms[i++].setUInt32(pEvent->ContextID());
|
---|
| 1696 | paParms[i++].setUInt32(mData.mProtocolVersion);
|
---|
| 1697 | paParms[i++].setPointer((void*)mData.mCredentials.mUser.c_str(),
|
---|
| 1698 | (ULONG)mData.mCredentials.mUser.length() + 1);
|
---|
| 1699 | paParms[i++].setPointer((void*)mData.mCredentials.mPassword.c_str(),
|
---|
| 1700 | (ULONG)mData.mCredentials.mPassword.length() + 1);
|
---|
| 1701 | paParms[i++].setPointer((void*)mData.mCredentials.mDomain.c_str(),
|
---|
| 1702 | (ULONG)mData.mCredentials.mDomain.length() + 1);
|
---|
| 1703 | paParms[i++].setUInt32(mData.mSession.mOpenFlags);
|
---|
| 1704 |
|
---|
[47627] | 1705 | alock.release(); /* Drop write lock before sending. */
|
---|
| 1706 |
|
---|
[50727] | 1707 | vrc = i_sendCommand(HOST_SESSION_CREATE, i, paParms);
|
---|
[44863] | 1708 | if (RT_SUCCESS(vrc))
|
---|
[49349] | 1709 | {
|
---|
[50727] | 1710 | vrc = i_waitForStatusChange(pEvent, GuestSessionWaitForFlag_Start,
|
---|
| 1711 | 30 * 1000 /* 30s timeout */,
|
---|
| 1712 | NULL /* Session status */, pGuestRc);
|
---|
[49349] | 1713 | }
|
---|
| 1714 | else
|
---|
| 1715 | {
|
---|
| 1716 | /*
|
---|
| 1717 | * Unable to start guest session - update its current state.
|
---|
| 1718 | * Since there is no (official API) way to recover a failed guest session
|
---|
| 1719 | * this also marks the end state. Internally just calling this
|
---|
| 1720 | * same function again will work though.
|
---|
| 1721 | */
|
---|
| 1722 | mData.mStatus = GuestSessionStatus_Error;
|
---|
| 1723 | mData.mRC = vrc;
|
---|
| 1724 | }
|
---|
[44863] | 1725 |
|
---|
[47469] | 1726 | unregisterWaitEvent(pEvent);
|
---|
[45780] | 1727 |
|
---|
[44863] | 1728 | LogFlowFuncLeaveRC(vrc);
|
---|
| 1729 | return vrc;
|
---|
| 1730 | }
|
---|
| 1731 |
|
---|
[50727] | 1732 | int GuestSession::i_startSessionAsync(void)
|
---|
[44935] | 1733 | {
|
---|
| 1734 | LogFlowThisFuncEnter();
|
---|
| 1735 |
|
---|
[63250] | 1736 | int vrc;
|
---|
[58521] | 1737 | GuestSessionTaskInternalOpen* pTask = NULL;
|
---|
[44935] | 1738 | try
|
---|
| 1739 | {
|
---|
[58521] | 1740 | pTask = new GuestSessionTaskInternalOpen(this);
|
---|
| 1741 | if (!pTask->isOk())
|
---|
| 1742 | {
|
---|
| 1743 | delete pTask;
|
---|
[58552] | 1744 | LogFlow(("GuestSession: Could not create GuestSessionTaskInternalOpen object \n"));
|
---|
| 1745 | throw VERR_MEMOBJ_INIT_FAILED;
|
---|
[58521] | 1746 | }
|
---|
| 1747 |
|
---|
[44935] | 1748 | /* Asynchronously open the session on the guest by kicking off a
|
---|
| 1749 | * worker thread. */
|
---|
[58521] | 1750 | //this function delete pTask in case of exceptions, so there is no need in the call of delete operator
|
---|
[62379] | 1751 | HRESULT hrc = pTask->createThread();
|
---|
[63250] | 1752 | vrc = Global::vboxStatusCodeFromCOM(hrc);
|
---|
[44935] | 1753 | }
|
---|
| 1754 | catch(std::bad_alloc &)
|
---|
| 1755 | {
|
---|
| 1756 | vrc = VERR_NO_MEMORY;
|
---|
| 1757 | }
|
---|
[58552] | 1758 | catch(int eVRC)
|
---|
[58521] | 1759 | {
|
---|
[58552] | 1760 | vrc = eVRC;
|
---|
| 1761 | LogFlow(("GuestSession: Could not create thread for GuestSessionTaskInternalOpen task %Rrc\n", vrc));
|
---|
[58521] | 1762 | }
|
---|
[44935] | 1763 |
|
---|
| 1764 | LogFlowFuncLeaveRC(vrc);
|
---|
| 1765 | return vrc;
|
---|
| 1766 | }
|
---|
| 1767 |
|
---|
| 1768 | /* static */
|
---|
[63186] | 1769 | void GuestSession::i_startSessionThreadTask(GuestSessionTaskInternalOpen *pTask)
|
---|
[44935] | 1770 | {
|
---|
[63186] | 1771 | LogFlowFunc(("pTask=%p\n", pTask));
|
---|
[58521] | 1772 | AssertPtr(pTask);
|
---|
| 1773 |
|
---|
[44935] | 1774 | const ComObjPtr<GuestSession> pSession(pTask->Session());
|
---|
| 1775 | Assert(!pSession.isNull());
|
---|
| 1776 |
|
---|
| 1777 | AutoCaller autoCaller(pSession);
|
---|
[63186] | 1778 | if (FAILED(autoCaller.rc()))
|
---|
| 1779 | return;
|
---|
[44935] | 1780 |
|
---|
[50727] | 1781 | int vrc = pSession->i_startSessionInternal(NULL /* Guest rc, ignored */);
|
---|
[63186] | 1782 | /** @todo
|
---|
| 1783 | *
|
---|
| 1784 | * r=bird: Is it okay to ignore @a vrc here?
|
---|
| 1785 | *
|
---|
| 1786 | */
|
---|
| 1787 |
|
---|
[44935] | 1788 | /* Nothing to do here anymore. */
|
---|
| 1789 |
|
---|
| 1790 | LogFlowFuncLeaveRC(vrc);
|
---|
[63186] | 1791 | NOREF(vrc);
|
---|
[44935] | 1792 | }
|
---|
| 1793 |
|
---|
[50727] | 1794 | int GuestSession::i_pathRenameInternal(const Utf8Str &strSource, const Utf8Str &strDest,
|
---|
[49349] | 1795 | uint32_t uFlags, int *pGuestRc)
|
---|
| 1796 | {
|
---|
| 1797 | AssertReturn(!(uFlags & ~PATHRENAME_FLAG_VALID_MASK), VERR_INVALID_PARAMETER);
|
---|
| 1798 |
|
---|
| 1799 | LogFlowThisFunc(("strSource=%s, strDest=%s, uFlags=0x%x\n",
|
---|
| 1800 | strSource.c_str(), strDest.c_str(), uFlags));
|
---|
| 1801 |
|
---|
| 1802 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1803 |
|
---|
| 1804 | GuestWaitEvent *pEvent = NULL;
|
---|
| 1805 | int vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
|
---|
| 1806 | &pEvent);
|
---|
| 1807 | if (RT_FAILURE(vrc))
|
---|
| 1808 | return vrc;
|
---|
| 1809 |
|
---|
| 1810 | /* Prepare HGCM call. */
|
---|
| 1811 | VBOXHGCMSVCPARM paParms[8];
|
---|
| 1812 | int i = 0;
|
---|
| 1813 | paParms[i++].setUInt32(pEvent->ContextID());
|
---|
| 1814 | paParms[i++].setPointer((void*)strSource.c_str(),
|
---|
| 1815 | (ULONG)strSource.length() + 1);
|
---|
| 1816 | paParms[i++].setPointer((void*)strDest.c_str(),
|
---|
| 1817 | (ULONG)strDest.length() + 1);
|
---|
| 1818 | paParms[i++].setUInt32(uFlags);
|
---|
| 1819 |
|
---|
| 1820 | alock.release(); /* Drop write lock before sending. */
|
---|
| 1821 |
|
---|
[50727] | 1822 | vrc = i_sendCommand(HOST_PATH_RENAME, i, paParms);
|
---|
[49349] | 1823 | if (RT_SUCCESS(vrc))
|
---|
| 1824 | {
|
---|
| 1825 | vrc = pEvent->Wait(30 * 1000);
|
---|
| 1826 | if ( vrc == VERR_GSTCTL_GUEST_ERROR
|
---|
| 1827 | && pGuestRc)
|
---|
| 1828 | *pGuestRc = pEvent->GuestResult();
|
---|
| 1829 | }
|
---|
| 1830 |
|
---|
| 1831 | unregisterWaitEvent(pEvent);
|
---|
| 1832 |
|
---|
| 1833 | LogFlowFuncLeaveRC(vrc);
|
---|
| 1834 | return vrc;
|
---|
| 1835 | }
|
---|
| 1836 |
|
---|
[50727] | 1837 | int GuestSession::i_processRemoveFromList(GuestProcess *pProcess)
|
---|
[42105] | 1838 | {
|
---|
[45415] | 1839 | AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
|
---|
[42897] | 1840 |
|
---|
[45415] | 1841 | LogFlowThisFunc(("pProcess=%p\n", pProcess));
|
---|
| 1842 |
|
---|
[42105] | 1843 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1844 |
|
---|
[42897] | 1845 | int rc = VERR_NOT_FOUND;
|
---|
| 1846 |
|
---|
| 1847 | ULONG uPID;
|
---|
| 1848 | HRESULT hr = pProcess->COMGETTER(PID)(&uPID);
|
---|
[45415] | 1849 | ComAssertComRC(hr);
|
---|
[42897] | 1850 |
|
---|
[49504] | 1851 | LogFlowFunc(("Removing process (PID=%RU32) ...\n", uPID));
|
---|
[42897] | 1852 |
|
---|
[45415] | 1853 | SessionProcesses::iterator itProcs = mData.mProcesses.begin();
|
---|
| 1854 | while (itProcs != mData.mProcesses.end())
|
---|
[42105] | 1855 | {
|
---|
[42160] | 1856 | if (pProcess == itProcs->second)
|
---|
[42105] | 1857 | {
|
---|
[49504] | 1858 | #ifdef DEBUG_andy
|
---|
| 1859 | ULONG cRefs = pProcess->AddRef();
|
---|
| 1860 | Assert(cRefs >= 2);
|
---|
| 1861 | LogFlowFunc(("pProcess=%p, cRefs=%RU32\n", pProcess, cRefs - 1));
|
---|
| 1862 | pProcess->Release();
|
---|
| 1863 | #endif
|
---|
| 1864 | /* Make sure to consume the pointer before the one of the
|
---|
[47627] | 1865 | * iterator gets released. */
|
---|
[49504] | 1866 | ComObjPtr<GuestProcess> pProc = pProcess;
|
---|
[42634] | 1867 |
|
---|
[49504] | 1868 | hr = pProc->COMGETTER(PID)(&uPID);
|
---|
[42897] | 1869 | ComAssertComRC(hr);
|
---|
| 1870 |
|
---|
[49504] | 1871 | Assert(mData.mProcesses.size());
|
---|
[42897] | 1872 | Assert(mData.mNumObjects);
|
---|
[49504] | 1873 | LogFlowFunc(("Removing process ID=%RU32 (Session: %RU32), guest PID=%RU32 (now total %zu processes, %RU32 objects)\n",
|
---|
[47627] | 1874 | pProcess->getObjectID(), mData.mSession.mID, uPID, mData.mProcesses.size() - 1, mData.mNumObjects - 1));
|
---|
[42897] | 1875 |
|
---|
[50618] | 1876 | rc = pProcess->i_onRemove();
|
---|
[42160] | 1877 | mData.mProcesses.erase(itProcs);
|
---|
[42897] | 1878 | mData.mNumObjects--;
|
---|
| 1879 |
|
---|
[47627] | 1880 | alock.release(); /* Release lock before firing off event. */
|
---|
| 1881 |
|
---|
[49504] | 1882 | fireGuestProcessRegisteredEvent(mEventSource, this /* Session */, pProc,
|
---|
[45415] | 1883 | uPID, false /* Process unregistered */);
|
---|
[49504] | 1884 | pProc.setNull();
|
---|
[42897] | 1885 | break;
|
---|
[42105] | 1886 | }
|
---|
[45415] | 1887 |
|
---|
[56030] | 1888 | ++itProcs;
|
---|
[42105] | 1889 | }
|
---|
| 1890 |
|
---|
[42897] | 1891 | LogFlowFuncLeaveRC(rc);
|
---|
| 1892 | return rc;
|
---|
[42105] | 1893 | }
|
---|
| 1894 |
|
---|
[42611] | 1895 | /**
|
---|
[55535] | 1896 | * Creates but does *not* start the process yet.
|
---|
[42611] | 1897 | *
|
---|
[55535] | 1898 | * See GuestProcess::startProcess() or GuestProcess::startProcessAsync() for
|
---|
| 1899 | * starting the process.
|
---|
| 1900 | *
|
---|
[42611] | 1901 | * @return IPRT status code.
|
---|
| 1902 | * @param procInfo
|
---|
| 1903 | * @param pProcess
|
---|
| 1904 | */
|
---|
[55535] | 1905 | int GuestSession::i_processCreateExInternal(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProcess)
|
---|
[42105] | 1906 | {
|
---|
[55535] | 1907 | LogFlowFunc(("mExe=%s, mFlags=%x, mTimeoutMS=%RU32\n",
|
---|
| 1908 | procInfo.mExecutable.c_str(), procInfo.mFlags, procInfo.mTimeoutMS));
|
---|
[42611] | 1909 | #ifdef DEBUG
|
---|
| 1910 | if (procInfo.mArguments.size())
|
---|
| 1911 | {
|
---|
| 1912 | LogFlowFunc(("Arguments:"));
|
---|
| 1913 | ProcessArguments::const_iterator it = procInfo.mArguments.begin();
|
---|
| 1914 | while (it != procInfo.mArguments.end())
|
---|
| 1915 | {
|
---|
| 1916 | LogFlow((" %s", (*it).c_str()));
|
---|
[55769] | 1917 | ++it;
|
---|
[42611] | 1918 | }
|
---|
| 1919 | LogFlow(("\n"));
|
---|
| 1920 | }
|
---|
| 1921 | #endif
|
---|
[42436] | 1922 |
|
---|
[42105] | 1923 | /* Validate flags. */
|
---|
[42354] | 1924 | if (procInfo.mFlags)
|
---|
[42105] | 1925 | {
|
---|
[42354] | 1926 | if ( !(procInfo.mFlags & ProcessCreateFlag_IgnoreOrphanedProcesses)
|
---|
| 1927 | && !(procInfo.mFlags & ProcessCreateFlag_WaitForProcessStartOnly)
|
---|
| 1928 | && !(procInfo.mFlags & ProcessCreateFlag_Hidden)
|
---|
[61893] | 1929 | && !(procInfo.mFlags & ProcessCreateFlag_Profile)
|
---|
[42411] | 1930 | && !(procInfo.mFlags & ProcessCreateFlag_WaitForStdOut)
|
---|
| 1931 | && !(procInfo.mFlags & ProcessCreateFlag_WaitForStdErr))
|
---|
[42105] | 1932 | {
|
---|
| 1933 | return VERR_INVALID_PARAMETER;
|
---|
| 1934 | }
|
---|
| 1935 | }
|
---|
| 1936 |
|
---|
[43981] | 1937 | if ( (procInfo.mFlags & ProcessCreateFlag_WaitForProcessStartOnly)
|
---|
| 1938 | && ( (procInfo.mFlags & ProcessCreateFlag_WaitForStdOut)
|
---|
| 1939 | || (procInfo.mFlags & ProcessCreateFlag_WaitForStdErr)
|
---|
| 1940 | )
|
---|
| 1941 | )
|
---|
| 1942 | {
|
---|
| 1943 | return VERR_INVALID_PARAMETER;
|
---|
| 1944 | }
|
---|
| 1945 |
|
---|
[60622] | 1946 | /* Adjust timeout.
|
---|
| 1947 | * If set to 0, we define an infinite timeout (unlimited process run time). */
|
---|
[42272] | 1948 | if (procInfo.mTimeoutMS == 0)
|
---|
| 1949 | procInfo.mTimeoutMS = UINT32_MAX;
|
---|
[42105] | 1950 |
|
---|
[65120] | 1951 | /** @todo Implement process priority + affinity. */
|
---|
[42105] | 1952 |
|
---|
[42436] | 1953 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1954 |
|
---|
[42272] | 1955 | int rc = VERR_MAX_PROCS_REACHED;
|
---|
[42897] | 1956 | if (mData.mNumObjects >= VBOX_GUESTCTRL_MAX_OBJECTS)
|
---|
[42272] | 1957 | return rc;
|
---|
[42160] | 1958 |
|
---|
| 1959 | /* Create a new (host-based) process ID and assign it. */
|
---|
[42634] | 1960 | uint32_t uNewProcessID = 0;
|
---|
[42214] | 1961 | ULONG uTries = 0;
|
---|
[42160] | 1962 |
|
---|
| 1963 | for (;;)
|
---|
| 1964 | {
|
---|
[42272] | 1965 | /* Is the context ID already used? */
|
---|
[50727] | 1966 | if (!i_processExists(uNewProcessID, NULL /* pProcess */))
|
---|
[42160] | 1967 | {
|
---|
| 1968 | /* Callback with context ID was not found. This means
|
---|
| 1969 | * we can use this context ID for our new callback we want
|
---|
| 1970 | * to add below. */
|
---|
| 1971 | rc = VINF_SUCCESS;
|
---|
| 1972 | break;
|
---|
| 1973 | }
|
---|
[42634] | 1974 | uNewProcessID++;
|
---|
[42897] | 1975 | if (uNewProcessID == VBOX_GUESTCTRL_MAX_OBJECTS)
|
---|
[42634] | 1976 | uNewProcessID = 0;
|
---|
[42160] | 1977 |
|
---|
[44935] | 1978 | if (++uTries == VBOX_GUESTCTRL_MAX_OBJECTS)
|
---|
[42160] | 1979 | break; /* Don't try too hard. */
|
---|
| 1980 | }
|
---|
| 1981 |
|
---|
[42693] | 1982 | if (RT_FAILURE(rc))
|
---|
| 1983 | return rc;
|
---|
[42105] | 1984 |
|
---|
[42693] | 1985 | /* Create the process object. */
|
---|
| 1986 | HRESULT hr = pProcess.createObject();
|
---|
| 1987 | if (FAILED(hr))
|
---|
| 1988 | return VERR_COM_UNEXPECTED;
|
---|
[42105] | 1989 |
|
---|
[52082] | 1990 | rc = pProcess->init(mParent->i_getConsole() /* Console */, this /* Session */,
|
---|
[55591] | 1991 | uNewProcessID, procInfo, mData.mpBaseEnvironment);
|
---|
[42693] | 1992 | if (RT_FAILURE(rc))
|
---|
| 1993 | return rc;
|
---|
[42436] | 1994 |
|
---|
[42693] | 1995 | /* Add the created process to our map. */
|
---|
[47781] | 1996 | try
|
---|
| 1997 | {
|
---|
| 1998 | mData.mProcesses[uNewProcessID] = pProcess;
|
---|
| 1999 | mData.mNumObjects++;
|
---|
| 2000 | Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
|
---|
[42105] | 2001 |
|
---|
[49619] | 2002 | LogFlowFunc(("Added new process (Session: %RU32) with process ID=%RU32 (now total %zu processes, %RU32 objects)\n",
|
---|
[47781] | 2003 | mData.mSession.mID, uNewProcessID, mData.mProcesses.size(), mData.mNumObjects));
|
---|
[45415] | 2004 |
|
---|
[49504] | 2005 | alock.release(); /* Release lock before firing off event. */
|
---|
| 2006 |
|
---|
[47781] | 2007 | fireGuestProcessRegisteredEvent(mEventSource, this /* Session */, pProcess,
|
---|
| 2008 | 0 /* PID */, true /* Process registered */);
|
---|
| 2009 | }
|
---|
| 2010 | catch (std::bad_alloc &)
|
---|
| 2011 | {
|
---|
| 2012 | rc = VERR_NO_MEMORY;
|
---|
| 2013 | }
|
---|
[42693] | 2014 |
|
---|
[42105] | 2015 | return rc;
|
---|
[42160] | 2016 | }
|
---|
[42105] | 2017 |
|
---|
[50727] | 2018 | inline bool GuestSession::i_processExists(uint32_t uProcessID, ComObjPtr<GuestProcess> *pProcess)
|
---|
[42160] | 2019 | {
|
---|
[42214] | 2020 | SessionProcesses::const_iterator it = mData.mProcesses.find(uProcessID);
|
---|
| 2021 | if (it != mData.mProcesses.end())
|
---|
| 2022 | {
|
---|
| 2023 | if (pProcess)
|
---|
| 2024 | *pProcess = it->second;
|
---|
| 2025 | return true;
|
---|
| 2026 | }
|
---|
| 2027 | return false;
|
---|
[42105] | 2028 | }
|
---|
| 2029 |
|
---|
[50727] | 2030 | inline int GuestSession::i_processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess)
|
---|
[42214] | 2031 | {
|
---|
| 2032 | AssertReturn(uPID, false);
|
---|
| 2033 | /* pProcess is optional. */
|
---|
| 2034 |
|
---|
[42897] | 2035 | SessionProcesses::iterator itProcs = mData.mProcesses.begin();
|
---|
[56030] | 2036 | for (; itProcs != mData.mProcesses.end(); ++itProcs)
|
---|
[42214] | 2037 | {
|
---|
[42897] | 2038 | ComObjPtr<GuestProcess> pCurProc = itProcs->second;
|
---|
[42214] | 2039 | AutoCaller procCaller(pCurProc);
|
---|
| 2040 | if (procCaller.rc())
|
---|
| 2041 | return VERR_COM_INVALID_OBJECT_STATE;
|
---|
| 2042 |
|
---|
[42897] | 2043 | ULONG uCurPID;
|
---|
| 2044 | HRESULT hr = pCurProc->COMGETTER(PID)(&uCurPID);
|
---|
| 2045 | ComAssertComRC(hr);
|
---|
| 2046 |
|
---|
| 2047 | if (uCurPID == uPID)
|
---|
[42214] | 2048 | {
|
---|
| 2049 | if (pProcess)
|
---|
| 2050 | *pProcess = pCurProc;
|
---|
| 2051 | return VINF_SUCCESS;
|
---|
| 2052 | }
|
---|
| 2053 | }
|
---|
| 2054 |
|
---|
| 2055 | return VERR_NOT_FOUND;
|
---|
| 2056 | }
|
---|
| 2057 |
|
---|
[50727] | 2058 | int GuestSession::i_sendCommand(uint32_t uFunction,
|
---|
| 2059 | uint32_t uParms, PVBOXHGCMSVCPARM paParms)
|
---|
[44863] | 2060 | {
|
---|
| 2061 | LogFlowThisFuncEnter();
|
---|
| 2062 |
|
---|
| 2063 | #ifndef VBOX_GUESTCTRL_TEST_CASE
|
---|
[52082] | 2064 | ComObjPtr<Console> pConsole = mParent->i_getConsole();
|
---|
[44863] | 2065 | Assert(!pConsole.isNull());
|
---|
| 2066 |
|
---|
| 2067 | /* Forward the information to the VMM device. */
|
---|
[51612] | 2068 | VMMDev *pVMMDev = pConsole->i_getVMMDev();
|
---|
[44863] | 2069 | AssertPtr(pVMMDev);
|
---|
| 2070 |
|
---|
| 2071 | LogFlowThisFunc(("uFunction=%RU32, uParms=%RU32\n", uFunction, uParms));
|
---|
| 2072 | int vrc = pVMMDev->hgcmHostCall(HGCMSERVICE_NAME, uFunction, uParms, paParms);
|
---|
| 2073 | if (RT_FAILURE(vrc))
|
---|
| 2074 | {
|
---|
| 2075 | /** @todo What to do here? */
|
---|
| 2076 | }
|
---|
| 2077 | #else
|
---|
| 2078 | /* Not needed within testcases. */
|
---|
| 2079 | int vrc = VINF_SUCCESS;
|
---|
| 2080 | #endif
|
---|
| 2081 | LogFlowFuncLeaveRC(vrc);
|
---|
| 2082 | return vrc;
|
---|
| 2083 | }
|
---|
| 2084 |
|
---|
[44935] | 2085 | /* static */
|
---|
[50727] | 2086 | HRESULT GuestSession::i_setErrorExternal(VirtualBoxBase *pInterface, int guestRc)
|
---|
[44935] | 2087 | {
|
---|
| 2088 | AssertPtr(pInterface);
|
---|
| 2089 | AssertMsg(RT_FAILURE(guestRc), ("Guest rc does not indicate a failure when setting error\n"));
|
---|
| 2090 |
|
---|
[50727] | 2091 | return pInterface->setError(VBOX_E_IPRT_ERROR, GuestSession::i_guestErrorToString(guestRc).c_str());
|
---|
[44935] | 2092 | }
|
---|
| 2093 |
|
---|
[45415] | 2094 | /* Does not do locking; caller is responsible for that! */
|
---|
[50727] | 2095 | int GuestSession::i_setSessionStatus(GuestSessionStatus_T sessionStatus, int sessionRc)
|
---|
[45415] | 2096 | {
|
---|
[49504] | 2097 | LogFlowThisFunc(("oldStatus=%RU32, newStatus=%RU32, sessionRc=%Rrc\n",
|
---|
[45415] | 2098 | mData.mStatus, sessionStatus, sessionRc));
|
---|
| 2099 |
|
---|
| 2100 | if (sessionStatus == GuestSessionStatus_Error)
|
---|
| 2101 | {
|
---|
| 2102 | AssertMsg(RT_FAILURE(sessionRc), ("Guest rc must be an error (%Rrc)\n", sessionRc));
|
---|
| 2103 | /* Do not allow overwriting an already set error. If this happens
|
---|
| 2104 | * this means we forgot some error checking/locking somewhere. */
|
---|
| 2105 | AssertMsg(RT_SUCCESS(mData.mRC), ("Guest rc already set (to %Rrc)\n", mData.mRC));
|
---|
| 2106 | }
|
---|
| 2107 | else
|
---|
| 2108 | AssertMsg(RT_SUCCESS(sessionRc), ("Guest rc must not be an error (%Rrc)\n", sessionRc));
|
---|
| 2109 |
|
---|
| 2110 | if (mData.mStatus != sessionStatus)
|
---|
| 2111 | {
|
---|
| 2112 | mData.mStatus = sessionStatus;
|
---|
| 2113 | mData.mRC = sessionRc;
|
---|
| 2114 |
|
---|
[45805] | 2115 | ComObjPtr<VirtualBoxErrorInfo> errorInfo;
|
---|
[45415] | 2116 | HRESULT hr = errorInfo.createObject();
|
---|
| 2117 | ComAssertComRC(hr);
|
---|
[45805] | 2118 | int rc2 = errorInfo->initEx(VBOX_E_IPRT_ERROR, sessionRc,
|
---|
| 2119 | COM_IIDOF(IGuestSession), getComponentName(),
|
---|
[50727] | 2120 | i_guestErrorToString(sessionRc));
|
---|
[45415] | 2121 | AssertRC(rc2);
|
---|
| 2122 |
|
---|
| 2123 | fireGuestSessionStateChangedEvent(mEventSource, this,
|
---|
| 2124 | mData.mSession.mID, sessionStatus, errorInfo);
|
---|
| 2125 | }
|
---|
| 2126 |
|
---|
| 2127 | return VINF_SUCCESS;
|
---|
| 2128 | }
|
---|
| 2129 |
|
---|
[50727] | 2130 | int GuestSession::i_signalWaiters(GuestSessionWaitResult_T enmWaitResult, int rc /*= VINF_SUCCESS */)
|
---|
[45415] | 2131 | {
|
---|
[63251] | 2132 | RT_NOREF(enmWaitResult, rc);
|
---|
| 2133 |
|
---|
[45415] | 2134 | /*LogFlowThisFunc(("enmWaitResult=%d, rc=%Rrc, mWaitCount=%RU32, mWaitEvent=%p\n",
|
---|
| 2135 | enmWaitResult, rc, mData.mWaitCount, mData.mWaitEvent));*/
|
---|
| 2136 |
|
---|
| 2137 | /* Note: No write locking here -- already done in the caller. */
|
---|
| 2138 |
|
---|
| 2139 | int vrc = VINF_SUCCESS;
|
---|
| 2140 | /*if (mData.mWaitEvent)
|
---|
| 2141 | vrc = mData.mWaitEvent->Signal(enmWaitResult, rc);*/
|
---|
| 2142 | LogFlowFuncLeaveRC(vrc);
|
---|
| 2143 | return vrc;
|
---|
| 2144 | }
|
---|
| 2145 |
|
---|
[42461] | 2146 | /**
|
---|
[55588] | 2147 | * Determines the protocol version (sets mData.mProtocolVersion).
|
---|
[42461] | 2148 | *
|
---|
[55588] | 2149 | * This is called from the init method prior to to establishing a guest
|
---|
| 2150 | * session.
|
---|
| 2151 | *
|
---|
[42461] | 2152 | * @return IPRT status code.
|
---|
| 2153 | */
|
---|
[55588] | 2154 | int GuestSession::i_determineProtocolVersion(void)
|
---|
[42461] | 2155 | {
|
---|
| 2156 | /*
|
---|
[55588] | 2157 | * We currently do this based on the reported guest additions version,
|
---|
| 2158 | * ASSUMING that VBoxService and VBoxDrv are at the same version.
|
---|
[42461] | 2159 | */
|
---|
[45415] | 2160 | ComObjPtr<Guest> pGuest = mParent;
|
---|
[55588] | 2161 | AssertReturn(!pGuest.isNull(), VERR_NOT_SUPPORTED);
|
---|
| 2162 | uint32_t uGaVersion = pGuest->i_getAdditionsVersion();
|
---|
[42461] | 2163 |
|
---|
[55588] | 2164 | /* Everyone supports version one, if they support anything at all. */
|
---|
| 2165 | mData.mProtocolVersion = 1;
|
---|
[47469] | 2166 |
|
---|
[55588] | 2167 | /* Guest control 2.0 was introduced with 4.3.0. */
|
---|
| 2168 | if (uGaVersion >= VBOX_FULL_VERSION_MAKE(4,3,0))
|
---|
| 2169 | mData.mProtocolVersion = 2; /* Guest control 2.0. */
|
---|
[42461] | 2170 |
|
---|
[55588] | 2171 | LogFlowThisFunc(("uGaVersion=%u.%u.%u => mProtocolVersion=%u\n",
|
---|
| 2172 | VBOX_FULL_VERSION_GET_MAJOR(uGaVersion), VBOX_FULL_VERSION_GET_MINOR(uGaVersion),
|
---|
| 2173 | VBOX_FULL_VERSION_GET_BUILD(uGaVersion), mData.mProtocolVersion));
|
---|
[47469] | 2174 |
|
---|
[55588] | 2175 | /*
|
---|
| 2176 | * Inform the user about outdated guest additions (VM release log).
|
---|
| 2177 | */
|
---|
[54009] | 2178 | if (mData.mProtocolVersion < 2)
|
---|
[55588] | 2179 | LogRelMax(3, (tr("Warning: Guest Additions v%u.%u.%u only supports the older guest control protocol version %u.\n"
|
---|
| 2180 | " Please upgrade GAs to the current version to get full guest control capabilities.\n"),
|
---|
| 2181 | VBOX_FULL_VERSION_GET_MAJOR(uGaVersion), VBOX_FULL_VERSION_GET_MINOR(uGaVersion),
|
---|
| 2182 | VBOX_FULL_VERSION_GET_BUILD(uGaVersion), mData.mProtocolVersion));
|
---|
[50899] | 2183 |
|
---|
[42461] | 2184 | return VINF_SUCCESS;
|
---|
| 2185 | }
|
---|
| 2186 |
|
---|
[50727] | 2187 | int GuestSession::i_waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, GuestSessionWaitResult_T &waitResult, int *pGuestRc)
|
---|
[45010] | 2188 | {
|
---|
| 2189 | LogFlowThisFuncEnter();
|
---|
| 2190 |
|
---|
| 2191 | AssertReturn(fWaitFlags, VERR_INVALID_PARAMETER);
|
---|
| 2192 |
|
---|
[45415] | 2193 | /*LogFlowThisFunc(("fWaitFlags=0x%x, uTimeoutMS=%RU32, mStatus=%RU32, mWaitCount=%RU32, mWaitEvent=%p, pGuestRc=%p\n",
|
---|
| 2194 | fWaitFlags, uTimeoutMS, mData.mStatus, mData.mWaitCount, mData.mWaitEvent, pGuestRc));*/
|
---|
[45010] | 2195 |
|
---|
[47469] | 2196 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[45010] | 2197 |
|
---|
| 2198 | /* Did some error occur before? Then skip waiting and return. */
|
---|
| 2199 | if (mData.mStatus == GuestSessionStatus_Error)
|
---|
| 2200 | {
|
---|
| 2201 | waitResult = GuestSessionWaitResult_Error;
|
---|
| 2202 | AssertMsg(RT_FAILURE(mData.mRC), ("No error rc (%Rrc) set when guest session indicated an error\n", mData.mRC));
|
---|
| 2203 | if (pGuestRc)
|
---|
| 2204 | *pGuestRc = mData.mRC; /* Return last set error. */
|
---|
[45078] | 2205 | return VERR_GSTCTL_GUEST_ERROR;
|
---|
[45010] | 2206 | }
|
---|
| 2207 |
|
---|
[47469] | 2208 | /* Guest Additions < 4.3 don't support session handling, skip. */
|
---|
| 2209 | if (mData.mProtocolVersion < 2)
|
---|
| 2210 | {
|
---|
| 2211 | waitResult = GuestSessionWaitResult_WaitFlagNotSupported;
|
---|
| 2212 |
|
---|
| 2213 | LogFlowThisFunc(("Installed Guest Additions don't support waiting for dedicated sessions, skipping\n"));
|
---|
| 2214 | return VINF_SUCCESS;
|
---|
| 2215 | }
|
---|
| 2216 |
|
---|
[45010] | 2217 | waitResult = GuestSessionWaitResult_None;
|
---|
| 2218 | if (fWaitFlags & GuestSessionWaitForFlag_Terminate)
|
---|
| 2219 | {
|
---|
| 2220 | switch (mData.mStatus)
|
---|
| 2221 | {
|
---|
| 2222 | case GuestSessionStatus_Terminated:
|
---|
| 2223 | case GuestSessionStatus_Down:
|
---|
| 2224 | waitResult = GuestSessionWaitResult_Terminate;
|
---|
| 2225 | break;
|
---|
| 2226 |
|
---|
| 2227 | case GuestSessionStatus_TimedOutKilled:
|
---|
| 2228 | case GuestSessionStatus_TimedOutAbnormally:
|
---|
| 2229 | waitResult = GuestSessionWaitResult_Timeout;
|
---|
| 2230 | break;
|
---|
| 2231 |
|
---|
| 2232 | case GuestSessionStatus_Error:
|
---|
| 2233 | /* Handled above. */
|
---|
| 2234 | break;
|
---|
| 2235 |
|
---|
| 2236 | case GuestSessionStatus_Started:
|
---|
| 2237 | waitResult = GuestSessionWaitResult_Start;
|
---|
| 2238 | break;
|
---|
| 2239 |
|
---|
| 2240 | case GuestSessionStatus_Undefined:
|
---|
| 2241 | case GuestSessionStatus_Starting:
|
---|
| 2242 | /* Do the waiting below. */
|
---|
| 2243 | break;
|
---|
| 2244 |
|
---|
| 2245 | default:
|
---|
[49504] | 2246 | AssertMsgFailed(("Unhandled session status %RU32\n", mData.mStatus));
|
---|
[45010] | 2247 | return VERR_NOT_IMPLEMENTED;
|
---|
| 2248 | }
|
---|
| 2249 | }
|
---|
| 2250 | else if (fWaitFlags & GuestSessionWaitForFlag_Start)
|
---|
| 2251 | {
|
---|
| 2252 | switch (mData.mStatus)
|
---|
| 2253 | {
|
---|
| 2254 | case GuestSessionStatus_Started:
|
---|
| 2255 | case GuestSessionStatus_Terminating:
|
---|
| 2256 | case GuestSessionStatus_Terminated:
|
---|
| 2257 | case GuestSessionStatus_Down:
|
---|
| 2258 | waitResult = GuestSessionWaitResult_Start;
|
---|
| 2259 | break;
|
---|
| 2260 |
|
---|
| 2261 | case GuestSessionStatus_Error:
|
---|
| 2262 | waitResult = GuestSessionWaitResult_Error;
|
---|
| 2263 | break;
|
---|
| 2264 |
|
---|
| 2265 | case GuestSessionStatus_TimedOutKilled:
|
---|
| 2266 | case GuestSessionStatus_TimedOutAbnormally:
|
---|
| 2267 | waitResult = GuestSessionWaitResult_Timeout;
|
---|
| 2268 | break;
|
---|
| 2269 |
|
---|
| 2270 | case GuestSessionStatus_Undefined:
|
---|
| 2271 | case GuestSessionStatus_Starting:
|
---|
| 2272 | /* Do the waiting below. */
|
---|
| 2273 | break;
|
---|
| 2274 |
|
---|
| 2275 | default:
|
---|
[49504] | 2276 | AssertMsgFailed(("Unhandled session status %RU32\n", mData.mStatus));
|
---|
[45010] | 2277 | return VERR_NOT_IMPLEMENTED;
|
---|
| 2278 | }
|
---|
| 2279 | }
|
---|
| 2280 |
|
---|
[49504] | 2281 | LogFlowThisFunc(("sessionStatus=%RU32, sessionRc=%Rrc, waitResult=%RU32\n",
|
---|
[45010] | 2282 | mData.mStatus, mData.mRC, waitResult));
|
---|
| 2283 |
|
---|
| 2284 | /* No waiting needed? Return immediately using the last set error. */
|
---|
| 2285 | if (waitResult != GuestSessionWaitResult_None)
|
---|
| 2286 | {
|
---|
| 2287 | if (pGuestRc)
|
---|
| 2288 | *pGuestRc = mData.mRC; /* Return last set error (if any). */
|
---|
[45078] | 2289 | return RT_SUCCESS(mData.mRC) ? VINF_SUCCESS : VERR_GSTCTL_GUEST_ERROR;
|
---|
[45010] | 2290 | }
|
---|
| 2291 |
|
---|
[45780] | 2292 | int vrc;
|
---|
| 2293 |
|
---|
| 2294 | GuestWaitEvent *pEvent = NULL;
|
---|
[49349] | 2295 | GuestEventTypes eventTypes;
|
---|
[45780] | 2296 | try
|
---|
| 2297 | {
|
---|
| 2298 | eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
|
---|
| 2299 |
|
---|
[47469] | 2300 | vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
|
---|
| 2301 | eventTypes, &pEvent);
|
---|
[45780] | 2302 | }
|
---|
| 2303 | catch (std::bad_alloc)
|
---|
| 2304 | {
|
---|
| 2305 | vrc = VERR_NO_MEMORY;
|
---|
| 2306 | }
|
---|
| 2307 |
|
---|
| 2308 | if (RT_FAILURE(vrc))
|
---|
| 2309 | return vrc;
|
---|
| 2310 |
|
---|
[47627] | 2311 | alock.release(); /* Release lock before waiting. */
|
---|
| 2312 |
|
---|
[45415] | 2313 | GuestSessionStatus_T sessionStatus;
|
---|
[50727] | 2314 | vrc = i_waitForStatusChange(pEvent, fWaitFlags,
|
---|
| 2315 | uTimeoutMS, &sessionStatus, pGuestRc);
|
---|
[45415] | 2316 | if (RT_SUCCESS(vrc))
|
---|
[45010] | 2317 | {
|
---|
[45415] | 2318 | switch (sessionStatus)
|
---|
| 2319 | {
|
---|
| 2320 | case GuestSessionStatus_Started:
|
---|
| 2321 | waitResult = GuestSessionWaitResult_Start;
|
---|
| 2322 | break;
|
---|
| 2323 |
|
---|
| 2324 | case GuestSessionStatus_Terminated:
|
---|
| 2325 | waitResult = GuestSessionWaitResult_Terminate;
|
---|
| 2326 | break;
|
---|
| 2327 |
|
---|
| 2328 | case GuestSessionStatus_TimedOutKilled:
|
---|
| 2329 | case GuestSessionStatus_TimedOutAbnormally:
|
---|
| 2330 | waitResult = GuestSessionWaitResult_Timeout;
|
---|
| 2331 | break;
|
---|
| 2332 |
|
---|
| 2333 | case GuestSessionStatus_Down:
|
---|
| 2334 | waitResult = GuestSessionWaitResult_Terminate;
|
---|
| 2335 | break;
|
---|
| 2336 |
|
---|
| 2337 | case GuestSessionStatus_Error:
|
---|
| 2338 | waitResult = GuestSessionWaitResult_Error;
|
---|
| 2339 | break;
|
---|
| 2340 |
|
---|
| 2341 | default:
|
---|
| 2342 | waitResult = GuestSessionWaitResult_Status;
|
---|
| 2343 | break;
|
---|
| 2344 | }
|
---|
[45010] | 2345 | }
|
---|
[45415] | 2346 |
|
---|
[47469] | 2347 | unregisterWaitEvent(pEvent);
|
---|
[45780] | 2348 |
|
---|
[45415] | 2349 | LogFlowFuncLeaveRC(vrc);
|
---|
| 2350 | return vrc;
|
---|
| 2351 | }
|
---|
| 2352 |
|
---|
[50727] | 2353 | int GuestSession::i_waitForStatusChange(GuestWaitEvent *pEvent, uint32_t fWaitFlags, uint32_t uTimeoutMS,
|
---|
| 2354 | GuestSessionStatus_T *pSessionStatus, int *pGuestRc)
|
---|
[45415] | 2355 | {
|
---|
[63251] | 2356 | RT_NOREF(fWaitFlags);
|
---|
[45780] | 2357 | AssertPtrReturn(pEvent, VERR_INVALID_POINTER);
|
---|
[45415] | 2358 |
|
---|
[45780] | 2359 | VBoxEventType_T evtType;
|
---|
| 2360 | ComPtr<IEvent> pIEvent;
|
---|
| 2361 | int vrc = waitForEvent(pEvent, uTimeoutMS,
|
---|
| 2362 | &evtType, pIEvent.asOutParam());
|
---|
| 2363 | if (RT_SUCCESS(vrc))
|
---|
[45010] | 2364 | {
|
---|
[45780] | 2365 | Assert(evtType == VBoxEventType_OnGuestSessionStateChanged);
|
---|
[45010] | 2366 |
|
---|
[45780] | 2367 | ComPtr<IGuestSessionStateChangedEvent> pChangedEvent = pIEvent;
|
---|
| 2368 | Assert(!pChangedEvent.isNull());
|
---|
[45010] | 2369 |
|
---|
[45780] | 2370 | GuestSessionStatus_T sessionStatus;
|
---|
| 2371 | pChangedEvent->COMGETTER(Status)(&sessionStatus);
|
---|
| 2372 | if (pSessionStatus)
|
---|
| 2373 | *pSessionStatus = sessionStatus;
|
---|
[45010] | 2374 |
|
---|
[45805] | 2375 | ComPtr<IVirtualBoxErrorInfo> errorInfo;
|
---|
[45780] | 2376 | HRESULT hr = pChangedEvent->COMGETTER(Error)(errorInfo.asOutParam());
|
---|
| 2377 | ComAssertComRC(hr);
|
---|
[45010] | 2378 |
|
---|
[45780] | 2379 | LONG lGuestRc;
|
---|
[45805] | 2380 | hr = errorInfo->COMGETTER(ResultDetail)(&lGuestRc);
|
---|
[45780] | 2381 | ComAssertComRC(hr);
|
---|
| 2382 | if (RT_FAILURE((int)lGuestRc))
|
---|
| 2383 | vrc = VERR_GSTCTL_GUEST_ERROR;
|
---|
| 2384 | if (pGuestRc)
|
---|
| 2385 | *pGuestRc = (int)lGuestRc;
|
---|
[45010] | 2386 |
|
---|
[49504] | 2387 | LogFlowThisFunc(("Status changed event for session ID=%RU32, new status is: %RU32 (%Rrc)\n",
|
---|
[45780] | 2388 | mData.mSession.mID, sessionStatus,
|
---|
| 2389 | RT_SUCCESS((int)lGuestRc) ? VINF_SUCCESS : (int)lGuestRc));
|
---|
[45010] | 2390 | }
|
---|
| 2391 |
|
---|
| 2392 | LogFlowFuncLeaveRC(vrc);
|
---|
| 2393 | return vrc;
|
---|
| 2394 | }
|
---|
| 2395 |
|
---|
[42084] | 2396 | // implementation of public methods
|
---|
| 2397 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 2398 |
|
---|
[50729] | 2399 | HRESULT GuestSession::close()
|
---|
[42084] | 2400 | {
|
---|
[42194] | 2401 | LogFlowThisFuncEnter();
|
---|
| 2402 |
|
---|
[42897] | 2403 | AutoCaller autoCaller(this);
|
---|
| 2404 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2405 |
|
---|
[45109] | 2406 | /* Close session on guest. */
|
---|
[47469] | 2407 | int guestRc = VINF_SUCCESS;
|
---|
[50727] | 2408 | int rc = i_closeSession(0 /* Flags */, 30 * 1000 /* Timeout */,
|
---|
| 2409 | &guestRc);
|
---|
[44935] | 2410 | /* On failure don't return here, instead do all the cleanup
|
---|
| 2411 | * work first and then return an error. */
|
---|
[44863] | 2412 |
|
---|
[42897] | 2413 | /* Remove ourselves from the session list. */
|
---|
[52082] | 2414 | int rc2 = mParent->i_sessionRemove(this);
|
---|
[49349] | 2415 | if (rc2 == VERR_NOT_FOUND) /* Not finding the session anymore isn't critical. */
|
---|
| 2416 | rc2 = VINF_SUCCESS;
|
---|
| 2417 |
|
---|
[44935] | 2418 | if (RT_SUCCESS(rc))
|
---|
| 2419 | rc = rc2;
|
---|
[42897] | 2420 |
|
---|
[47469] | 2421 | LogFlowThisFunc(("Returning rc=%Rrc, guestRc=%Rrc\n",
|
---|
| 2422 | rc, guestRc));
|
---|
[44935] | 2423 | if (RT_FAILURE(rc))
|
---|
| 2424 | {
|
---|
[45109] | 2425 | if (rc == VERR_GSTCTL_GUEST_ERROR)
|
---|
[50727] | 2426 | return GuestSession::i_setErrorExternal(this, guestRc);
|
---|
[45109] | 2427 |
|
---|
[44935] | 2428 | return setError(VBOX_E_IPRT_ERROR,
|
---|
[45415] | 2429 | tr("Closing guest session failed with %Rrc"), rc);
|
---|
[44935] | 2430 | }
|
---|
| 2431 |
|
---|
[42105] | 2432 | return S_OK;
|
---|
[42084] | 2433 | }
|
---|
| 2434 |
|
---|
[55631] | 2435 | HRESULT GuestSession::fileCopy(const com::Utf8Str &aSource, const com::Utf8Str &aDestination,
|
---|
| 2436 | const std::vector<FileCopyFlag_T> &aFlags, ComPtr<IProgress> &aProgress)
|
---|
[42084] | 2437 | {
|
---|
[63251] | 2438 | RT_NOREF(aSource, aDestination, aFlags, aProgress);
|
---|
[55631] | 2439 | ReturnComNotImplemented();
|
---|
| 2440 | }
|
---|
| 2441 |
|
---|
| 2442 | HRESULT GuestSession::fileCopyFromGuest(const com::Utf8Str &aSource, const com::Utf8Str &aDest,
|
---|
| 2443 | const std::vector<FileCopyFlag_T> &aFlags,
|
---|
| 2444 | ComPtr<IProgress> &aProgress)
|
---|
| 2445 | {
|
---|
[42194] | 2446 | LogFlowThisFuncEnter();
|
---|
| 2447 |
|
---|
[50727] | 2448 | if (RT_UNLIKELY((aSource.c_str()) == NULL || *(aSource.c_str()) == '\0'))
|
---|
[42566] | 2449 | return setError(E_INVALIDARG, tr("No source specified"));
|
---|
[50727] | 2450 | if (RT_UNLIKELY((aDest.c_str()) == NULL || *(aDest.c_str()) == '\0'))
|
---|
[42566] | 2451 | return setError(E_INVALIDARG, tr("No destination specified"));
|
---|
| 2452 |
|
---|
[55631] | 2453 | uint32_t fFlags = FileCopyFlag_None;
|
---|
[50727] | 2454 | if (aFlags.size())
|
---|
[42566] | 2455 | {
|
---|
[50727] | 2456 | for (size_t i = 0; i < aFlags.size(); i++)
|
---|
| 2457 | fFlags |= aFlags[i];
|
---|
[42566] | 2458 | }
|
---|
[55631] | 2459 | /** @todo r=bird: fend off flags we don't implement here! */
|
---|
[42566] | 2460 |
|
---|
| 2461 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 2462 |
|
---|
| 2463 | HRESULT hr = S_OK;
|
---|
| 2464 |
|
---|
[43170] | 2465 | try
|
---|
[42566] | 2466 | {
|
---|
[58521] | 2467 | SessionTaskCopyFrom *pTask = NULL;
|
---|
[43170] | 2468 | ComObjPtr<Progress> pProgress;
|
---|
[58521] | 2469 | try
|
---|
| 2470 | {
|
---|
| 2471 | pTask = new SessionTaskCopyFrom(this /* GuestSession */, aSource, aDest, fFlags);
|
---|
| 2472 | }
|
---|
| 2473 | catch(...)
|
---|
| 2474 | {
|
---|
| 2475 | hr = setError(VBOX_E_IPRT_ERROR, tr("Failed to create SessionTaskCopyFrom object "));
|
---|
| 2476 | throw;
|
---|
| 2477 | }
|
---|
| 2478 |
|
---|
| 2479 |
|
---|
| 2480 | hr = pTask->Init(Utf8StrFmt(tr("Copying \"%s\" from guest to \"%s\" on the host"), aSource.c_str(), aDest.c_str()));
|
---|
| 2481 | if (FAILED(hr))
|
---|
| 2482 | {
|
---|
| 2483 | delete pTask;
|
---|
| 2484 | hr = setError(VBOX_E_IPRT_ERROR,
|
---|
| 2485 | tr("Creating progress object for SessionTaskCopyFrom object failed"));
|
---|
| 2486 | throw hr;
|
---|
| 2487 | }
|
---|
| 2488 |
|
---|
[63182] | 2489 | hr = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER);
|
---|
[58521] | 2490 |
|
---|
| 2491 | if (SUCCEEDED(hr))
|
---|
| 2492 | {
|
---|
[43170] | 2493 | /* Return progress to the caller. */
|
---|
[58521] | 2494 | pProgress = pTask->GetProgressObject();
|
---|
[50727] | 2495 | hr = pProgress.queryInterfaceTo(aProgress.asOutParam());
|
---|
[58521] | 2496 | }
|
---|
[43170] | 2497 | else
|
---|
| 2498 | hr = setError(VBOX_E_IPRT_ERROR,
|
---|
[58521] | 2499 | tr("Starting thread for copying file \"%s\" from guest to \"%s\" on the host failed "),
|
---|
| 2500 | aSource.c_str(), aDest.c_str());
|
---|
| 2501 |
|
---|
[42566] | 2502 | }
|
---|
[43170] | 2503 | catch(std::bad_alloc &)
|
---|
| 2504 | {
|
---|
| 2505 | hr = E_OUTOFMEMORY;
|
---|
| 2506 | }
|
---|
[58521] | 2507 | catch(HRESULT eHR)
|
---|
| 2508 | {
|
---|
| 2509 | hr = eHR;
|
---|
| 2510 | LogFlowThisFunc(("Exception was caught in the function \n"));
|
---|
| 2511 | }
|
---|
[43170] | 2512 |
|
---|
[42566] | 2513 | return hr;
|
---|
[42084] | 2514 | }
|
---|
| 2515 |
|
---|
[55631] | 2516 | HRESULT GuestSession::fileCopyToGuest(const com::Utf8Str &aSource, const com::Utf8Str &aDest,
|
---|
| 2517 | const std::vector<FileCopyFlag_T> &aFlags, ComPtr<IProgress> &aProgress)
|
---|
[42084] | 2518 | {
|
---|
[42194] | 2519 | LogFlowThisFuncEnter();
|
---|
| 2520 |
|
---|
[50727] | 2521 | if (RT_UNLIKELY((aSource.c_str()) == NULL || *(aSource.c_str()) == '\0'))
|
---|
[42566] | 2522 | return setError(E_INVALIDARG, tr("No source specified"));
|
---|
[50727] | 2523 | if (RT_UNLIKELY((aDest.c_str()) == NULL || *(aDest.c_str()) == '\0'))
|
---|
[42566] | 2524 | return setError(E_INVALIDARG, tr("No destination specified"));
|
---|
| 2525 |
|
---|
[55631] | 2526 | uint32_t fFlags = FileCopyFlag_None;
|
---|
[50727] | 2527 | if (aFlags.size())
|
---|
[42566] | 2528 | {
|
---|
[50727] | 2529 | for (size_t i = 0; i < aFlags.size(); i++)
|
---|
| 2530 | fFlags |= aFlags[i];
|
---|
[42566] | 2531 | }
|
---|
[55631] | 2532 | /** @todo r=bird: fend off flags we don't implement here! */
|
---|
[42566] | 2533 |
|
---|
| 2534 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 2535 |
|
---|
| 2536 | HRESULT hr = S_OK;
|
---|
| 2537 |
|
---|
[43170] | 2538 | try
|
---|
[42566] | 2539 | {
|
---|
[58521] | 2540 | SessionTaskCopyTo *pTask = NULL;
|
---|
[43170] | 2541 | ComObjPtr<Progress> pProgress;
|
---|
[58521] | 2542 | try
|
---|
[43170] | 2543 | {
|
---|
[58521] | 2544 | pTask = new SessionTaskCopyTo(this /* GuestSession */, aSource, aDest, fFlags);
|
---|
| 2545 | }
|
---|
| 2546 | catch(...)
|
---|
| 2547 | {
|
---|
| 2548 | hr = setError(VBOX_E_IPRT_ERROR, tr("Failed to create SessionTaskCopyTo object "));
|
---|
| 2549 | throw;
|
---|
| 2550 | }
|
---|
| 2551 |
|
---|
| 2552 |
|
---|
| 2553 | hr = pTask->Init(Utf8StrFmt(tr("Copying \"%s\" from host to \"%s\" on the guest"), aSource.c_str(), aDest.c_str()));
|
---|
| 2554 | if (FAILED(hr))
|
---|
| 2555 | {
|
---|
| 2556 | delete pTask;
|
---|
| 2557 | hr = setError(VBOX_E_IPRT_ERROR,
|
---|
| 2558 | tr("Creating progress object for SessionTaskCopyTo object failed"));
|
---|
| 2559 | throw hr;
|
---|
| 2560 | }
|
---|
| 2561 |
|
---|
[63182] | 2562 | hr = pTask->createThreadWithType(RTTHREADTYPE_MAIN_HEAVY_WORKER);
|
---|
[58521] | 2563 |
|
---|
| 2564 | if (SUCCEEDED(hr))
|
---|
| 2565 | {
|
---|
[43170] | 2566 | /* Return progress to the caller. */
|
---|
[58521] | 2567 | pProgress = pTask->GetProgressObject();
|
---|
[50727] | 2568 | hr = pProgress.queryInterfaceTo(aProgress.asOutParam());
|
---|
[43170] | 2569 | }
|
---|
| 2570 | else
|
---|
| 2571 | hr = setError(VBOX_E_IPRT_ERROR,
|
---|
[60490] | 2572 | tr("Starting thread for copying file \"%s\" from host to \"%s\" on the guest failed "),
|
---|
[58521] | 2573 | aSource.c_str(), aDest.c_str());
|
---|
[42566] | 2574 | }
|
---|
[43170] | 2575 | catch(std::bad_alloc &)
|
---|
| 2576 | {
|
---|
| 2577 | hr = E_OUTOFMEMORY;
|
---|
| 2578 | }
|
---|
[58521] | 2579 | catch(HRESULT eHR)
|
---|
| 2580 | {
|
---|
| 2581 | hr = eHR;
|
---|
| 2582 | LogFlowThisFunc(("Exception was caught in the function \n"));
|
---|
| 2583 | }
|
---|
[43170] | 2584 |
|
---|
| 2585 | return hr;
|
---|
[42084] | 2586 | }
|
---|
| 2587 |
|
---|
[55631] | 2588 | HRESULT GuestSession::directoryCopy(const com::Utf8Str &aSource, const com::Utf8Str &aDestination,
|
---|
| 2589 | const std::vector<DirectoryCopyFlags_T> &aFlags, ComPtr<IProgress> &aProgress)
|
---|
| 2590 | {
|
---|
[63251] | 2591 | RT_NOREF(aSource, aDestination, aFlags, aProgress);
|
---|
[55631] | 2592 | ReturnComNotImplemented();
|
---|
| 2593 | }
|
---|
| 2594 |
|
---|
| 2595 | HRESULT GuestSession::directoryCopyFromGuest(const com::Utf8Str &aSource, const com::Utf8Str &aDestination,
|
---|
| 2596 | const std::vector<DirectoryCopyFlags_T> &aFlags, ComPtr<IProgress> &aProgress)
|
---|
| 2597 | {
|
---|
[63251] | 2598 | RT_NOREF(aSource, aDestination, aFlags, aProgress);
|
---|
[55631] | 2599 | ReturnComNotImplemented();
|
---|
| 2600 | }
|
---|
| 2601 |
|
---|
| 2602 | HRESULT GuestSession::directoryCopyToGuest(const com::Utf8Str &aSource, const com::Utf8Str &aDestination,
|
---|
| 2603 | const std::vector<DirectoryCopyFlags_T> &aFlags, ComPtr<IProgress> &aProgress)
|
---|
| 2604 | {
|
---|
[63251] | 2605 | RT_NOREF(aSource, aDestination, aFlags, aProgress);
|
---|
[55631] | 2606 | ReturnComNotImplemented();
|
---|
| 2607 | }
|
---|
| 2608 |
|
---|
[50727] | 2609 | HRESULT GuestSession::directoryCreate(const com::Utf8Str &aPath, ULONG aMode,
|
---|
| 2610 | const std::vector<DirectoryCreateFlag_T> &aFlags)
|
---|
[42084] | 2611 | {
|
---|
[42194] | 2612 | LogFlowThisFuncEnter();
|
---|
| 2613 |
|
---|
[50727] | 2614 | if (RT_UNLIKELY((aPath.c_str()) == NULL || *(aPath.c_str()) == '\0'))
|
---|
[42525] | 2615 | return setError(E_INVALIDARG, tr("No directory to create specified"));
|
---|
| 2616 |
|
---|
| 2617 | uint32_t fFlags = DirectoryCreateFlag_None;
|
---|
[50727] | 2618 | if (aFlags.size())
|
---|
[42525] | 2619 | {
|
---|
[50727] | 2620 | for (size_t i = 0; i < aFlags.size(); i++)
|
---|
| 2621 | fFlags |= aFlags[i];
|
---|
[42525] | 2622 |
|
---|
[42611] | 2623 | if (fFlags)
|
---|
| 2624 | if (!(fFlags & DirectoryCreateFlag_Parents))
|
---|
| 2625 | return setError(E_INVALIDARG, tr("Unknown flags (%#x)"), fFlags);
|
---|
[42525] | 2626 | }
|
---|
| 2627 |
|
---|
| 2628 | HRESULT hr = S_OK;
|
---|
| 2629 |
|
---|
[43162] | 2630 | ComObjPtr <GuestDirectory> pDirectory; int guestRc;
|
---|
[50727] | 2631 | int rc = i_directoryCreateInternal(aPath, (uint32_t)aMode, fFlags, &guestRc);
|
---|
[42808] | 2632 | if (RT_FAILURE(rc))
|
---|
[42525] | 2633 | {
|
---|
| 2634 | switch (rc)
|
---|
| 2635 | {
|
---|
[45078] | 2636 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[60622] | 2637 | hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: %s",
|
---|
| 2638 | GuestDirectory::i_guestErrorToString(guestRc).c_str()));
|
---|
[43162] | 2639 | break;
|
---|
| 2640 |
|
---|
[42525] | 2641 | case VERR_INVALID_PARAMETER:
|
---|
| 2642 | hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Invalid parameters given"));
|
---|
| 2643 | break;
|
---|
| 2644 |
|
---|
| 2645 | case VERR_BROKEN_PIPE:
|
---|
| 2646 | hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Unexpectedly aborted"));
|
---|
| 2647 | break;
|
---|
| 2648 |
|
---|
| 2649 | default:
|
---|
| 2650 | hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: %Rrc"), rc);
|
---|
| 2651 | break;
|
---|
| 2652 | }
|
---|
| 2653 | }
|
---|
| 2654 |
|
---|
| 2655 | return hr;
|
---|
[42084] | 2656 | }
|
---|
| 2657 |
|
---|
[50874] | 2658 | HRESULT GuestSession::directoryCreateTemp(const com::Utf8Str &aTemplateName, ULONG aMode, const com::Utf8Str &aPath,
|
---|
| 2659 | BOOL aSecure, com::Utf8Str &aDirectory)
|
---|
[42084] | 2660 | {
|
---|
[63251] | 2661 | RT_NOREF(aMode, aSecure);
|
---|
[42194] | 2662 | LogFlowThisFuncEnter();
|
---|
| 2663 |
|
---|
[50727] | 2664 | if (RT_UNLIKELY((aTemplateName.c_str()) == NULL || *(aTemplateName.c_str()) == '\0'))
|
---|
[43162] | 2665 | return setError(E_INVALIDARG, tr("No template specified"));
|
---|
[50727] | 2666 | if (RT_UNLIKELY((aPath.c_str()) == NULL || *(aPath.c_str()) == '\0'))
|
---|
[43162] | 2667 | return setError(E_INVALIDARG, tr("No directory name specified"));
|
---|
[42657] | 2668 |
|
---|
[43162] | 2669 | HRESULT hr = S_OK;
|
---|
[42657] | 2670 |
|
---|
[50727] | 2671 | int guestRc;
|
---|
| 2672 | int rc = i_objectCreateTempInternal(aTemplateName,
|
---|
| 2673 | aPath,
|
---|
| 2674 | true /* Directory */, aDirectory, &guestRc);
|
---|
| 2675 | if (!RT_SUCCESS(rc))
|
---|
[42657] | 2676 | {
|
---|
[43162] | 2677 | switch (rc)
|
---|
| 2678 | {
|
---|
[45078] | 2679 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[50709] | 2680 | hr = GuestProcess::i_setErrorExternal(this, guestRc);
|
---|
[43162] | 2681 | break;
|
---|
| 2682 |
|
---|
| 2683 | default:
|
---|
| 2684 | hr = setError(VBOX_E_IPRT_ERROR, tr("Temporary directory creation \"%s\" with template \"%s\" failed: %Rrc"),
|
---|
[50727] | 2685 | aPath.c_str(), aTemplateName.c_str(), rc);
|
---|
[43162] | 2686 | break;
|
---|
| 2687 | }
|
---|
[42657] | 2688 | }
|
---|
[43162] | 2689 |
|
---|
| 2690 | return hr;
|
---|
[42084] | 2691 | }
|
---|
| 2692 |
|
---|
[55631] | 2693 | HRESULT GuestSession::directoryExists(const com::Utf8Str &aPath, BOOL aFollowSymlinks, BOOL *aExists)
|
---|
[42084] | 2694 | {
|
---|
[42194] | 2695 | LogFlowThisFuncEnter();
|
---|
| 2696 |
|
---|
[50727] | 2697 | if (RT_UNLIKELY((aPath.c_str()) == NULL || *(aPath.c_str()) == '\0'))
|
---|
[42531] | 2698 | return setError(E_INVALIDARG, tr("No directory to check existence for specified"));
|
---|
| 2699 |
|
---|
| 2700 | HRESULT hr = S_OK;
|
---|
| 2701 |
|
---|
[43162] | 2702 | GuestFsObjData objData; int guestRc;
|
---|
[55631] | 2703 | int rc = i_directoryQueryInfoInternal(aPath, aFollowSymlinks != FALSE, objData, &guestRc);
|
---|
[42531] | 2704 | if (RT_SUCCESS(rc))
|
---|
| 2705 | *aExists = objData.mType == FsObjType_Directory;
|
---|
| 2706 | else
|
---|
| 2707 | {
|
---|
[55631] | 2708 | /** @todo r=bird: Looks like this code raises errors if the directory doesn't
|
---|
| 2709 | * exist... That's of course not right. */
|
---|
[42531] | 2710 | switch (rc)
|
---|
| 2711 | {
|
---|
[45078] | 2712 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[50709] | 2713 | hr = GuestProcess::i_setErrorExternal(this, guestRc);
|
---|
[43162] | 2714 | break;
|
---|
[42531] | 2715 |
|
---|
| 2716 | default:
|
---|
[43162] | 2717 | hr = setError(VBOX_E_IPRT_ERROR, tr("Querying directory existence \"%s\" failed: %Rrc"),
|
---|
[50727] | 2718 | aPath.c_str(), rc);
|
---|
[42531] | 2719 | break;
|
---|
| 2720 | }
|
---|
| 2721 | }
|
---|
| 2722 |
|
---|
| 2723 | return hr;
|
---|
[42084] | 2724 | }
|
---|
| 2725 |
|
---|
[50874] | 2726 | HRESULT GuestSession::directoryOpen(const com::Utf8Str &aPath, const com::Utf8Str &aFilter,
|
---|
| 2727 | const std::vector<DirectoryOpenFlag_T> &aFlags, ComPtr<IGuestDirectory> &aDirectory)
|
---|
[42084] | 2728 | {
|
---|
[42194] | 2729 | LogFlowThisFuncEnter();
|
---|
| 2730 |
|
---|
[50727] | 2731 | if (RT_UNLIKELY((aPath.c_str()) == NULL || *(aPath.c_str()) == '\0'))
|
---|
[42673] | 2732 | return setError(E_INVALIDARG, tr("No directory to open specified"));
|
---|
[50727] | 2733 | if (RT_UNLIKELY((aFilter.c_str()) != NULL && *(aFilter.c_str()) != '\0'))
|
---|
[43162] | 2734 | return setError(E_INVALIDARG, tr("Directory filters are not implemented yet"));
|
---|
[42673] | 2735 |
|
---|
| 2736 | uint32_t fFlags = DirectoryOpenFlag_None;
|
---|
[50727] | 2737 | if (aFlags.size())
|
---|
[42673] | 2738 | {
|
---|
[50727] | 2739 | for (size_t i = 0; i < aFlags.size(); i++)
|
---|
| 2740 | fFlags |= aFlags[i];
|
---|
[42673] | 2741 |
|
---|
| 2742 | if (fFlags)
|
---|
| 2743 | return setError(E_INVALIDARG, tr("Open flags (%#x) not implemented yet"), fFlags);
|
---|
| 2744 | }
|
---|
| 2745 |
|
---|
| 2746 | HRESULT hr = S_OK;
|
---|
| 2747 |
|
---|
[49349] | 2748 | GuestDirectoryOpenInfo openInfo;
|
---|
[50727] | 2749 | openInfo.mPath = aPath;
|
---|
| 2750 | openInfo.mFilter = aFilter;
|
---|
[49349] | 2751 | openInfo.mFlags = fFlags;
|
---|
| 2752 |
|
---|
| 2753 | ComObjPtr <GuestDirectory> pDirectory; int guestRc;
|
---|
[50727] | 2754 | int rc = i_directoryOpenInternal(openInfo, pDirectory, &guestRc);
|
---|
[42673] | 2755 | if (RT_SUCCESS(rc))
|
---|
| 2756 | {
|
---|
[43162] | 2757 | /* Return directory object to the caller. */
|
---|
[50727] | 2758 | hr = pDirectory.queryInterfaceTo(aDirectory.asOutParam());
|
---|
[42673] | 2759 | }
|
---|
| 2760 | else
|
---|
| 2761 | {
|
---|
| 2762 | switch (rc)
|
---|
| 2763 | {
|
---|
| 2764 | case VERR_INVALID_PARAMETER:
|
---|
[53128] | 2765 | hr = setError(VBOX_E_IPRT_ERROR, tr("Opening directory \"%s\" failed; invalid parameters given"),
|
---|
| 2766 | aPath.c_str());
|
---|
[42673] | 2767 | break;
|
---|
| 2768 |
|
---|
[49349] | 2769 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[50559] | 2770 | hr = GuestDirectory::i_setErrorExternal(this, guestRc);
|
---|
[49349] | 2771 | break;
|
---|
| 2772 |
|
---|
[42673] | 2773 | default:
|
---|
[43162] | 2774 | hr = setError(VBOX_E_IPRT_ERROR, tr("Opening directory \"%s\" failed: %Rrc"),
|
---|
[50727] | 2775 | aPath.c_str(),rc);
|
---|
[42673] | 2776 | break;
|
---|
| 2777 | }
|
---|
| 2778 | }
|
---|
| 2779 |
|
---|
| 2780 | return hr;
|
---|
[42084] | 2781 | }
|
---|
| 2782 |
|
---|
[50727] | 2783 | HRESULT GuestSession::directoryRemove(const com::Utf8Str &aPath)
|
---|
[42084] | 2784 | {
|
---|
[42194] | 2785 | LogFlowThisFuncEnter();
|
---|
| 2786 |
|
---|
[50727] | 2787 | if (RT_UNLIKELY((aPath.c_str()) == NULL || *(aPath.c_str()) == '\0'))
|
---|
[49349] | 2788 | return setError(E_INVALIDARG, tr("No directory to remove specified"));
|
---|
| 2789 |
|
---|
[50727] | 2790 | HRESULT hr = i_isReadyExternal();
|
---|
[49349] | 2791 | if (FAILED(hr))
|
---|
| 2792 | return hr;
|
---|
| 2793 |
|
---|
| 2794 | /* No flags; only remove the directory when empty. */
|
---|
| 2795 | uint32_t uFlags = 0;
|
---|
| 2796 |
|
---|
| 2797 | int guestRc;
|
---|
[50727] | 2798 | int vrc = i_directoryRemoveInternal(aPath, uFlags, &guestRc);
|
---|
[49349] | 2799 | if (RT_FAILURE(vrc))
|
---|
| 2800 | {
|
---|
| 2801 | switch (vrc)
|
---|
| 2802 | {
|
---|
| 2803 | case VERR_NOT_SUPPORTED:
|
---|
| 2804 | hr = setError(VBOX_E_IPRT_ERROR,
|
---|
| 2805 | tr("Handling removing guest directories not supported by installed Guest Additions"));
|
---|
| 2806 | break;
|
---|
| 2807 |
|
---|
| 2808 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[50559] | 2809 | hr = GuestDirectory::i_setErrorExternal(this, guestRc);
|
---|
[49349] | 2810 | break;
|
---|
| 2811 |
|
---|
| 2812 | default:
|
---|
| 2813 | hr = setError(VBOX_E_IPRT_ERROR, tr("Removing guest directory \"%s\" failed: %Rrc"),
|
---|
[50727] | 2814 | aPath.c_str(), vrc);
|
---|
[49349] | 2815 | break;
|
---|
| 2816 | }
|
---|
| 2817 | }
|
---|
| 2818 |
|
---|
| 2819 | return hr;
|
---|
[42084] | 2820 | }
|
---|
| 2821 |
|
---|
[50874] | 2822 | HRESULT GuestSession::directoryRemoveRecursive(const com::Utf8Str &aPath, const std::vector<DirectoryRemoveRecFlag_T> &aFlags,
|
---|
| 2823 | ComPtr<IProgress> &aProgress)
|
---|
[42084] | 2824 | {
|
---|
[63251] | 2825 | RT_NOREF(aFlags);
|
---|
[42194] | 2826 | LogFlowThisFuncEnter();
|
---|
| 2827 |
|
---|
[50727] | 2828 | if (RT_UNLIKELY((aPath.c_str()) == NULL || *(aPath.c_str()) == '\0'))
|
---|
[49349] | 2829 | return setError(E_INVALIDARG, tr("No directory to remove recursively specified"));
|
---|
| 2830 |
|
---|
[55631] | 2831 | /** @todo r=bird: Must check that the flags matches the hardcoded behavior
|
---|
| 2832 | * further down!! */
|
---|
| 2833 |
|
---|
[50727] | 2834 | HRESULT hr = i_isReadyExternal();
|
---|
[49349] | 2835 | if (FAILED(hr))
|
---|
| 2836 | return hr;
|
---|
| 2837 |
|
---|
| 2838 | ComObjPtr<Progress> pProgress;
|
---|
| 2839 | hr = pProgress.createObject();
|
---|
| 2840 | if (SUCCEEDED(hr))
|
---|
| 2841 | hr = pProgress->init(static_cast<IGuestSession *>(this),
|
---|
| 2842 | Bstr(tr("Removing guest directory")).raw(),
|
---|
| 2843 | TRUE /*aCancelable*/);
|
---|
| 2844 | if (FAILED(hr))
|
---|
| 2845 | return hr;
|
---|
| 2846 |
|
---|
| 2847 | /* Note: At the moment we don't supply progress information while
|
---|
| 2848 | * deleting a guest directory recursively. So just complete
|
---|
| 2849 | * the progress object right now. */
|
---|
| 2850 | /** @todo Implement progress reporting on guest directory deletion! */
|
---|
[50874] | 2851 | hr = pProgress->i_notifyComplete(S_OK);
|
---|
[49349] | 2852 | if (FAILED(hr))
|
---|
| 2853 | return hr;
|
---|
| 2854 |
|
---|
| 2855 | /* Remove the directory + all its contents. */
|
---|
| 2856 | uint32_t uFlags = DIRREMOVE_FLAG_RECURSIVE
|
---|
| 2857 | | DIRREMOVE_FLAG_CONTENT_AND_DIR;
|
---|
| 2858 | int guestRc;
|
---|
[50727] | 2859 | int vrc = i_directoryRemoveInternal(aPath, uFlags, &guestRc);
|
---|
[49349] | 2860 | if (RT_FAILURE(vrc))
|
---|
| 2861 | {
|
---|
| 2862 | switch (vrc)
|
---|
| 2863 | {
|
---|
| 2864 | case VERR_NOT_SUPPORTED:
|
---|
| 2865 | hr = setError(VBOX_E_IPRT_ERROR,
|
---|
| 2866 | tr("Handling removing guest directories recursively not supported by installed Guest Additions"));
|
---|
| 2867 | break;
|
---|
| 2868 |
|
---|
| 2869 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[50618] | 2870 | hr = GuestFile::i_setErrorExternal(this, guestRc);
|
---|
[49349] | 2871 | break;
|
---|
| 2872 |
|
---|
| 2873 | default:
|
---|
| 2874 | hr = setError(VBOX_E_IPRT_ERROR, tr("Recursively removing guest directory \"%s\" failed: %Rrc"),
|
---|
[50727] | 2875 | aPath.c_str(), vrc);
|
---|
[49349] | 2876 | break;
|
---|
| 2877 | }
|
---|
| 2878 | }
|
---|
| 2879 | else
|
---|
| 2880 | {
|
---|
[50727] | 2881 | pProgress.queryInterfaceTo(aProgress.asOutParam());
|
---|
[49349] | 2882 | }
|
---|
| 2883 |
|
---|
| 2884 | return hr;
|
---|
[42084] | 2885 | }
|
---|
| 2886 |
|
---|
[55591] | 2887 | HRESULT GuestSession::environmentScheduleSet(const com::Utf8Str &aName, const com::Utf8Str &aValue)
|
---|
[42084] | 2888 | {
|
---|
[42194] | 2889 | LogFlowThisFuncEnter();
|
---|
| 2890 |
|
---|
[55588] | 2891 | HRESULT hrc;
|
---|
| 2892 | if (RT_LIKELY(aName.isNotEmpty()))
|
---|
| 2893 | {
|
---|
| 2894 | if (RT_LIKELY(strchr(aName.c_str(), '=') == NULL))
|
---|
| 2895 | {
|
---|
| 2896 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[55591] | 2897 | int vrc = mData.mEnvironmentChanges.setVariable(aName, aValue);
|
---|
[55588] | 2898 | if (RT_SUCCESS(vrc))
|
---|
| 2899 | hrc = S_OK;
|
---|
| 2900 | else
|
---|
| 2901 | hrc = setErrorVrc(vrc);
|
---|
| 2902 | }
|
---|
| 2903 | else
|
---|
| 2904 | hrc = setError(E_INVALIDARG, tr("The equal char is not allowed in environment variable names"));
|
---|
| 2905 | }
|
---|
| 2906 | else
|
---|
| 2907 | hrc = setError(E_INVALIDARG, tr("No variable name specified"));
|
---|
[42194] | 2908 |
|
---|
[55588] | 2909 | LogFlowThisFuncLeave();
|
---|
| 2910 | return hrc;
|
---|
[42084] | 2911 | }
|
---|
| 2912 |
|
---|
[55591] | 2913 | HRESULT GuestSession::environmentScheduleUnset(const com::Utf8Str &aName)
|
---|
[42084] | 2914 | {
|
---|
[42194] | 2915 | LogFlowThisFuncEnter();
|
---|
[55588] | 2916 | HRESULT hrc;
|
---|
| 2917 | if (RT_LIKELY(aName.isNotEmpty()))
|
---|
| 2918 | {
|
---|
| 2919 | if (RT_LIKELY(strchr(aName.c_str(), '=') == NULL))
|
---|
| 2920 | {
|
---|
| 2921 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[55591] | 2922 | int vrc = mData.mEnvironmentChanges.unsetVariable(aName);
|
---|
[55588] | 2923 | if (RT_SUCCESS(vrc))
|
---|
| 2924 | hrc = S_OK;
|
---|
| 2925 | else
|
---|
| 2926 | hrc = setErrorVrc(vrc);
|
---|
| 2927 | }
|
---|
| 2928 | else
|
---|
| 2929 | hrc = setError(E_INVALIDARG, tr("The equal char is not allowed in environment variable names"));
|
---|
| 2930 | }
|
---|
| 2931 | else
|
---|
| 2932 | hrc = setError(E_INVALIDARG, tr("No variable name specified"));
|
---|
[42194] | 2933 |
|
---|
[47627] | 2934 | LogFlowThisFuncLeave();
|
---|
[55588] | 2935 | return hrc;
|
---|
[42084] | 2936 | }
|
---|
| 2937 |
|
---|
[55591] | 2938 | HRESULT GuestSession::environmentGetBaseVariable(const com::Utf8Str &aName, com::Utf8Str &aValue)
|
---|
| 2939 | {
|
---|
| 2940 | LogFlowThisFuncEnter();
|
---|
| 2941 | HRESULT hrc;
|
---|
| 2942 | if (RT_LIKELY(aName.isNotEmpty()))
|
---|
| 2943 | {
|
---|
| 2944 | if (RT_LIKELY(strchr(aName.c_str(), '=') == NULL))
|
---|
| 2945 | {
|
---|
| 2946 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 2947 | if (mData.mpBaseEnvironment)
|
---|
| 2948 | {
|
---|
| 2949 | int vrc = mData.mpBaseEnvironment->getVariable(aName, &aValue);
|
---|
| 2950 | if (RT_SUCCESS(vrc))
|
---|
| 2951 | hrc = S_OK;
|
---|
| 2952 | else
|
---|
| 2953 | hrc = setErrorVrc(vrc);
|
---|
| 2954 | }
|
---|
| 2955 | else if (mData.mProtocolVersion < 99999)
|
---|
| 2956 | hrc = setError(VBOX_E_NOT_SUPPORTED, tr("The base environment feature is not supported by the guest additions"));
|
---|
| 2957 | else
|
---|
| 2958 | hrc = setError(VBOX_E_INVALID_OBJECT_STATE, tr("The base environment has not yet been reported by the guest"));
|
---|
| 2959 | }
|
---|
| 2960 | else
|
---|
| 2961 | hrc = setError(E_INVALIDARG, tr("The equal char is not allowed in environment variable names"));
|
---|
| 2962 | }
|
---|
| 2963 | else
|
---|
| 2964 | hrc = setError(E_INVALIDARG, tr("No variable name specified"));
|
---|
| 2965 |
|
---|
| 2966 | LogFlowThisFuncLeave();
|
---|
| 2967 | return hrc;
|
---|
| 2968 | }
|
---|
| 2969 |
|
---|
| 2970 | HRESULT GuestSession::environmentDoesBaseVariableExist(const com::Utf8Str &aName, BOOL *aExists)
|
---|
| 2971 | {
|
---|
| 2972 | LogFlowThisFuncEnter();
|
---|
| 2973 | *aExists = FALSE;
|
---|
| 2974 | HRESULT hrc;
|
---|
| 2975 | if (RT_LIKELY(aName.isNotEmpty()))
|
---|
| 2976 | {
|
---|
| 2977 | if (RT_LIKELY(strchr(aName.c_str(), '=') == NULL))
|
---|
| 2978 | {
|
---|
| 2979 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 2980 | if (mData.mpBaseEnvironment)
|
---|
| 2981 | {
|
---|
| 2982 | hrc = S_OK;
|
---|
| 2983 | *aExists = mData.mpBaseEnvironment->doesVariableExist(aName);
|
---|
| 2984 | }
|
---|
| 2985 | else if (mData.mProtocolVersion < 99999)
|
---|
| 2986 | hrc = setError(VBOX_E_NOT_SUPPORTED, tr("The base environment feature is not supported by the guest additions"));
|
---|
| 2987 | else
|
---|
| 2988 | hrc = setError(VBOX_E_INVALID_OBJECT_STATE, tr("The base environment has not yet been reported by the guest"));
|
---|
| 2989 | }
|
---|
| 2990 | else
|
---|
| 2991 | hrc = setError(E_INVALIDARG, tr("The equal char is not allowed in environment variable names"));
|
---|
| 2992 | }
|
---|
| 2993 | else
|
---|
| 2994 | hrc = setError(E_INVALIDARG, tr("No variable name specified"));
|
---|
| 2995 |
|
---|
| 2996 | LogFlowThisFuncLeave();
|
---|
| 2997 | return hrc;
|
---|
| 2998 | }
|
---|
| 2999 |
|
---|
[50874] | 3000 | HRESULT GuestSession::fileCreateTemp(const com::Utf8Str &aTemplateName, ULONG aMode, const com::Utf8Str &aPath, BOOL aSecure,
|
---|
| 3001 | ComPtr<IGuestFile> &aFile)
|
---|
[42084] | 3002 | {
|
---|
[63251] | 3003 | RT_NOREF(aTemplateName, aMode, aPath, aSecure, aFile);
|
---|
[42084] | 3004 | ReturnComNotImplemented();
|
---|
| 3005 | }
|
---|
| 3006 |
|
---|
[55631] | 3007 | HRESULT GuestSession::fileExists(const com::Utf8Str &aPath, BOOL aFollowSymlinks, BOOL *aExists)
|
---|
[42084] | 3008 | {
|
---|
[42194] | 3009 | LogFlowThisFuncEnter();
|
---|
| 3010 |
|
---|
[55631] | 3011 | /** @todo r=bird: Treat empty file with a FALSE return. */
|
---|
[50727] | 3012 | if (RT_UNLIKELY((aPath.c_str()) == NULL || *(aPath.c_str()) == '\0'))
|
---|
[42531] | 3013 | return setError(E_INVALIDARG, tr("No file to check existence for specified"));
|
---|
| 3014 |
|
---|
[43162] | 3015 | GuestFsObjData objData; int guestRc;
|
---|
[55631] | 3016 | int vrc = i_fileQueryInfoInternal(aPath, aFollowSymlinks != FALSE, objData, &guestRc);
|
---|
[43162] | 3017 | if (RT_SUCCESS(vrc))
|
---|
| 3018 | {
|
---|
| 3019 | *aExists = TRUE;
|
---|
| 3020 | return S_OK;
|
---|
| 3021 | }
|
---|
| 3022 |
|
---|
[42531] | 3023 | HRESULT hr = S_OK;
|
---|
| 3024 |
|
---|
[43162] | 3025 | switch (vrc)
|
---|
[42531] | 3026 | {
|
---|
[45078] | 3027 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[50709] | 3028 | hr = GuestProcess::i_setErrorExternal(this, guestRc);
|
---|
[43162] | 3029 | break;
|
---|
[42531] | 3030 |
|
---|
[55631] | 3031 | /** @todo r=bird: what about VERR_PATH_NOT_FOUND and VERR_FILE_NOT_FOUND?
|
---|
| 3032 | * Where does that get converted to *aExists = FALSE? */
|
---|
[43162] | 3033 | case VERR_NOT_A_FILE:
|
---|
| 3034 | *aExists = FALSE;
|
---|
| 3035 | break;
|
---|
| 3036 |
|
---|
| 3037 | default:
|
---|
| 3038 | hr = setError(VBOX_E_IPRT_ERROR, tr("Querying file information for \"%s\" failed: %Rrc"),
|
---|
[50727] | 3039 | aPath.c_str(), vrc);
|
---|
[43162] | 3040 | break;
|
---|
[42531] | 3041 | }
|
---|
| 3042 |
|
---|
| 3043 | return hr;
|
---|
[42084] | 3044 | }
|
---|
| 3045 |
|
---|
[55631] | 3046 | HRESULT GuestSession::fileOpen(const com::Utf8Str &aPath, FileAccessMode_T aAccessMode, FileOpenAction_T aOpenAction,
|
---|
[50874] | 3047 | ULONG aCreationMode, ComPtr<IGuestFile> &aFile)
|
---|
[42084] | 3048 | {
|
---|
[42194] | 3049 | LogFlowThisFuncEnter();
|
---|
[55668] | 3050 | const std::vector<FileOpenExFlags_T> EmptyFlags;
|
---|
| 3051 | return fileOpenEx(aPath, aAccessMode, aOpenAction, FileSharingMode_All, aCreationMode, EmptyFlags, aFile);
|
---|
[47817] | 3052 | }
|
---|
| 3053 |
|
---|
[55631] | 3054 | HRESULT GuestSession::fileOpenEx(const com::Utf8Str &aPath, FileAccessMode_T aAccessMode, FileOpenAction_T aOpenAction,
|
---|
[55668] | 3055 | FileSharingMode_T aSharingMode, ULONG aCreationMode,
|
---|
| 3056 | const std::vector<FileOpenExFlags_T> &aFlags, ComPtr<IGuestFile> &aFile)
|
---|
[47817] | 3057 | {
|
---|
| 3058 | LogFlowThisFuncEnter();
|
---|
| 3059 |
|
---|
[50727] | 3060 | if (RT_UNLIKELY((aPath.c_str()) == NULL || *(aPath.c_str()) == '\0'))
|
---|
[42611] | 3061 | return setError(E_INVALIDARG, tr("No file to open specified"));
|
---|
| 3062 |
|
---|
[50727] | 3063 | HRESULT hr = i_isReadyExternal();
|
---|
[45415] | 3064 | if (FAILED(hr))
|
---|
| 3065 | return hr;
|
---|
| 3066 |
|
---|
[44863] | 3067 | GuestFileOpenInfo openInfo;
|
---|
[50727] | 3068 | openInfo.mFileName = aPath;
|
---|
[44863] | 3069 | openInfo.mCreationMode = aCreationMode;
|
---|
| 3070 |
|
---|
[55631] | 3071 | /* convert + validate aAccessMode to the old format. */
|
---|
| 3072 | openInfo.mAccessMode = aAccessMode;
|
---|
| 3073 | switch (aAccessMode)
|
---|
| 3074 | {
|
---|
| 3075 | case (FileAccessMode_T)FileAccessMode_ReadOnly: openInfo.mpszAccessMode = "r"; break;
|
---|
| 3076 | case (FileAccessMode_T)FileAccessMode_WriteOnly: openInfo.mpszAccessMode = "w"; break;
|
---|
| 3077 | case (FileAccessMode_T)FileAccessMode_ReadWrite: openInfo.mpszAccessMode = "r+"; break;
|
---|
| 3078 | case (FileAccessMode_T)FileAccessMode_AppendOnly:
|
---|
[69046] | 3079 | RT_FALL_THRU();
|
---|
[55631] | 3080 | case (FileAccessMode_T)FileAccessMode_AppendRead:
|
---|
| 3081 | return setError(E_NOTIMPL, tr("Append access modes are not yet implemented"));
|
---|
| 3082 | default:
|
---|
| 3083 | return setError(E_INVALIDARG, tr("Unknown FileAccessMode value %u (%#x)"), aAccessMode, aAccessMode);
|
---|
| 3084 | }
|
---|
[47817] | 3085 |
|
---|
[55631] | 3086 | /* convert + validate aOpenAction to the old format. */
|
---|
| 3087 | openInfo.mOpenAction = aOpenAction;
|
---|
| 3088 | switch (aOpenAction)
|
---|
| 3089 | {
|
---|
| 3090 | case (FileOpenAction_T)FileOpenAction_OpenExisting: openInfo.mpszOpenAction = "oe"; break;
|
---|
| 3091 | case (FileOpenAction_T)FileOpenAction_OpenOrCreate: openInfo.mpszOpenAction = "oc"; break;
|
---|
| 3092 | case (FileOpenAction_T)FileOpenAction_CreateNew: openInfo.mpszOpenAction = "ce"; break;
|
---|
| 3093 | case (FileOpenAction_T)FileOpenAction_CreateOrReplace: openInfo.mpszOpenAction = "ca"; break;
|
---|
| 3094 | case (FileOpenAction_T)FileOpenAction_OpenExistingTruncated: openInfo.mpszOpenAction = "ot"; break;
|
---|
| 3095 | case (FileOpenAction_T)FileOpenAction_AppendOrCreate:
|
---|
[55633] | 3096 | openInfo.mpszOpenAction = "oa"; /** @todo get rid of this one and implement AppendOnly/AppendRead. */
|
---|
[55631] | 3097 | break;
|
---|
| 3098 | default:
|
---|
| 3099 | return setError(E_INVALIDARG, tr("Unknown FileOpenAction value %u (%#x)"), aAccessMode, aAccessMode);
|
---|
| 3100 | }
|
---|
| 3101 |
|
---|
| 3102 | /* validate aSharingMode */
|
---|
| 3103 | openInfo.mSharingMode = aSharingMode;
|
---|
| 3104 | switch (aSharingMode)
|
---|
| 3105 | {
|
---|
| 3106 | case (FileSharingMode_T)FileSharingMode_All: /* OK */ break;
|
---|
| 3107 | case (FileSharingMode_T)FileSharingMode_Read:
|
---|
| 3108 | case (FileSharingMode_T)FileSharingMode_Write:
|
---|
| 3109 | case (FileSharingMode_T)FileSharingMode_ReadWrite:
|
---|
| 3110 | case (FileSharingMode_T)FileSharingMode_Delete:
|
---|
| 3111 | case (FileSharingMode_T)FileSharingMode_ReadDelete:
|
---|
| 3112 | case (FileSharingMode_T)FileSharingMode_WriteDelete:
|
---|
| 3113 | return setError(E_NOTIMPL, tr("Only FileSharingMode_All is currently implemented"));
|
---|
| 3114 |
|
---|
| 3115 | default:
|
---|
| 3116 | return setError(E_INVALIDARG, tr("Unknown FileOpenAction value %u (%#x)"), aAccessMode, aAccessMode);
|
---|
| 3117 | }
|
---|
| 3118 |
|
---|
[55668] | 3119 | /* Combine and validate flags. */
|
---|
| 3120 | uint32_t fOpenEx = 0;
|
---|
| 3121 | for (size_t i = 0; i < aFlags.size(); i++)
|
---|
| 3122 | fOpenEx = aFlags[i];
|
---|
| 3123 | if (fOpenEx)
|
---|
| 3124 | return setError(E_INVALIDARG, tr("Unsupported FileOpenExFlags values in aFlags (%#x)"), fOpenEx);
|
---|
| 3125 | openInfo.mfOpenEx = fOpenEx;
|
---|
| 3126 |
|
---|
[55631] | 3127 | ComObjPtr <GuestFile> pFile;
|
---|
| 3128 | int guestRc;
|
---|
| 3129 | int vrc = i_fileOpenInternal(openInfo, pFile, &guestRc);
|
---|
[43162] | 3130 | if (RT_SUCCESS(vrc))
|
---|
[42611] | 3131 | /* Return directory object to the caller. */
|
---|
[50727] | 3132 | hr = pFile.queryInterfaceTo(aFile.asOutParam());
|
---|
[42611] | 3133 | else
|
---|
| 3134 | {
|
---|
[43162] | 3135 | switch (vrc)
|
---|
[42611] | 3136 | {
|
---|
[47781] | 3137 | case VERR_NOT_SUPPORTED:
|
---|
| 3138 | hr = setError(VBOX_E_IPRT_ERROR,
|
---|
| 3139 | tr("Handling guest files not supported by installed Guest Additions"));
|
---|
| 3140 | break;
|
---|
| 3141 |
|
---|
[45078] | 3142 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[50618] | 3143 | hr = GuestFile::i_setErrorExternal(this, guestRc);
|
---|
[43162] | 3144 | break;
|
---|
[42611] | 3145 |
|
---|
| 3146 | default:
|
---|
[45109] | 3147 | hr = setError(VBOX_E_IPRT_ERROR, tr("Opening guest file \"%s\" failed: %Rrc"),
|
---|
[50727] | 3148 | aPath.c_str(), vrc);
|
---|
[43162] | 3149 | break;
|
---|
[42611] | 3150 | }
|
---|
| 3151 | }
|
---|
| 3152 |
|
---|
| 3153 | return hr;
|
---|
[42084] | 3154 | }
|
---|
| 3155 |
|
---|
[55631] | 3156 | HRESULT GuestSession::fileQuerySize(const com::Utf8Str &aPath, BOOL aFollowSymlinks, LONG64 *aSize)
|
---|
[42084] | 3157 | {
|
---|
[61792] | 3158 | if (aPath.isEmpty())
|
---|
| 3159 | return setError(E_INVALIDARG, tr("No path specified"));
|
---|
[42194] | 3160 |
|
---|
[42530] | 3161 | HRESULT hr = S_OK;
|
---|
| 3162 |
|
---|
[43162] | 3163 | int64_t llSize; int guestRc;
|
---|
[55631] | 3164 | int vrc = i_fileQuerySizeInternal(aPath, aFollowSymlinks != FALSE, &llSize, &guestRc);
|
---|
[43162] | 3165 | if (RT_SUCCESS(vrc))
|
---|
[61792] | 3166 | {
|
---|
[42530] | 3167 | *aSize = llSize;
|
---|
[61792] | 3168 | }
|
---|
[42530] | 3169 | else
|
---|
| 3170 | {
|
---|
[61792] | 3171 | if (GuestProcess::i_isGuestError(vrc))
|
---|
[42530] | 3172 | {
|
---|
[61792] | 3173 | hr = GuestProcess::i_setErrorExternal(this, guestRc);
|
---|
[42530] | 3174 | }
|
---|
[61792] | 3175 | else
|
---|
| 3176 | hr = setError(VBOX_E_IPRT_ERROR, tr("Querying file size failed: %Rrc"), vrc);
|
---|
[42530] | 3177 | }
|
---|
| 3178 |
|
---|
| 3179 | return hr;
|
---|
[42084] | 3180 | }
|
---|
| 3181 |
|
---|
[55631] | 3182 | HRESULT GuestSession::fsObjExists(const com::Utf8Str &aPath, BOOL aFollowSymlinks, BOOL *aExists)
|
---|
[42084] | 3183 | {
|
---|
[61792] | 3184 | if (aPath.isEmpty())
|
---|
| 3185 | return setError(E_INVALIDARG, tr("No path specified"));
|
---|
[42194] | 3186 |
|
---|
[61792] | 3187 | LogFlowThisFunc(("aPath=%s, aFollowSymlinks=%RTbool\n", aPath.c_str(), RT_BOOL(aFollowSymlinks)));
|
---|
| 3188 |
|
---|
[55613] | 3189 | HRESULT hrc = S_OK;
|
---|
[61792] | 3190 |
|
---|
[55613] | 3191 | *aExists = false;
|
---|
[61792] | 3192 |
|
---|
| 3193 | GuestFsObjData objData;
|
---|
| 3194 | int rcGuest;
|
---|
| 3195 | int vrc = i_fsQueryInfoInternal(aPath, aFollowSymlinks != FALSE, objData, &rcGuest);
|
---|
| 3196 | if (RT_SUCCESS(vrc))
|
---|
[55613] | 3197 | {
|
---|
[61792] | 3198 | *aExists = TRUE;
|
---|
| 3199 | }
|
---|
| 3200 | else
|
---|
| 3201 | {
|
---|
| 3202 | if (GuestProcess::i_isGuestError(vrc))
|
---|
| 3203 | {
|
---|
| 3204 | if ( rcGuest == VERR_NOT_A_FILE
|
---|
| 3205 | || rcGuest == VERR_PATH_NOT_FOUND
|
---|
| 3206 | || rcGuest == VERR_FILE_NOT_FOUND
|
---|
| 3207 | || rcGuest == VERR_INVALID_NAME)
|
---|
| 3208 | {
|
---|
| 3209 | hrc = S_OK; /* Ignore these vrc values. */
|
---|
| 3210 | }
|
---|
| 3211 | else
|
---|
| 3212 | hrc = GuestProcess::i_setErrorExternal(this, rcGuest);
|
---|
| 3213 | }
|
---|
[55613] | 3214 | else
|
---|
| 3215 | hrc = setErrorVrc(vrc, tr("Querying file information for \"%s\" failed: %Rrc"), aPath.c_str(), vrc);
|
---|
| 3216 | }
|
---|
[61792] | 3217 |
|
---|
[55613] | 3218 | return hrc;
|
---|
| 3219 | }
|
---|
| 3220 |
|
---|
[55631] | 3221 | HRESULT GuestSession::fsObjQueryInfo(const com::Utf8Str &aPath, BOOL aFollowSymlinks, ComPtr<IGuestFsObjInfo> &aInfo)
|
---|
[55613] | 3222 | {
|
---|
[61792] | 3223 | if (aPath.isEmpty())
|
---|
| 3224 | return setError(E_INVALIDARG, tr("No path specified"));
|
---|
[55613] | 3225 |
|
---|
[61792] | 3226 | LogFlowThisFunc(("aPath=%s, aFollowSymlinks=%RTbool\n", aPath.c_str(), RT_BOOL(aFollowSymlinks)));
|
---|
| 3227 |
|
---|
[55613] | 3228 | HRESULT hrc = S_OK;
|
---|
[61792] | 3229 |
|
---|
| 3230 | GuestFsObjData Info; int guestRc;
|
---|
| 3231 | int vrc = i_fsQueryInfoInternal(aPath, aFollowSymlinks != FALSE, Info, &guestRc);
|
---|
| 3232 | if (RT_SUCCESS(vrc))
|
---|
[55613] | 3233 | {
|
---|
[61792] | 3234 | ComObjPtr<GuestFsObjInfo> ptrFsObjInfo;
|
---|
| 3235 | hrc = ptrFsObjInfo.createObject();
|
---|
| 3236 | if (SUCCEEDED(hrc))
|
---|
[55613] | 3237 | {
|
---|
[61792] | 3238 | vrc = ptrFsObjInfo->init(Info);
|
---|
| 3239 | if (RT_SUCCESS(vrc))
|
---|
| 3240 | hrc = ptrFsObjInfo.queryInterfaceTo(aInfo.asOutParam());
|
---|
| 3241 | else
|
---|
| 3242 | hrc = setErrorVrc(vrc);
|
---|
[55613] | 3243 | }
|
---|
[61792] | 3244 | }
|
---|
| 3245 | else
|
---|
| 3246 | {
|
---|
| 3247 | if (GuestProcess::i_isGuestError(vrc))
|
---|
| 3248 | {
|
---|
| 3249 | hrc = GuestProcess::i_setErrorExternal(this, guestRc);
|
---|
| 3250 | }
|
---|
[55613] | 3251 | else
|
---|
| 3252 | hrc = setErrorVrc(vrc, tr("Querying file information for \"%s\" failed: %Rrc"), aPath.c_str(), vrc);
|
---|
| 3253 | }
|
---|
[61792] | 3254 |
|
---|
[55613] | 3255 | return hrc;
|
---|
| 3256 | }
|
---|
| 3257 |
|
---|
[55631] | 3258 | HRESULT GuestSession::fsObjRemove(const com::Utf8Str &aPath)
|
---|
| 3259 | {
|
---|
| 3260 | if (RT_UNLIKELY(aPath.isEmpty()))
|
---|
[61792] | 3261 | return setError(E_INVALIDARG, tr("No path specified"));
|
---|
[55631] | 3262 |
|
---|
[61792] | 3263 | LogFlowThisFunc(("aPath=%s\n", aPath.c_str()));
|
---|
[55631] | 3264 |
|
---|
[61792] | 3265 | HRESULT hrc = S_OK;
|
---|
| 3266 |
|
---|
[55631] | 3267 | int guestRc;
|
---|
| 3268 | int vrc = i_fileRemoveInternal(aPath, &guestRc);
|
---|
| 3269 | if (RT_FAILURE(vrc))
|
---|
| 3270 | {
|
---|
[61792] | 3271 | if (GuestProcess::i_isGuestError(vrc))
|
---|
[55631] | 3272 | {
|
---|
[61792] | 3273 | hrc = GuestProcess::i_setErrorExternal(this, guestRc);
|
---|
[55631] | 3274 | }
|
---|
[61792] | 3275 | else
|
---|
| 3276 | hrc = setError(VBOX_E_IPRT_ERROR, tr("Removing file \"%s\" failed: %Rrc"), aPath.c_str(), vrc);
|
---|
[55631] | 3277 | }
|
---|
| 3278 |
|
---|
[61792] | 3279 | return hrc;
|
---|
[55631] | 3280 | }
|
---|
| 3281 |
|
---|
| 3282 | HRESULT GuestSession::fsObjRename(const com::Utf8Str &aSource,
|
---|
| 3283 | const com::Utf8Str &aDestination,
|
---|
| 3284 | const std::vector<FsObjRenameFlag_T> &aFlags)
|
---|
| 3285 | {
|
---|
| 3286 | if (RT_UNLIKELY(aSource.isEmpty()))
|
---|
| 3287 | return setError(E_INVALIDARG, tr("No source path specified"));
|
---|
| 3288 |
|
---|
| 3289 | if (RT_UNLIKELY(aDestination.isEmpty()))
|
---|
| 3290 | return setError(E_INVALIDARG, tr("No destination path specified"));
|
---|
| 3291 |
|
---|
[61792] | 3292 | LogFlowThisFunc(("aSource=%s, aDestination=%s\n", aSource.c_str(), aDestination.c_str()));
|
---|
| 3293 |
|
---|
[55631] | 3294 | HRESULT hr = i_isReadyExternal();
|
---|
| 3295 | if (FAILED(hr))
|
---|
| 3296 | return hr;
|
---|
| 3297 |
|
---|
| 3298 | /* Combine, validate and convert flags. */
|
---|
| 3299 | uint32_t fApiFlags = 0;
|
---|
| 3300 | for (size_t i = 0; i < aFlags.size(); i++)
|
---|
| 3301 | fApiFlags |= aFlags[i];
|
---|
| 3302 | if (fApiFlags & ~((uint32_t)FsObjRenameFlag_NoReplace | (uint32_t)FsObjRenameFlag_Replace))
|
---|
| 3303 | return setError(E_INVALIDARG, tr("Unknown rename flag: %#x"), fApiFlags);
|
---|
| 3304 |
|
---|
| 3305 | AssertCompile(FsObjRenameFlag_NoReplace == 0);
|
---|
| 3306 | AssertCompile(FsObjRenameFlag_Replace != 0);
|
---|
| 3307 | uint32_t fBackend;
|
---|
| 3308 | if ((fApiFlags & ((uint32_t)FsObjRenameFlag_NoReplace | (uint32_t)FsObjRenameFlag_Replace)) == FsObjRenameFlag_Replace)
|
---|
| 3309 | fBackend = PATHRENAME_FLAG_REPLACE;
|
---|
| 3310 | else
|
---|
| 3311 | fBackend = PATHRENAME_FLAG_NO_REPLACE;
|
---|
| 3312 |
|
---|
| 3313 | /* Call worker to do the job. */
|
---|
| 3314 | int guestRc;
|
---|
| 3315 | int vrc = i_pathRenameInternal(aSource, aDestination, fBackend, &guestRc);
|
---|
| 3316 | if (RT_FAILURE(vrc))
|
---|
| 3317 | {
|
---|
| 3318 | switch (vrc)
|
---|
| 3319 | {
|
---|
| 3320 | case VERR_NOT_SUPPORTED:
|
---|
| 3321 | hr = setError(VBOX_E_IPRT_ERROR,
|
---|
| 3322 | tr("Handling renaming guest directories not supported by installed Guest Additions"));
|
---|
| 3323 | break;
|
---|
| 3324 |
|
---|
| 3325 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
| 3326 | hr = setError(VBOX_E_IPRT_ERROR,
|
---|
| 3327 | tr("Renaming guest directory failed: %Rrc"), guestRc);
|
---|
| 3328 | break;
|
---|
| 3329 |
|
---|
| 3330 | default:
|
---|
| 3331 | hr = setError(VBOX_E_IPRT_ERROR, tr("Renaming guest directory \"%s\" failed: %Rrc"),
|
---|
| 3332 | aSource.c_str(), vrc);
|
---|
| 3333 | break;
|
---|
| 3334 | }
|
---|
| 3335 | }
|
---|
| 3336 |
|
---|
| 3337 | return hr;
|
---|
| 3338 | }
|
---|
| 3339 |
|
---|
| 3340 | HRESULT GuestSession::fsObjMove(const com::Utf8Str &aSource, const com::Utf8Str &aDestination,
|
---|
| 3341 | const std::vector<FsObjMoveFlags_T> &aFlags, ComPtr<IProgress> &aProgress)
|
---|
| 3342 | {
|
---|
[63251] | 3343 | RT_NOREF(aSource, aDestination, aFlags, aProgress);
|
---|
[55631] | 3344 | ReturnComNotImplemented();
|
---|
| 3345 | }
|
---|
| 3346 |
|
---|
| 3347 | HRESULT GuestSession::fsObjSetACL(const com::Utf8Str &aPath, BOOL aFollowSymlinks, const com::Utf8Str &aAcl, ULONG aMode)
|
---|
| 3348 | {
|
---|
[63251] | 3349 | RT_NOREF(aPath, aFollowSymlinks, aAcl, aMode);
|
---|
[55631] | 3350 | ReturnComNotImplemented();
|
---|
| 3351 | }
|
---|
| 3352 |
|
---|
| 3353 |
|
---|
[55535] | 3354 | HRESULT GuestSession::processCreate(const com::Utf8Str &aExecutable, const std::vector<com::Utf8Str> &aArguments,
|
---|
[50874] | 3355 | const std::vector<com::Utf8Str> &aEnvironment,
|
---|
| 3356 | const std::vector<ProcessCreateFlag_T> &aFlags,
|
---|
| 3357 | ULONG aTimeoutMS, ComPtr<IGuestProcess> &aGuestProcess)
|
---|
[42084] | 3358 | {
|
---|
[42194] | 3359 | LogFlowThisFuncEnter();
|
---|
[42084] | 3360 |
|
---|
[50727] | 3361 | std::vector<LONG> affinityIgnored;
|
---|
[42105] | 3362 |
|
---|
[55535] | 3363 | return processCreateEx(aExecutable, aArguments, aEnvironment, aFlags, aTimeoutMS, ProcessPriority_Default,
|
---|
[50874] | 3364 | affinityIgnored, aGuestProcess);
|
---|
[42084] | 3365 | }
|
---|
| 3366 |
|
---|
[55535] | 3367 | HRESULT GuestSession::processCreateEx(const com::Utf8Str &aExecutable, const std::vector<com::Utf8Str> &aArguments,
|
---|
[50874] | 3368 | const std::vector<com::Utf8Str> &aEnvironment,
|
---|
| 3369 | const std::vector<ProcessCreateFlag_T> &aFlags, ULONG aTimeoutMS,
|
---|
| 3370 | ProcessPriority_T aPriority, const std::vector<LONG> &aAffinity,
|
---|
| 3371 | ComPtr<IGuestProcess> &aGuestProcess)
|
---|
[42084] | 3372 | {
|
---|
[42194] | 3373 | LogFlowThisFuncEnter();
|
---|
| 3374 |
|
---|
[55588] | 3375 | /** @todo r=bird: Check input better? aPriority is passed on to the guest
|
---|
| 3376 | * without any validation. Flags not existing in this vbox version are
|
---|
| 3377 | * ignored, potentially doing something entirely different than what the
|
---|
| 3378 | * caller had in mind. */
|
---|
| 3379 |
|
---|
[55535] | 3380 | /*
|
---|
| 3381 | * Must have an executable to execute. If none is given, we try use the
|
---|
| 3382 | * zero'th argument.
|
---|
| 3383 | */
|
---|
| 3384 | const char *pszExecutable = aExecutable.c_str();
|
---|
| 3385 | if (RT_UNLIKELY(pszExecutable == NULL || *pszExecutable == '\0'))
|
---|
| 3386 | {
|
---|
| 3387 | if (aArguments.size() > 0)
|
---|
| 3388 | pszExecutable = aArguments[0].c_str();
|
---|
| 3389 | if (pszExecutable == NULL || *pszExecutable == '\0')
|
---|
| 3390 | return setError(E_INVALIDARG, tr("No command to execute specified"));
|
---|
| 3391 | }
|
---|
[42214] | 3392 |
|
---|
[55535] | 3393 | /*
|
---|
| 3394 | * Check the session.
|
---|
| 3395 | */
|
---|
[50727] | 3396 | HRESULT hr = i_isReadyExternal();
|
---|
[45415] | 3397 | if (FAILED(hr))
|
---|
| 3398 | return hr;
|
---|
| 3399 |
|
---|
[55535] | 3400 | /*
|
---|
| 3401 | * Build the process startup info.
|
---|
| 3402 | */
|
---|
[42611] | 3403 | GuestProcessStartupInfo procInfo;
|
---|
[42160] | 3404 |
|
---|
[55535] | 3405 | /* Executable and arguments. */
|
---|
| 3406 | procInfo.mExecutable = pszExecutable;
|
---|
[50727] | 3407 | if (aArguments.size())
|
---|
| 3408 | for (size_t i = 0; i < aArguments.size(); i++)
|
---|
| 3409 | procInfo.mArguments.push_back(aArguments[i]);
|
---|
[42111] | 3410 |
|
---|
[55588] | 3411 | /* Combine the environment changes associated with the ones passed in by
|
---|
| 3412 | the caller, giving priority to the latter. The changes are putenv style
|
---|
| 3413 | and will be applied to the standard environment for the guest user. */
|
---|
[55591] | 3414 | int vrc = procInfo.mEnvironmentChanges.copy(mData.mEnvironmentChanges);
|
---|
[55588] | 3415 | if (RT_SUCCESS(vrc))
|
---|
[55591] | 3416 | vrc = procInfo.mEnvironmentChanges.applyPutEnvArray(aEnvironment);
|
---|
[55588] | 3417 | if (RT_SUCCESS(vrc))
|
---|
[42160] | 3418 | {
|
---|
[55535] | 3419 | /* Convert the flag array into a mask. */
|
---|
[50727] | 3420 | if (aFlags.size())
|
---|
| 3421 | for (size_t i = 0; i < aFlags.size(); i++)
|
---|
| 3422 | procInfo.mFlags |= aFlags[i];
|
---|
[42160] | 3423 |
|
---|
[42171] | 3424 | procInfo.mTimeoutMS = aTimeoutMS;
|
---|
[42160] | 3425 |
|
---|
[55535] | 3426 | /** @todo use RTCPUSET instead of archaic 64-bit variables! */
|
---|
[50727] | 3427 | if (aAffinity.size())
|
---|
| 3428 | for (size_t i = 0; i < aAffinity.size(); i++)
|
---|
| 3429 | if (aAffinity[i])
|
---|
[44863] | 3430 | procInfo.mAffinity |= (uint64_t)1 << i;
|
---|
[42160] | 3431 |
|
---|
[42171] | 3432 | procInfo.mPriority = aPriority;
|
---|
[42160] | 3433 |
|
---|
[55535] | 3434 | /*
|
---|
| 3435 | * Create a guest process object.
|
---|
| 3436 | */
|
---|
[42354] | 3437 | ComObjPtr<GuestProcess> pProcess;
|
---|
[55588] | 3438 | vrc = i_processCreateExInternal(procInfo, pProcess);
|
---|
| 3439 | if (RT_SUCCESS(vrc))
|
---|
[42354] | 3440 | {
|
---|
[60640] | 3441 | ComPtr<IGuestProcess> pIProcess;
|
---|
| 3442 | hr = pProcess.queryInterfaceTo(pIProcess.asOutParam());
|
---|
[55588] | 3443 | if (SUCCEEDED(hr))
|
---|
[55535] | 3444 | {
|
---|
| 3445 | /*
|
---|
| 3446 | * Start the process.
|
---|
| 3447 | */
|
---|
[55588] | 3448 | vrc = pProcess->i_startProcessAsync();
|
---|
| 3449 | if (RT_SUCCESS(vrc))
|
---|
[55535] | 3450 | {
|
---|
[60640] | 3451 | aGuestProcess = pIProcess;
|
---|
| 3452 |
|
---|
[55588] | 3453 | LogFlowFuncLeaveRC(vrc);
|
---|
| 3454 | return S_OK;
|
---|
[55535] | 3455 | }
|
---|
[55588] | 3456 |
|
---|
| 3457 | hr = setErrorVrc(vrc, tr("Failed to start guest process: %Rrc"), vrc);
|
---|
[55535] | 3458 | }
|
---|
[42354] | 3459 | }
|
---|
[55588] | 3460 | else if (vrc == VERR_MAX_PROCS_REACHED)
|
---|
| 3461 | hr = setErrorVrc(vrc, tr("Maximum number of concurrent guest processes per session (%u) reached"),
|
---|
| 3462 | VBOX_GUESTCTRL_MAX_OBJECTS);
|
---|
| 3463 | else
|
---|
| 3464 | hr = setErrorVrc(vrc, tr("Failed to create guest process object: %Rrc"), vrc);
|
---|
[42171] | 3465 | }
|
---|
[55588] | 3466 | else
|
---|
| 3467 | hr = setErrorVrc(vrc, tr("Failed to set up the environment: %Rrc"), vrc);
|
---|
[42194] | 3468 |
|
---|
[55588] | 3469 | LogFlowFuncLeaveRC(vrc);
|
---|
[42194] | 3470 | return hr;
|
---|
[42084] | 3471 | }
|
---|
| 3472 |
|
---|
[50727] | 3473 | HRESULT GuestSession::processGet(ULONG aPid, ComPtr<IGuestProcess> &aGuestProcess)
|
---|
| 3474 |
|
---|
[42084] | 3475 | {
|
---|
[50727] | 3476 | LogFlowThisFunc(("PID=%RU32\n", aPid));
|
---|
[42194] | 3477 |
|
---|
[50727] | 3478 | if (aPid == 0)
|
---|
[42214] | 3479 | return setError(E_INVALIDARG, tr("No valid process ID (PID) specified"));
|
---|
| 3480 |
|
---|
| 3481 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 3482 |
|
---|
| 3483 | HRESULT hr = S_OK;
|
---|
| 3484 |
|
---|
| 3485 | ComObjPtr<GuestProcess> pProcess;
|
---|
[50727] | 3486 | int rc = i_processGetByPID(aPid, &pProcess);
|
---|
[42214] | 3487 | if (RT_FAILURE(rc))
|
---|
[50727] | 3488 | hr = setError(E_INVALIDARG, tr("No process with PID %RU32 found"), aPid);
|
---|
[42214] | 3489 |
|
---|
| 3490 | /* This will set (*aProcess) to NULL if pProgress is NULL. */
|
---|
[50727] | 3491 | HRESULT hr2 = pProcess.queryInterfaceTo(aGuestProcess.asOutParam());
|
---|
[42214] | 3492 | if (SUCCEEDED(hr))
|
---|
| 3493 | hr = hr2;
|
---|
| 3494 |
|
---|
[50727] | 3495 | LogFlowThisFunc(("aProcess=%p, hr=%Rhrc\n", (IGuestProcess*)aGuestProcess, hr));
|
---|
[42214] | 3496 | return hr;
|
---|
[42084] | 3497 | }
|
---|
| 3498 |
|
---|
[50727] | 3499 | HRESULT GuestSession::symlinkCreate(const com::Utf8Str &aSource, const com::Utf8Str &aTarget, SymlinkType_T aType)
|
---|
[42084] | 3500 | {
|
---|
[63251] | 3501 | RT_NOREF(aSource, aTarget, aType);
|
---|
[42084] | 3502 | ReturnComNotImplemented();
|
---|
| 3503 | }
|
---|
| 3504 |
|
---|
[50727] | 3505 | HRESULT GuestSession::symlinkExists(const com::Utf8Str &aSymlink, BOOL *aExists)
|
---|
| 3506 |
|
---|
[42084] | 3507 | {
|
---|
[63251] | 3508 | RT_NOREF(aSymlink, aExists);
|
---|
[42084] | 3509 | ReturnComNotImplemented();
|
---|
| 3510 | }
|
---|
| 3511 |
|
---|
[50874] | 3512 | HRESULT GuestSession::symlinkRead(const com::Utf8Str &aSymlink, const std::vector<SymlinkReadFlag_T> &aFlags,
|
---|
| 3513 | com::Utf8Str &aTarget)
|
---|
[42084] | 3514 | {
|
---|
[63251] | 3515 | RT_NOREF(aSymlink, aFlags, aTarget);
|
---|
[42084] | 3516 | ReturnComNotImplemented();
|
---|
| 3517 | }
|
---|
| 3518 |
|
---|
[50727] | 3519 | HRESULT GuestSession::waitFor(ULONG aWaitFor, ULONG aTimeoutMS, GuestSessionWaitResult_T *aReason)
|
---|
[45010] | 3520 | {
|
---|
| 3521 | LogFlowThisFuncEnter();
|
---|
| 3522 |
|
---|
| 3523 | /*
|
---|
| 3524 | * Note: Do not hold any locks here while waiting!
|
---|
| 3525 | */
|
---|
| 3526 | HRESULT hr = S_OK;
|
---|
| 3527 |
|
---|
| 3528 | int guestRc; GuestSessionWaitResult_T waitResult;
|
---|
[50727] | 3529 | int vrc = i_waitFor(aWaitFor, aTimeoutMS, waitResult, &guestRc);
|
---|
[45010] | 3530 | if (RT_SUCCESS(vrc))
|
---|
| 3531 | *aReason = waitResult;
|
---|
| 3532 | else
|
---|
| 3533 | {
|
---|
| 3534 | switch (vrc)
|
---|
| 3535 | {
|
---|
[45078] | 3536 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[50727] | 3537 | hr = GuestSession::i_setErrorExternal(this, guestRc);
|
---|
[45010] | 3538 | break;
|
---|
| 3539 |
|
---|
| 3540 | case VERR_TIMEOUT:
|
---|
| 3541 | *aReason = GuestSessionWaitResult_Timeout;
|
---|
| 3542 | break;
|
---|
| 3543 |
|
---|
| 3544 | default:
|
---|
| 3545 | {
|
---|
| 3546 | const char *pszSessionName = mData.mSession.mName.c_str();
|
---|
| 3547 | hr = setError(VBOX_E_IPRT_ERROR,
|
---|
| 3548 | tr("Waiting for guest session \"%s\" failed: %Rrc"),
|
---|
| 3549 | pszSessionName ? pszSessionName : tr("Unnamed"), vrc);
|
---|
| 3550 | break;
|
---|
| 3551 | }
|
---|
| 3552 | }
|
---|
| 3553 | }
|
---|
| 3554 |
|
---|
| 3555 | LogFlowFuncLeaveRC(vrc);
|
---|
| 3556 | return hr;
|
---|
| 3557 | }
|
---|
| 3558 |
|
---|
[50874] | 3559 | HRESULT GuestSession::waitForArray(const std::vector<GuestSessionWaitForFlag_T> &aWaitFor, ULONG aTimeoutMS,
|
---|
| 3560 | GuestSessionWaitResult_T *aReason)
|
---|
[45010] | 3561 | {
|
---|
| 3562 | LogFlowThisFuncEnter();
|
---|
| 3563 |
|
---|
| 3564 | /*
|
---|
| 3565 | * Note: Do not hold any locks here while waiting!
|
---|
| 3566 | */
|
---|
| 3567 | uint32_t fWaitFor = GuestSessionWaitForFlag_None;
|
---|
[50727] | 3568 | for (size_t i = 0; i < aWaitFor.size(); i++)
|
---|
| 3569 | fWaitFor |= aWaitFor[i];
|
---|
[45010] | 3570 |
|
---|
| 3571 | return WaitFor(fWaitFor, aTimeoutMS, aReason);
|
---|
| 3572 | }
|
---|
| 3573 |
|
---|