[42084] | 1 |
|
---|
| 2 | /* $Id: GuestSessionImpl.cpp 47469 2013-07-30 09:43:14Z vboxsync $ */
|
---|
| 3 | /** @file
|
---|
[44863] | 4 | * VirtualBox Main - Guest session handling.
|
---|
[42084] | 5 | */
|
---|
| 6 |
|
---|
| 7 | /*
|
---|
[44863] | 8 | * Copyright (C) 2012-2013 Oracle Corporation
|
---|
[42084] | 9 | *
|
---|
| 10 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
| 11 | * available from http://www.virtualbox.org. This file is free software;
|
---|
| 12 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
| 13 | * General Public License (GPL) as published by the Free Software
|
---|
| 14 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
| 15 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
| 16 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 |
|
---|
| 20 | /*******************************************************************************
|
---|
| 21 | * Header Files *
|
---|
| 22 | *******************************************************************************/
|
---|
[42105] | 23 | #include "GuestImpl.h"
|
---|
[42084] | 24 | #include "GuestSessionImpl.h"
|
---|
[42478] | 25 | #include "GuestCtrlImplPrivate.h"
|
---|
[45805] | 26 | #include "VirtualBoxErrorInfoImpl.h"
|
---|
[42084] | 27 |
|
---|
| 28 | #include "Global.h"
|
---|
| 29 | #include "AutoCaller.h"
|
---|
[42566] | 30 | #include "ProgressImpl.h"
|
---|
[45415] | 31 | #include "VBoxEvents.h"
|
---|
[44863] | 32 | #include "VMMDev.h"
|
---|
[42084] | 33 |
|
---|
[42567] | 34 | #include <memory> /* For auto_ptr. */
|
---|
| 35 |
|
---|
[45415] | 36 | #include <iprt/cpp/utils.h> /* For unconst(). */
|
---|
[42171] | 37 | #include <iprt/env.h>
|
---|
[42573] | 38 | #include <iprt/file.h> /* For CopyTo/From. */
|
---|
[42171] | 39 |
|
---|
[42084] | 40 | #include <VBox/com/array.h>
|
---|
[45415] | 41 | #include <VBox/com/listeners.h>
|
---|
[42461] | 42 | #include <VBox/version.h>
|
---|
[42084] | 43 |
|
---|
[42897] | 44 | #ifdef LOG_GROUP
|
---|
| 45 | #undef LOG_GROUP
|
---|
| 46 | #endif
|
---|
| 47 | #define LOG_GROUP LOG_GROUP_GUEST_CONTROL
|
---|
| 48 | #include <VBox/log.h>
|
---|
[42084] | 49 |
|
---|
[44935] | 50 |
|
---|
| 51 | /**
|
---|
| 52 | * Base class representing an internal
|
---|
| 53 | * asynchronous session task.
|
---|
| 54 | */
|
---|
| 55 | class GuestSessionTaskInternal
|
---|
| 56 | {
|
---|
| 57 | public:
|
---|
| 58 |
|
---|
| 59 | GuestSessionTaskInternal(GuestSession *pSession)
|
---|
| 60 | : mSession(pSession),
|
---|
| 61 | mRC(VINF_SUCCESS) { }
|
---|
| 62 |
|
---|
| 63 | virtual ~GuestSessionTaskInternal(void) { }
|
---|
| 64 |
|
---|
| 65 | int rc(void) const { return mRC; }
|
---|
| 66 | bool isOk(void) const { return RT_SUCCESS(mRC); }
|
---|
| 67 | const ComObjPtr<GuestSession> &Session(void) const { return mSession; }
|
---|
| 68 |
|
---|
| 69 | protected:
|
---|
| 70 |
|
---|
| 71 | const ComObjPtr<GuestSession> mSession;
|
---|
| 72 | int mRC;
|
---|
| 73 | };
|
---|
| 74 |
|
---|
| 75 | /**
|
---|
| 76 | * Class for asynchronously opening a guest session.
|
---|
| 77 | */
|
---|
| 78 | class GuestSessionTaskInternalOpen : public GuestSessionTaskInternal
|
---|
| 79 | {
|
---|
| 80 | public:
|
---|
| 81 |
|
---|
| 82 | GuestSessionTaskInternalOpen(GuestSession *pSession)
|
---|
| 83 | : GuestSessionTaskInternal(pSession) { }
|
---|
| 84 | };
|
---|
| 85 |
|
---|
[45780] | 86 | /**
|
---|
| 87 | * Internal listener class to serve events in an
|
---|
| 88 | * active manner, e.g. without polling delays.
|
---|
| 89 | */
|
---|
| 90 | class GuestSessionListener
|
---|
| 91 | {
|
---|
| 92 | public:
|
---|
| 93 |
|
---|
| 94 | GuestSessionListener(void)
|
---|
| 95 | {
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | HRESULT init(GuestSession *pSession)
|
---|
| 99 | {
|
---|
| 100 | mSession = pSession;
|
---|
| 101 | return S_OK;
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | void uninit(void)
|
---|
| 105 | {
|
---|
| 106 | mSession.setNull();
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | STDMETHOD(HandleEvent)(VBoxEventType_T aType, IEvent *aEvent)
|
---|
| 110 | {
|
---|
| 111 | switch (aType)
|
---|
| 112 | {
|
---|
| 113 | case VBoxEventType_OnGuestSessionStateChanged:
|
---|
| 114 | {
|
---|
| 115 | Assert(!mSession.isNull());
|
---|
| 116 | int rc2 = mSession->signalWaitEvents(aType, aEvent);
|
---|
| 117 | #ifdef DEBUG_andy
|
---|
| 118 | LogFlowFunc(("Signalling events of type=%ld, session=%p resulted in rc=%Rrc\n",
|
---|
| 119 | aType, mSession, rc2));
|
---|
| 120 | #endif
|
---|
| 121 | break;
|
---|
| 122 | }
|
---|
| 123 |
|
---|
| 124 | default:
|
---|
| 125 | AssertMsgFailed(("Unhandled event %ld\n", aType));
|
---|
| 126 | break;
|
---|
| 127 | }
|
---|
| 128 |
|
---|
| 129 | return S_OK;
|
---|
| 130 | }
|
---|
| 131 |
|
---|
| 132 | private:
|
---|
| 133 |
|
---|
| 134 | ComObjPtr<GuestSession> mSession;
|
---|
| 135 | };
|
---|
| 136 | typedef ListenerImpl<GuestSessionListener, GuestSession*> GuestSessionListenerImpl;
|
---|
| 137 |
|
---|
[45782] | 138 | VBOX_LISTENER_DECLARE(GuestSessionListenerImpl)
|
---|
[45780] | 139 |
|
---|
[42084] | 140 | // constructor / destructor
|
---|
| 141 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 142 |
|
---|
| 143 | DEFINE_EMPTY_CTOR_DTOR(GuestSession)
|
---|
| 144 |
|
---|
| 145 | HRESULT GuestSession::FinalConstruct(void)
|
---|
| 146 | {
|
---|
| 147 | LogFlowThisFunc(("\n"));
|
---|
| 148 | return BaseFinalConstruct();
|
---|
| 149 | }
|
---|
| 150 |
|
---|
| 151 | void GuestSession::FinalRelease(void)
|
---|
| 152 | {
|
---|
| 153 | LogFlowThisFuncEnter();
|
---|
| 154 | uninit();
|
---|
| 155 | BaseFinalRelease();
|
---|
| 156 | LogFlowThisFuncLeave();
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | // public initializer/uninitializer for internal purposes only
|
---|
| 160 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 161 |
|
---|
[44863] | 162 | /**
|
---|
| 163 | * Initializes a guest session but does *not* open in on the guest side
|
---|
[44935] | 164 | * yet. This needs to be done via the openSession() / openSessionAsync calls.
|
---|
[44863] | 165 | *
|
---|
| 166 | * @return IPRT status code.
|
---|
[44935] | 167 | ** @todo Docs!
|
---|
[44863] | 168 | */
|
---|
[44935] | 169 | int GuestSession::init(Guest *pGuest, const GuestSessionStartupInfo &ssInfo,
|
---|
| 170 | const GuestCredentials &guestCreds)
|
---|
[42084] | 171 | {
|
---|
[44935] | 172 | LogFlowThisFunc(("pGuest=%p, ssInfo=%p, guestCreds=%p\n",
|
---|
| 173 | pGuest, &ssInfo, &guestCreds));
|
---|
[42194] | 174 |
|
---|
[42084] | 175 | /* Enclose the state transition NotReady->InInit->Ready. */
|
---|
| 176 | AutoInitSpan autoInitSpan(this);
|
---|
[42105] | 177 | AssertReturn(autoInitSpan.isOk(), VERR_OBJECT_DESTROYED);
|
---|
[42084] | 178 |
|
---|
[45426] | 179 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 180 | autoInitSpan.setSucceeded();
|
---|
| 181 | return VINF_SUCCESS;
|
---|
| 182 | #else
|
---|
| 183 | AssertPtrReturn(pGuest, VERR_INVALID_POINTER);
|
---|
| 184 |
|
---|
[45415] | 185 | mParent = pGuest;
|
---|
[42084] | 186 |
|
---|
[44935] | 187 | /* Copy over startup info. */
|
---|
| 188 | /** @todo Use an overloaded copy operator. Later. */
|
---|
| 189 | mData.mSession.mID = ssInfo.mID;
|
---|
| 190 | mData.mSession.mIsInternal = ssInfo.mIsInternal;
|
---|
| 191 | mData.mSession.mName = ssInfo.mName;
|
---|
| 192 | mData.mSession.mOpenFlags = ssInfo.mOpenFlags;
|
---|
| 193 | mData.mSession.mOpenTimeoutMS = ssInfo.mOpenTimeoutMS;
|
---|
| 194 |
|
---|
| 195 | /** @todo Use an overloaded copy operator. Later. */
|
---|
| 196 | mData.mCredentials.mUser = guestCreds.mUser;
|
---|
| 197 | mData.mCredentials.mPassword = guestCreds.mPassword;
|
---|
| 198 | mData.mCredentials.mDomain = guestCreds.mDomain;
|
---|
| 199 |
|
---|
[45426] | 200 | mData.mRC = VINF_SUCCESS;
|
---|
[44935] | 201 | mData.mStatus = GuestSessionStatus_Undefined;
|
---|
[42897] | 202 | mData.mNumObjects = 0;
|
---|
[42084] | 203 |
|
---|
[45780] | 204 | HRESULT hr;
|
---|
| 205 |
|
---|
[44935] | 206 | int rc = queryInfo();
|
---|
| 207 | if (RT_SUCCESS(rc))
|
---|
| 208 | {
|
---|
[47469] | 209 | hr = unconst(mEventSource).createObject();
|
---|
[45415] | 210 | if (FAILED(hr))
|
---|
[47469] | 211 | rc = VERR_NO_MEMORY;
|
---|
| 212 | else
|
---|
| 213 | {
|
---|
| 214 | hr = mEventSource->init(static_cast<IGuestSession*>(this));
|
---|
| 215 | if (FAILED(hr))
|
---|
| 216 | rc = VERR_COM_UNEXPECTED;
|
---|
| 217 | }
|
---|
[45415] | 218 | }
|
---|
| 219 |
|
---|
| 220 | if (RT_SUCCESS(rc))
|
---|
| 221 | {
|
---|
[45780] | 222 | try
|
---|
| 223 | {
|
---|
| 224 | GuestSessionListener *pListener = new GuestSessionListener();
|
---|
| 225 | ComObjPtr<GuestSessionListenerImpl> thisListener;
|
---|
| 226 | hr = thisListener.createObject();
|
---|
| 227 | if (SUCCEEDED(hr))
|
---|
| 228 | hr = thisListener->init(pListener, this);
|
---|
| 229 |
|
---|
| 230 | if (SUCCEEDED(hr))
|
---|
| 231 | {
|
---|
| 232 | com::SafeArray <VBoxEventType_T> eventTypes;
|
---|
| 233 | eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
|
---|
[47469] | 234 | hr = mEventSource->RegisterListener(thisListener,
|
---|
[45780] | 235 | ComSafeArrayAsInParam(eventTypes),
|
---|
| 236 | TRUE /* Active listener */);
|
---|
| 237 | if (SUCCEEDED(hr))
|
---|
| 238 | {
|
---|
[47469] | 239 | mLocalListener = thisListener;
|
---|
| 240 |
|
---|
[45780] | 241 | rc = RTCritSectInit(&mWaitEventCritSect);
|
---|
| 242 | AssertRC(rc);
|
---|
| 243 | }
|
---|
| 244 | else
|
---|
| 245 | rc = VERR_COM_UNEXPECTED;
|
---|
| 246 | }
|
---|
| 247 | else
|
---|
| 248 | rc = VERR_COM_UNEXPECTED;
|
---|
| 249 | }
|
---|
| 250 | catch(std::bad_alloc &)
|
---|
| 251 | {
|
---|
| 252 | rc = VERR_NO_MEMORY;
|
---|
| 253 | }
|
---|
| 254 | }
|
---|
| 255 |
|
---|
| 256 | if (RT_SUCCESS(rc))
|
---|
| 257 | {
|
---|
[44935] | 258 | /* Confirm a successful initialization when it's the case. */
|
---|
| 259 | autoInitSpan.setSucceeded();
|
---|
| 260 | }
|
---|
| 261 | else
|
---|
| 262 | autoInitSpan.setFailed();
|
---|
[42084] | 263 |
|
---|
[47469] | 264 | LogFlowThisFunc(("mName=%s, mID=%RU32, mIsInternal=%RTbool, rc=%Rrc\n",
|
---|
| 265 | mData.mSession.mName.c_str(), mData.mSession.mID, mData.mSession.mIsInternal, rc));
|
---|
[44935] | 266 | return rc;
|
---|
[45426] | 267 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
[42084] | 268 | }
|
---|
| 269 |
|
---|
| 270 | /**
|
---|
| 271 | * Uninitializes the instance.
|
---|
| 272 | * Called from FinalRelease().
|
---|
| 273 | */
|
---|
| 274 | void GuestSession::uninit(void)
|
---|
| 275 | {
|
---|
[42194] | 276 | LogFlowThisFuncEnter();
|
---|
[42084] | 277 |
|
---|
| 278 | /* Enclose the state transition Ready->InUninit->NotReady. */
|
---|
| 279 | AutoUninitSpan autoUninitSpan(this);
|
---|
| 280 | if (autoUninitSpan.uninitDone())
|
---|
| 281 | return;
|
---|
[42090] | 282 |
|
---|
[42897] | 283 | int rc = VINF_SUCCESS;
|
---|
| 284 |
|
---|
[45415] | 285 | #ifdef VBOX_WITH_GUEST_CONTROL
|
---|
[42897] | 286 | LogFlowThisFunc(("Closing directories (%RU64 total)\n",
|
---|
| 287 | mData.mDirectories.size()));
|
---|
[42105] | 288 | for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
|
---|
| 289 | itDirs != mData.mDirectories.end(); ++itDirs)
|
---|
[42090] | 290 | {
|
---|
[47469] | 291 | (*itDirs)->Release();
|
---|
[42090] | 292 | }
|
---|
[42105] | 293 | mData.mDirectories.clear();
|
---|
[42090] | 294 |
|
---|
[42897] | 295 | LogFlowThisFunc(("Closing files (%RU64 total)\n",
|
---|
| 296 | mData.mFiles.size()));
|
---|
[42105] | 297 | for (SessionFiles::iterator itFiles = mData.mFiles.begin();
|
---|
| 298 | itFiles != mData.mFiles.end(); ++itFiles)
|
---|
[42090] | 299 | {
|
---|
[47469] | 300 | itFiles->second->Release();
|
---|
[42090] | 301 | }
|
---|
[42105] | 302 | mData.mFiles.clear();
|
---|
[42090] | 303 |
|
---|
[42897] | 304 | LogFlowThisFunc(("Closing processes (%RU64 total)\n",
|
---|
| 305 | mData.mProcesses.size()));
|
---|
[42105] | 306 | for (SessionProcesses::iterator itProcs = mData.mProcesses.begin();
|
---|
[42090] | 307 | itProcs != mData.mProcesses.end(); ++itProcs)
|
---|
| 308 | {
|
---|
[47469] | 309 | itProcs->second->Release();
|
---|
[42090] | 310 | }
|
---|
[42105] | 311 | mData.mProcesses.clear();
|
---|
| 312 |
|
---|
[42897] | 313 | LogFlowThisFunc(("mNumObjects=%RU32\n", mData.mNumObjects));
|
---|
[45415] | 314 |
|
---|
[47469] | 315 | baseUninit();
|
---|
| 316 |
|
---|
| 317 | mEventSource->UnregisterListener(mLocalListener);
|
---|
[45415] | 318 | unconst(mEventSource).setNull();
|
---|
| 319 |
|
---|
| 320 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
[42897] | 321 | LogFlowFuncLeaveRC(rc);
|
---|
[42084] | 322 | }
|
---|
| 323 |
|
---|
| 324 | // implementation of public getters/setters for attributes
|
---|
| 325 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 326 |
|
---|
[42094] | 327 | STDMETHODIMP GuestSession::COMGETTER(User)(BSTR *aUser)
|
---|
[42084] | 328 | {
|
---|
| 329 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 330 | ReturnComNotImplemented();
|
---|
| 331 | #else
|
---|
[42194] | 332 | LogFlowThisFuncEnter();
|
---|
| 333 |
|
---|
[42084] | 334 | CheckComArgOutPointerValid(aUser);
|
---|
| 335 |
|
---|
| 336 | AutoCaller autoCaller(this);
|
---|
| 337 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 338 |
|
---|
| 339 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 340 |
|
---|
[42160] | 341 | mData.mCredentials.mUser.cloneTo(aUser);
|
---|
[42084] | 342 |
|
---|
[42194] | 343 | LogFlowFuncLeaveRC(S_OK);
|
---|
[42084] | 344 | return S_OK;
|
---|
| 345 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 346 | }
|
---|
| 347 |
|
---|
[42094] | 348 | STDMETHODIMP GuestSession::COMGETTER(Domain)(BSTR *aDomain)
|
---|
[42084] | 349 | {
|
---|
| 350 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 351 | ReturnComNotImplemented();
|
---|
| 352 | #else
|
---|
[42194] | 353 | LogFlowThisFuncEnter();
|
---|
| 354 |
|
---|
[42084] | 355 | CheckComArgOutPointerValid(aDomain);
|
---|
| 356 |
|
---|
| 357 | AutoCaller autoCaller(this);
|
---|
| 358 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 359 |
|
---|
| 360 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 361 |
|
---|
[42160] | 362 | mData.mCredentials.mDomain.cloneTo(aDomain);
|
---|
[42084] | 363 |
|
---|
[42194] | 364 | LogFlowFuncLeaveRC(S_OK);
|
---|
[42084] | 365 | return S_OK;
|
---|
| 366 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 367 | }
|
---|
| 368 |
|
---|
[42094] | 369 | STDMETHODIMP GuestSession::COMGETTER(Name)(BSTR *aName)
|
---|
[42084] | 370 | {
|
---|
| 371 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 372 | ReturnComNotImplemented();
|
---|
| 373 | #else
|
---|
[42194] | 374 | LogFlowThisFuncEnter();
|
---|
| 375 |
|
---|
[42084] | 376 | CheckComArgOutPointerValid(aName);
|
---|
| 377 |
|
---|
| 378 | AutoCaller autoCaller(this);
|
---|
| 379 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 380 |
|
---|
| 381 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 382 |
|
---|
[44935] | 383 | mData.mSession.mName.cloneTo(aName);
|
---|
[42084] | 384 |
|
---|
[42194] | 385 | LogFlowFuncLeaveRC(S_OK);
|
---|
[42084] | 386 | return S_OK;
|
---|
| 387 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 388 | }
|
---|
| 389 |
|
---|
| 390 | STDMETHODIMP GuestSession::COMGETTER(Id)(ULONG *aId)
|
---|
| 391 | {
|
---|
| 392 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 393 | ReturnComNotImplemented();
|
---|
| 394 | #else
|
---|
[42194] | 395 | LogFlowThisFuncEnter();
|
---|
| 396 |
|
---|
[42084] | 397 | CheckComArgOutPointerValid(aId);
|
---|
| 398 |
|
---|
| 399 | AutoCaller autoCaller(this);
|
---|
| 400 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 401 |
|
---|
| 402 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 403 |
|
---|
[44935] | 404 | *aId = mData.mSession.mID;
|
---|
[42084] | 405 |
|
---|
[42194] | 406 | LogFlowFuncLeaveRC(S_OK);
|
---|
[42084] | 407 | return S_OK;
|
---|
| 408 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 409 | }
|
---|
| 410 |
|
---|
[44935] | 411 | STDMETHODIMP GuestSession::COMGETTER(Status)(GuestSessionStatus_T *aStatus)
|
---|
| 412 | {
|
---|
| 413 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 414 | ReturnComNotImplemented();
|
---|
| 415 | #else
|
---|
| 416 | LogFlowThisFuncEnter();
|
---|
| 417 |
|
---|
| 418 | CheckComArgOutPointerValid(aStatus);
|
---|
| 419 |
|
---|
| 420 | AutoCaller autoCaller(this);
|
---|
| 421 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 422 |
|
---|
| 423 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 424 |
|
---|
| 425 | *aStatus = mData.mStatus;
|
---|
| 426 |
|
---|
| 427 | LogFlowFuncLeaveRC(S_OK);
|
---|
| 428 | return S_OK;
|
---|
| 429 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 430 | }
|
---|
| 431 |
|
---|
[42084] | 432 | STDMETHODIMP GuestSession::COMGETTER(Timeout)(ULONG *aTimeout)
|
---|
| 433 | {
|
---|
| 434 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 435 | ReturnComNotImplemented();
|
---|
| 436 | #else
|
---|
[42194] | 437 | LogFlowThisFuncEnter();
|
---|
| 438 |
|
---|
[42084] | 439 | CheckComArgOutPointerValid(aTimeout);
|
---|
| 440 |
|
---|
| 441 | AutoCaller autoCaller(this);
|
---|
| 442 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 443 |
|
---|
| 444 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 445 |
|
---|
| 446 | *aTimeout = mData.mTimeout;
|
---|
| 447 |
|
---|
[42194] | 448 | LogFlowFuncLeaveRC(S_OK);
|
---|
[42084] | 449 | return S_OK;
|
---|
| 450 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 451 | }
|
---|
| 452 |
|
---|
[42411] | 453 | STDMETHODIMP GuestSession::COMSETTER(Timeout)(ULONG aTimeout)
|
---|
| 454 | {
|
---|
| 455 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 456 | ReturnComNotImplemented();
|
---|
| 457 | #else
|
---|
| 458 | LogFlowThisFuncEnter();
|
---|
| 459 |
|
---|
| 460 | AutoCaller autoCaller(this);
|
---|
| 461 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 462 |
|
---|
| 463 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 464 |
|
---|
| 465 | mData.mTimeout = aTimeout;
|
---|
| 466 |
|
---|
| 467 | LogFlowFuncLeaveRC(S_OK);
|
---|
| 468 | return S_OK;
|
---|
| 469 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 470 | }
|
---|
| 471 |
|
---|
[47469] | 472 | STDMETHODIMP GuestSession::COMGETTER(ProtocolVersion)(ULONG *aVersion)
|
---|
| 473 | {
|
---|
| 474 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 475 | ReturnComNotImplemented();
|
---|
| 476 | #else
|
---|
| 477 | LogFlowThisFuncEnter();
|
---|
| 478 |
|
---|
| 479 | CheckComArgOutPointerValid(aVersion);
|
---|
| 480 |
|
---|
| 481 | AutoCaller autoCaller(this);
|
---|
| 482 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 483 |
|
---|
| 484 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 485 |
|
---|
| 486 | *aVersion = mData.mProtocolVersion;
|
---|
| 487 |
|
---|
| 488 | LogFlowFuncLeaveRC(S_OK);
|
---|
| 489 | return S_OK;
|
---|
| 490 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 491 | }
|
---|
| 492 |
|
---|
[42094] | 493 | STDMETHODIMP GuestSession::COMGETTER(Environment)(ComSafeArrayOut(BSTR, aEnvironment))
|
---|
[42084] | 494 | {
|
---|
| 495 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 496 | ReturnComNotImplemented();
|
---|
| 497 | #else
|
---|
[42194] | 498 | LogFlowThisFuncEnter();
|
---|
| 499 |
|
---|
[42084] | 500 | CheckComArgOutSafeArrayPointerValid(aEnvironment);
|
---|
| 501 |
|
---|
| 502 | AutoCaller autoCaller(this);
|
---|
| 503 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 504 |
|
---|
| 505 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 506 |
|
---|
[42194] | 507 | size_t cEnvVars = mData.mEnvironment.Size();
|
---|
[44935] | 508 | LogFlowThisFunc(("[%s]: cEnvVars=%RU32\n",
|
---|
| 509 | mData.mSession.mName.c_str(), cEnvVars));
|
---|
[42194] | 510 | com::SafeArray<BSTR> environment(cEnvVars);
|
---|
[42084] | 511 |
|
---|
[42194] | 512 | for (size_t i = 0; i < cEnvVars; i++)
|
---|
| 513 | {
|
---|
| 514 | Bstr strEnv(mData.mEnvironment.Get(i));
|
---|
| 515 | strEnv.cloneTo(&environment[i]);
|
---|
| 516 | }
|
---|
| 517 | environment.detachTo(ComSafeArrayOutArg(aEnvironment));
|
---|
| 518 |
|
---|
| 519 | LogFlowFuncLeaveRC(S_OK);
|
---|
[42084] | 520 | return S_OK;
|
---|
| 521 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 522 | }
|
---|
| 523 |
|
---|
[42551] | 524 | STDMETHODIMP GuestSession::COMSETTER(Environment)(ComSafeArrayIn(IN_BSTR, aValues))
|
---|
| 525 | {
|
---|
| 526 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 527 | ReturnComNotImplemented();
|
---|
| 528 | #else
|
---|
| 529 | LogFlowThisFuncEnter();
|
---|
| 530 |
|
---|
| 531 | AutoCaller autoCaller(this);
|
---|
| 532 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 533 |
|
---|
| 534 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 535 |
|
---|
| 536 | com::SafeArray<IN_BSTR> environment(ComSafeArrayInArg(aValues));
|
---|
| 537 |
|
---|
| 538 | int rc = VINF_SUCCESS;
|
---|
| 539 | for (size_t i = 0; i < environment.size() && RT_SUCCESS(rc); i++)
|
---|
| 540 | {
|
---|
| 541 | Utf8Str strEnv(environment[i]);
|
---|
| 542 | if (!strEnv.isEmpty()) /* Silently skip empty entries. */
|
---|
| 543 | rc = mData.mEnvironment.Set(strEnv);
|
---|
| 544 | }
|
---|
| 545 |
|
---|
| 546 | HRESULT hr = RT_SUCCESS(rc) ? S_OK : VBOX_E_IPRT_ERROR;
|
---|
| 547 | LogFlowFuncLeaveRC(hr);
|
---|
| 548 | return hr;
|
---|
| 549 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 550 | }
|
---|
| 551 |
|
---|
[42084] | 552 | STDMETHODIMP GuestSession::COMGETTER(Processes)(ComSafeArrayOut(IGuestProcess *, aProcesses))
|
---|
| 553 | {
|
---|
| 554 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 555 | ReturnComNotImplemented();
|
---|
| 556 | #else
|
---|
[42194] | 557 | LogFlowThisFuncEnter();
|
---|
| 558 |
|
---|
[42084] | 559 | CheckComArgOutSafeArrayPointerValid(aProcesses);
|
---|
| 560 |
|
---|
| 561 | AutoCaller autoCaller(this);
|
---|
| 562 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 563 |
|
---|
| 564 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 565 |
|
---|
| 566 | SafeIfaceArray<IGuestProcess> collection(mData.mProcesses);
|
---|
| 567 | collection.detachTo(ComSafeArrayOutArg(aProcesses));
|
---|
| 568 |
|
---|
[47469] | 569 | LogFlowFunc(("mProcesses=%zu\n", collection.size()));
|
---|
[42084] | 570 | return S_OK;
|
---|
| 571 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 572 | }
|
---|
| 573 |
|
---|
| 574 | STDMETHODIMP GuestSession::COMGETTER(Directories)(ComSafeArrayOut(IGuestDirectory *, aDirectories))
|
---|
| 575 | {
|
---|
| 576 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 577 | ReturnComNotImplemented();
|
---|
| 578 | #else
|
---|
[42194] | 579 | LogFlowThisFuncEnter();
|
---|
| 580 |
|
---|
[42084] | 581 | CheckComArgOutSafeArrayPointerValid(aDirectories);
|
---|
| 582 |
|
---|
| 583 | AutoCaller autoCaller(this);
|
---|
| 584 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 585 |
|
---|
| 586 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 587 |
|
---|
| 588 | SafeIfaceArray<IGuestDirectory> collection(mData.mDirectories);
|
---|
| 589 | collection.detachTo(ComSafeArrayOutArg(aDirectories));
|
---|
| 590 |
|
---|
[47469] | 591 | LogFlowFunc(("mDirectories=%zu\n", collection.size()));
|
---|
[42084] | 592 | return S_OK;
|
---|
| 593 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 594 | }
|
---|
| 595 |
|
---|
| 596 | STDMETHODIMP GuestSession::COMGETTER(Files)(ComSafeArrayOut(IGuestFile *, aFiles))
|
---|
| 597 | {
|
---|
| 598 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 599 | ReturnComNotImplemented();
|
---|
| 600 | #else
|
---|
[42194] | 601 | LogFlowThisFuncEnter();
|
---|
| 602 |
|
---|
[42084] | 603 | CheckComArgOutSafeArrayPointerValid(aFiles);
|
---|
| 604 |
|
---|
| 605 | AutoCaller autoCaller(this);
|
---|
| 606 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 607 |
|
---|
| 608 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 609 |
|
---|
| 610 | SafeIfaceArray<IGuestFile> collection(mData.mFiles);
|
---|
| 611 | collection.detachTo(ComSafeArrayOutArg(aFiles));
|
---|
| 612 |
|
---|
[47469] | 613 | LogFlowFunc(("mFiles=%zu\n", collection.size()));
|
---|
[42084] | 614 | return S_OK;
|
---|
| 615 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 616 | }
|
---|
| 617 |
|
---|
[45415] | 618 | STDMETHODIMP GuestSession::COMGETTER(EventSource)(IEventSource ** aEventSource)
|
---|
| 619 | {
|
---|
[45426] | 620 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 621 | ReturnComNotImplemented();
|
---|
| 622 | #else
|
---|
| 623 | LogFlowThisFuncEnter();
|
---|
| 624 |
|
---|
[45415] | 625 | CheckComArgOutPointerValid(aEventSource);
|
---|
| 626 |
|
---|
| 627 | AutoCaller autoCaller(this);
|
---|
| 628 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 629 |
|
---|
| 630 | // no need to lock - lifetime constant
|
---|
| 631 | mEventSource.queryInterfaceTo(aEventSource);
|
---|
| 632 |
|
---|
[45426] | 633 | LogFlowFuncLeaveRC(S_OK);
|
---|
[45415] | 634 | return S_OK;
|
---|
[45426] | 635 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
[45415] | 636 | }
|
---|
| 637 |
|
---|
[42105] | 638 | // private methods
|
---|
[44863] | 639 | ///////////////////////////////////////////////////////////////////////////////
|
---|
[42105] | 640 |
|
---|
[44863] | 641 | int GuestSession::closeSession(uint32_t uFlags, uint32_t uTimeoutMS, int *pGuestRc)
|
---|
| 642 | {
|
---|
| 643 | LogFlowThisFunc(("uFlags=%x, uTimeoutMS=%RU32\n", uFlags, uTimeoutMS));
|
---|
| 644 |
|
---|
[45415] | 645 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 646 |
|
---|
[47469] | 647 | /* Guest Additions < 4.3 don't support closing dedicated
|
---|
| 648 | guest sessions, skip. */
|
---|
[44863] | 649 | if (mData.mProtocolVersion < 2)
|
---|
| 650 | {
|
---|
[44935] | 651 | LogFlowThisFunc(("Installed Guest Additions don't support closing dedicated sessions, skipping\n"));
|
---|
[44863] | 652 | return VINF_SUCCESS;
|
---|
| 653 | }
|
---|
| 654 |
|
---|
[44935] | 655 | /** @todo uFlags validation. */
|
---|
| 656 |
|
---|
[45415] | 657 | if (mData.mStatus != GuestSessionStatus_Started)
|
---|
| 658 | return VINF_SUCCESS;
|
---|
[44863] | 659 |
|
---|
[45780] | 660 | int vrc;
|
---|
| 661 |
|
---|
| 662 | GuestWaitEvent *pEvent = NULL;
|
---|
| 663 | std::list < VBoxEventType_T > eventTypes;
|
---|
| 664 | try
|
---|
[44863] | 665 | {
|
---|
[45780] | 666 | eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
|
---|
[44863] | 667 |
|
---|
[47469] | 668 | vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
|
---|
| 669 | eventTypes, &pEvent);
|
---|
[45780] | 670 | }
|
---|
| 671 | catch (std::bad_alloc)
|
---|
| 672 | {
|
---|
| 673 | vrc = VERR_NO_MEMORY;
|
---|
| 674 | }
|
---|
[44863] | 675 |
|
---|
[45780] | 676 | if (RT_FAILURE(vrc))
|
---|
| 677 | return vrc;
|
---|
[44863] | 678 |
|
---|
[45780] | 679 | LogFlowThisFunc(("Sending closing request to guest session ID=%RU32, uFlags=%x\n",
|
---|
| 680 | mData.mSession.mID, uFlags));
|
---|
[44935] | 681 |
|
---|
[45780] | 682 | VBOXHGCMSVCPARM paParms[4];
|
---|
| 683 | int i = 0;
|
---|
| 684 | paParms[i++].setUInt32(pEvent->ContextID());
|
---|
| 685 | paParms[i++].setUInt32(uFlags);
|
---|
| 686 |
|
---|
| 687 | vrc = sendCommand(HOST_SESSION_CLOSE, i, paParms);
|
---|
| 688 | if (RT_SUCCESS(vrc))
|
---|
| 689 | {
|
---|
| 690 | alock.release(); /* Drop the write lock before waiting. */
|
---|
| 691 |
|
---|
| 692 | vrc = waitForStatusChange(pEvent, GuestSessionWaitForFlag_Terminate, uTimeoutMS,
|
---|
| 693 | NULL /* Session status */, pGuestRc);
|
---|
[44863] | 694 | }
|
---|
| 695 |
|
---|
[47469] | 696 | unregisterWaitEvent(pEvent);
|
---|
[45780] | 697 |
|
---|
[44863] | 698 | LogFlowFuncLeaveRC(vrc);
|
---|
| 699 | return vrc;
|
---|
| 700 | }
|
---|
| 701 |
|
---|
[42897] | 702 | int GuestSession::directoryRemoveFromList(GuestDirectory *pDirectory)
|
---|
[42105] | 703 | {
|
---|
| 704 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 705 |
|
---|
| 706 | for (SessionDirectories::iterator itDirs = mData.mDirectories.begin();
|
---|
| 707 | itDirs != mData.mDirectories.end(); ++itDirs)
|
---|
| 708 | {
|
---|
| 709 | if (pDirectory == (*itDirs))
|
---|
| 710 | {
|
---|
[42897] | 711 | Bstr strName;
|
---|
| 712 | HRESULT hr = (*itDirs)->COMGETTER(DirectoryName)(strName.asOutParam());
|
---|
| 713 | ComAssertComRC(hr);
|
---|
| 714 |
|
---|
| 715 | Assert(mData.mDirectories.size());
|
---|
| 716 | LogFlowFunc(("Removing directory \"%s\" (Session: %RU32) (now total %ld directories)\n",
|
---|
[44935] | 717 | Utf8Str(strName).c_str(), mData.mSession.mID, mData.mDirectories.size() - 1));
|
---|
[42897] | 718 |
|
---|
[42160] | 719 | mData.mDirectories.erase(itDirs);
|
---|
[42105] | 720 | return VINF_SUCCESS;
|
---|
| 721 | }
|
---|
| 722 | }
|
---|
| 723 |
|
---|
| 724 | return VERR_NOT_FOUND;
|
---|
| 725 | }
|
---|
| 726 |
|
---|
[43162] | 727 | int GuestSession::directoryCreateInternal(const Utf8Str &strPath, uint32_t uMode, uint32_t uFlags, int *pGuestRc)
|
---|
[42525] | 728 | {
|
---|
[45078] | 729 | /* pGuestRc is optional. */
|
---|
| 730 |
|
---|
[42525] | 731 | LogFlowThisFunc(("strPath=%s, uMode=%x, uFlags=%x\n",
|
---|
| 732 | strPath.c_str(), uMode, uFlags));
|
---|
| 733 |
|
---|
[42611] | 734 | GuestProcessStartupInfo procInfo;
|
---|
[43162] | 735 | procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_MKDIR);
|
---|
| 736 | procInfo.mFlags = ProcessCreateFlag_Hidden;
|
---|
[42525] | 737 |
|
---|
[43162] | 738 | int vrc = VINF_SUCCESS;
|
---|
[42525] | 739 |
|
---|
| 740 | /* Construct arguments. */
|
---|
| 741 | if (uFlags & DirectoryCreateFlag_Parents)
|
---|
| 742 | procInfo.mArguments.push_back(Utf8Str("--parents")); /* We also want to create the parent directories. */
|
---|
| 743 | if (uMode)
|
---|
| 744 | {
|
---|
| 745 | procInfo.mArguments.push_back(Utf8Str("--mode")); /* Set the creation mode. */
|
---|
| 746 |
|
---|
| 747 | char szMode[16];
|
---|
| 748 | if (RTStrPrintf(szMode, sizeof(szMode), "%o", uMode))
|
---|
| 749 | {
|
---|
| 750 | procInfo.mArguments.push_back(Utf8Str(szMode));
|
---|
| 751 | }
|
---|
| 752 | else
|
---|
[43162] | 753 | vrc = VERR_BUFFER_OVERFLOW;
|
---|
[42525] | 754 | }
|
---|
| 755 | procInfo.mArguments.push_back(strPath); /* The directory we want to create. */
|
---|
| 756 |
|
---|
[43162] | 757 | if (RT_SUCCESS(vrc))
|
---|
[42525] | 758 | {
|
---|
[44863] | 759 | int guestRc;
|
---|
[43162] | 760 | GuestProcessTool procTool;
|
---|
| 761 | vrc = procTool.Init(this, procInfo, false /* Async */, &guestRc);
|
---|
| 762 | if (RT_SUCCESS(vrc))
|
---|
[42525] | 763 | {
|
---|
[43162] | 764 | if (RT_SUCCESS(guestRc))
|
---|
| 765 | vrc = procTool.Wait(GUESTPROCESSTOOL_FLAG_NONE, &guestRc);
|
---|
[42525] | 766 | }
|
---|
[43162] | 767 |
|
---|
| 768 | if (RT_SUCCESS(vrc))
|
---|
| 769 | {
|
---|
| 770 | if (RT_SUCCESS(guestRc))
|
---|
| 771 | guestRc = procTool.TerminatedOk(NULL /* Exit code */);
|
---|
| 772 | }
|
---|
| 773 |
|
---|
[45078] | 774 | if ( vrc == VERR_GSTCTL_GUEST_ERROR
|
---|
| 775 | && pGuestRc)
|
---|
| 776 | {
|
---|
[43162] | 777 | *pGuestRc = guestRc;
|
---|
[45078] | 778 | }
|
---|
[42525] | 779 | }
|
---|
| 780 |
|
---|
[43162] | 781 | LogFlowFuncLeaveRC(vrc);
|
---|
[44863] | 782 | return vrc;
|
---|
[42808] | 783 | }
|
---|
[42525] | 784 |
|
---|
[43162] | 785 | int GuestSession::directoryQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc)
|
---|
[42808] | 786 | {
|
---|
| 787 | LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
|
---|
[42611] | 788 |
|
---|
[43162] | 789 | int vrc = fsQueryInfoInternal(strPath, objData, pGuestRc);
|
---|
| 790 | if (RT_SUCCESS(vrc))
|
---|
[42808] | 791 | {
|
---|
[43162] | 792 | vrc = objData.mType == FsObjType_Directory
|
---|
| 793 | ? VINF_SUCCESS : VERR_NOT_A_DIRECTORY;
|
---|
[42808] | 794 | }
|
---|
[42525] | 795 |
|
---|
[43162] | 796 | LogFlowFuncLeaveRC(vrc);
|
---|
| 797 | return vrc;
|
---|
[42525] | 798 | }
|
---|
| 799 |
|
---|
[43162] | 800 | int GuestSession::objectCreateTempInternal(const Utf8Str &strTemplate, const Utf8Str &strPath,
|
---|
| 801 | bool fDirectory, const Utf8Str &strName, int *pGuestRc)
|
---|
[42783] | 802 | {
|
---|
| 803 | GuestProcessStartupInfo procInfo;
|
---|
| 804 | procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_MKTEMP);
|
---|
[43162] | 805 | procInfo.mFlags = ProcessCreateFlag_WaitForStdOut;
|
---|
[42783] | 806 | procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
|
---|
| 807 | if (fDirectory)
|
---|
| 808 | procInfo.mArguments.push_back(Utf8Str("-d"));
|
---|
[43162] | 809 | if (strPath.length()) /* Otherwise use /tmp or equivalent. */
|
---|
[42783] | 810 | {
|
---|
| 811 | procInfo.mArguments.push_back(Utf8Str("-t"));
|
---|
| 812 | procInfo.mArguments.push_back(strPath);
|
---|
| 813 | }
|
---|
| 814 | procInfo.mArguments.push_back(strTemplate);
|
---|
| 815 |
|
---|
[43162] | 816 | GuestProcessTool procTool; int guestRc;
|
---|
| 817 | int vrc = procTool.Init(this, procInfo, false /* Async */, &guestRc);
|
---|
| 818 | if (RT_SUCCESS(vrc))
|
---|
[42783] | 819 | {
|
---|
[43162] | 820 | if (RT_SUCCESS(guestRc))
|
---|
| 821 | vrc = procTool.Wait(GUESTPROCESSTOOL_FLAG_NONE, &guestRc);
|
---|
| 822 | }
|
---|
[42783] | 823 |
|
---|
[43162] | 824 | if (RT_SUCCESS(vrc))
|
---|
| 825 | {
|
---|
| 826 | if (RT_SUCCESS(guestRc))
|
---|
| 827 | guestRc = procTool.TerminatedOk(NULL /* Exit code */);
|
---|
| 828 | }
|
---|
[42783] | 829 |
|
---|
[45078] | 830 | if ( vrc == VERR_GSTCTL_GUEST_ERROR
|
---|
[44863] | 831 | && pGuestRc)
|
---|
[45078] | 832 | {
|
---|
[43162] | 833 | *pGuestRc = guestRc;
|
---|
[45078] | 834 | }
|
---|
[42783] | 835 |
|
---|
[44863] | 836 | LogFlowFuncLeaveRC(vrc);
|
---|
| 837 | return vrc;
|
---|
[42783] | 838 | }
|
---|
| 839 |
|
---|
[42673] | 840 | int GuestSession::directoryOpenInternal(const Utf8Str &strPath, const Utf8Str &strFilter,
|
---|
| 841 | uint32_t uFlags, ComObjPtr<GuestDirectory> &pDirectory)
|
---|
| 842 | {
|
---|
| 843 | LogFlowThisFunc(("strPath=%s, strPath=%s, uFlags=%x\n",
|
---|
| 844 | strPath.c_str(), strFilter.c_str(), uFlags));
|
---|
| 845 |
|
---|
[42693] | 846 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[42673] | 847 |
|
---|
[42693] | 848 | /* Create the directory object. */
|
---|
| 849 | HRESULT hr = pDirectory.createObject();
|
---|
| 850 | if (FAILED(hr))
|
---|
| 851 | return VERR_COM_UNEXPECTED;
|
---|
[42673] | 852 |
|
---|
[43162] | 853 | int vrc = pDirectory->init(this /* Parent */,
|
---|
| 854 | strPath, strFilter, uFlags);
|
---|
| 855 | if (RT_FAILURE(vrc))
|
---|
| 856 | return vrc;
|
---|
[42673] | 857 |
|
---|
[42693] | 858 | /* Add the created directory to our vector. */
|
---|
| 859 | mData.mDirectories.push_back(pDirectory);
|
---|
[42673] | 860 |
|
---|
[42693] | 861 | LogFlowFunc(("Added new directory \"%s\" (Session: %RU32)\n",
|
---|
[44935] | 862 | strPath.c_str(), mData.mSession.mID));
|
---|
[42673] | 863 |
|
---|
[43162] | 864 | LogFlowFuncLeaveRC(vrc);
|
---|
| 865 | return vrc;
|
---|
[42673] | 866 | }
|
---|
| 867 |
|
---|
[44863] | 868 | int GuestSession::dispatchToFile(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
|
---|
[42214] | 869 | {
|
---|
[44863] | 870 | LogFlowFunc(("pCtxCb=%p, pSvcCb=%p\n", pCtxCb, pSvcCb));
|
---|
[42272] | 871 |
|
---|
[44863] | 872 | AssertPtrReturn(pCtxCb, VERR_INVALID_POINTER);
|
---|
| 873 | AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
|
---|
| 874 |
|
---|
[42214] | 875 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 876 |
|
---|
[44863] | 877 | uint32_t uFileID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCtxCb->uContextID);
|
---|
[42436] | 878 | #ifdef DEBUG
|
---|
[44863] | 879 | LogFlowFunc(("uFileID=%RU32 (%RU32 total)\n",
|
---|
| 880 | uFileID, mData.mFiles.size()));
|
---|
| 881 | #endif
|
---|
| 882 | int rc;
|
---|
| 883 | SessionFiles::const_iterator itFile
|
---|
| 884 | = mData.mFiles.find(uFileID);
|
---|
| 885 | if (itFile != mData.mFiles.end())
|
---|
| 886 | {
|
---|
| 887 | ComObjPtr<GuestFile> pFile(itFile->second);
|
---|
| 888 | Assert(!pFile.isNull());
|
---|
| 889 |
|
---|
| 890 | alock.release();
|
---|
| 891 |
|
---|
| 892 | rc = pFile->callbackDispatcher(pCtxCb, pSvcCb);
|
---|
| 893 | }
|
---|
| 894 | else
|
---|
| 895 | rc = VERR_NOT_FOUND;
|
---|
| 896 |
|
---|
| 897 | LogFlowFuncLeaveRC(rc);
|
---|
| 898 | return rc;
|
---|
| 899 | }
|
---|
| 900 |
|
---|
| 901 | int GuestSession::dispatchToProcess(PVBOXGUESTCTRLHOSTCBCTX pCtxCb, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
|
---|
| 902 | {
|
---|
| 903 | LogFlowFunc(("pCtxCb=%p, pSvcCb=%p\n", pCtxCb, pSvcCb));
|
---|
| 904 |
|
---|
| 905 | AssertPtrReturn(pCtxCb, VERR_INVALID_POINTER);
|
---|
| 906 | AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
|
---|
| 907 |
|
---|
| 908 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 909 |
|
---|
| 910 | uint32_t uProcessID = VBOX_GUESTCTRL_CONTEXTID_GET_OBJECT(pCtxCb->uContextID);
|
---|
| 911 | #ifdef DEBUG
|
---|
[42436] | 912 | LogFlowFunc(("uProcessID=%RU32 (%RU32 total)\n",
|
---|
| 913 | uProcessID, mData.mProcesses.size()));
|
---|
| 914 | #endif
|
---|
[42272] | 915 | int rc;
|
---|
[42214] | 916 | SessionProcesses::const_iterator itProc
|
---|
[42436] | 917 | = mData.mProcesses.find(uProcessID);
|
---|
[42214] | 918 | if (itProc != mData.mProcesses.end())
|
---|
| 919 | {
|
---|
| 920 | ComObjPtr<GuestProcess> pProcess(itProc->second);
|
---|
| 921 | Assert(!pProcess.isNull());
|
---|
| 922 |
|
---|
[44863] | 923 | /* Set protocol version so that pSvcCb can
|
---|
| 924 | * be interpreted right. */
|
---|
| 925 | pCtxCb->uProtocol = mData.mProtocolVersion;
|
---|
| 926 |
|
---|
[42214] | 927 | alock.release();
|
---|
[44863] | 928 | rc = pProcess->callbackDispatcher(pCtxCb, pSvcCb);
|
---|
[42214] | 929 | }
|
---|
[42272] | 930 | else
|
---|
| 931 | rc = VERR_NOT_FOUND;
|
---|
| 932 |
|
---|
| 933 | LogFlowFuncLeaveRC(rc);
|
---|
| 934 | return rc;
|
---|
[42214] | 935 | }
|
---|
| 936 |
|
---|
[44863] | 937 | int GuestSession::dispatchToThis(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCb)
|
---|
| 938 | {
|
---|
| 939 | AssertPtrReturn(pCbCtx, VERR_INVALID_POINTER);
|
---|
| 940 | AssertPtrReturn(pSvcCb, VERR_INVALID_POINTER);
|
---|
| 941 |
|
---|
| 942 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 943 |
|
---|
| 944 | #ifdef DEBUG
|
---|
[45415] | 945 | LogFlowThisFunc(("sessionID=%RU32, CID=%RU32, uFunction=%RU32, pSvcCb=%p\n",
|
---|
[44935] | 946 | mData.mSession.mID, pCbCtx->uContextID, pCbCtx->uFunction, pSvcCb));
|
---|
[44863] | 947 | #endif
|
---|
| 948 |
|
---|
| 949 | int rc = VINF_SUCCESS;
|
---|
| 950 | switch (pCbCtx->uFunction)
|
---|
| 951 | {
|
---|
[44935] | 952 | case GUEST_DISCONNECTED:
|
---|
[45415] | 953 | /** @todo Handle closing all guest objects. */
|
---|
[44935] | 954 | break;
|
---|
| 955 |
|
---|
[44863] | 956 | case GUEST_SESSION_NOTIFY:
|
---|
| 957 | {
|
---|
[45415] | 958 | rc = onSessionStatusChange(pCbCtx, pSvcCb);
|
---|
[44863] | 959 | break;
|
---|
| 960 | }
|
---|
| 961 |
|
---|
| 962 | default:
|
---|
| 963 | /* Silently skip unknown callbacks. */
|
---|
[44935] | 964 | rc = VERR_NOT_SUPPORTED;
|
---|
[44863] | 965 | break;
|
---|
| 966 | }
|
---|
| 967 |
|
---|
| 968 | LogFlowFuncLeaveRC(rc);
|
---|
| 969 | return rc;
|
---|
| 970 | }
|
---|
| 971 |
|
---|
| 972 | inline bool GuestSession::fileExists(uint32_t uFileID, ComObjPtr<GuestFile> *pFile)
|
---|
| 973 | {
|
---|
| 974 | SessionFiles::const_iterator it = mData.mFiles.find(uFileID);
|
---|
| 975 | if (it != mData.mFiles.end())
|
---|
| 976 | {
|
---|
| 977 | if (pFile)
|
---|
| 978 | *pFile = it->second;
|
---|
| 979 | return true;
|
---|
| 980 | }
|
---|
| 981 | return false;
|
---|
| 982 | }
|
---|
| 983 |
|
---|
[42897] | 984 | int GuestSession::fileRemoveFromList(GuestFile *pFile)
|
---|
[42105] | 985 | {
|
---|
| 986 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 987 |
|
---|
| 988 | for (SessionFiles::iterator itFiles = mData.mFiles.begin();
|
---|
| 989 | itFiles != mData.mFiles.end(); ++itFiles)
|
---|
| 990 | {
|
---|
[44863] | 991 | if (pFile == itFiles->second)
|
---|
[42105] | 992 | {
|
---|
[44863] | 993 | GuestFile *pThis = itFiles->second;
|
---|
| 994 | AssertPtr(pThis);
|
---|
| 995 |
|
---|
[42897] | 996 | Bstr strName;
|
---|
[44863] | 997 | HRESULT hr = pThis->COMGETTER(FileName)(strName.asOutParam());
|
---|
[42897] | 998 | ComAssertComRC(hr);
|
---|
| 999 |
|
---|
| 1000 | Assert(mData.mNumObjects);
|
---|
[45434] | 1001 | LogFlowThisFunc(("Removing guest file \"%s\" (Session: %RU32) (now total %ld files, %ld objects)\n",
|
---|
[44935] | 1002 | Utf8Str(strName).c_str(), mData.mSession.mID, mData.mFiles.size() - 1, mData.mNumObjects - 1));
|
---|
[45434] | 1003 |
|
---|
[42160] | 1004 | mData.mFiles.erase(itFiles);
|
---|
[42897] | 1005 | mData.mNumObjects--;
|
---|
[45434] | 1006 |
|
---|
| 1007 | fireGuestFileRegisteredEvent(mEventSource, this, pFile,
|
---|
| 1008 | false /* Unregistered */);
|
---|
[42105] | 1009 | return VINF_SUCCESS;
|
---|
| 1010 | }
|
---|
| 1011 | }
|
---|
| 1012 |
|
---|
| 1013 | return VERR_NOT_FOUND;
|
---|
| 1014 | }
|
---|
| 1015 |
|
---|
[43162] | 1016 | int GuestSession::fileRemoveInternal(const Utf8Str &strPath, int *pGuestRc)
|
---|
[42691] | 1017 | {
|
---|
| 1018 | GuestProcessStartupInfo procInfo;
|
---|
| 1019 | GuestProcessStream streamOut;
|
---|
| 1020 |
|
---|
| 1021 | procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_RM);
|
---|
[43162] | 1022 | procInfo.mFlags = ProcessCreateFlag_WaitForStdOut;
|
---|
[42691] | 1023 | procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
|
---|
[43162] | 1024 | procInfo.mArguments.push_back(strPath); /* The file we want to remove. */
|
---|
[42691] | 1025 |
|
---|
[43162] | 1026 | GuestProcessTool procTool; int guestRc;
|
---|
| 1027 | int vrc = procTool.Init(this, procInfo, false /* Async */, &guestRc);
|
---|
| 1028 | if (RT_SUCCESS(vrc))
|
---|
| 1029 | vrc = procTool.Wait(GUESTPROCESSTOOL_FLAG_NONE, &guestRc);
|
---|
| 1030 |
|
---|
| 1031 | if (RT_SUCCESS(vrc))
|
---|
[42691] | 1032 | {
|
---|
[43162] | 1033 | if (RT_SUCCESS(guestRc))
|
---|
| 1034 | guestRc = procTool.TerminatedOk(NULL /* Exit code */);
|
---|
| 1035 | }
|
---|
[42691] | 1036 |
|
---|
[45078] | 1037 | if ( vrc == VERR_GSTCTL_GUEST_ERROR
|
---|
[44863] | 1038 | && pGuestRc)
|
---|
[45078] | 1039 | {
|
---|
[43162] | 1040 | *pGuestRc = guestRc;
|
---|
[45078] | 1041 | }
|
---|
[42691] | 1042 |
|
---|
[44863] | 1043 | LogFlowFuncLeaveRC(vrc);
|
---|
| 1044 | return vrc;
|
---|
[42691] | 1045 | }
|
---|
| 1046 |
|
---|
[44863] | 1047 | int GuestSession::fileOpenInternal(const GuestFileOpenInfo &openInfo, ComObjPtr<GuestFile> &pFile, int *pGuestRc)
|
---|
[42611] | 1048 | {
|
---|
| 1049 | LogFlowThisFunc(("strPath=%s, strOpenMode=%s, strDisposition=%s, uCreationMode=%x, iOffset=%RI64\n",
|
---|
[44863] | 1050 | openInfo.mFileName.c_str(), openInfo.mOpenMode.c_str(), openInfo.mDisposition.c_str(),
|
---|
| 1051 | openInfo.mCreationMode, openInfo.mInitialOffset));
|
---|
[42611] | 1052 |
|
---|
[44863] | 1053 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1054 |
|
---|
| 1055 | int rc = VERR_MAX_PROCS_REACHED;
|
---|
| 1056 | if (mData.mNumObjects >= VBOX_GUESTCTRL_MAX_OBJECTS)
|
---|
| 1057 | return rc;
|
---|
| 1058 |
|
---|
| 1059 | /* Create a new (host-based) file ID and assign it. */
|
---|
| 1060 | uint32_t uNewFileID = 0;
|
---|
| 1061 | ULONG uTries = 0;
|
---|
| 1062 |
|
---|
| 1063 | for (;;)
|
---|
| 1064 | {
|
---|
| 1065 | /* Is the file ID already used? */
|
---|
| 1066 | if (!fileExists(uNewFileID, NULL /* pProgress */))
|
---|
| 1067 | {
|
---|
| 1068 | /* Callback with context ID was not found. This means
|
---|
| 1069 | * we can use this context ID for our new callback we want
|
---|
| 1070 | * to add below. */
|
---|
| 1071 | rc = VINF_SUCCESS;
|
---|
| 1072 | break;
|
---|
| 1073 | }
|
---|
| 1074 | uNewFileID++;
|
---|
| 1075 | if (uNewFileID == VBOX_GUESTCTRL_MAX_OBJECTS)
|
---|
| 1076 | uNewFileID = 0;
|
---|
| 1077 |
|
---|
| 1078 | if (++uTries == UINT32_MAX)
|
---|
| 1079 | break; /* Don't try too hard. */
|
---|
| 1080 | }
|
---|
| 1081 |
|
---|
| 1082 | if (RT_FAILURE(rc))
|
---|
| 1083 | return rc;
|
---|
| 1084 |
|
---|
[42693] | 1085 | /* Create the directory object. */
|
---|
| 1086 | HRESULT hr = pFile.createObject();
|
---|
| 1087 | if (FAILED(hr))
|
---|
| 1088 | return VERR_COM_UNEXPECTED;
|
---|
[42611] | 1089 |
|
---|
[45415] | 1090 | Console *pConsole = mParent->getConsole();
|
---|
[44863] | 1091 | AssertPtr(pConsole);
|
---|
[42611] | 1092 |
|
---|
[44863] | 1093 | rc = pFile->init(pConsole, this /* GuestSession */,
|
---|
| 1094 | uNewFileID, openInfo);
|
---|
| 1095 | if (RT_FAILURE(rc))
|
---|
| 1096 | return rc;
|
---|
| 1097 |
|
---|
[45109] | 1098 | int guestRc;
|
---|
| 1099 | rc = pFile->openFile(&guestRc);
|
---|
| 1100 | if (RT_SUCCESS(rc))
|
---|
| 1101 | {
|
---|
| 1102 | /* Add the created file to our vector. */
|
---|
| 1103 | mData.mFiles[uNewFileID] = pFile;
|
---|
| 1104 | mData.mNumObjects++;
|
---|
| 1105 | Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
|
---|
[42611] | 1106 |
|
---|
[45434] | 1107 | LogFlowFunc(("Added new guest file \"%s\" (Session: %RU32) (now total %ld files, %ld objects)\n",
|
---|
[45109] | 1108 | openInfo.mFileName.c_str(), mData.mSession.mID, mData.mFiles.size(), mData.mNumObjects));
|
---|
[45434] | 1109 |
|
---|
| 1110 | fireGuestFileRegisteredEvent(mEventSource, this, pFile,
|
---|
| 1111 | true /* Registered */);
|
---|
[45109] | 1112 | }
|
---|
[42611] | 1113 |
|
---|
[45109] | 1114 | if (pGuestRc)
|
---|
| 1115 | *pGuestRc = guestRc;
|
---|
| 1116 |
|
---|
[44863] | 1117 | LogFlowFuncLeaveRC(rc);
|
---|
| 1118 | return rc;
|
---|
[42611] | 1119 | }
|
---|
| 1120 |
|
---|
[43162] | 1121 | int GuestSession::fileQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc)
|
---|
[42530] | 1122 | {
|
---|
| 1123 | LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
|
---|
| 1124 |
|
---|
[43162] | 1125 | int vrc = fsQueryInfoInternal(strPath, objData, pGuestRc);
|
---|
| 1126 | if (RT_SUCCESS(vrc))
|
---|
[42808] | 1127 | {
|
---|
[43162] | 1128 | vrc = objData.mType == FsObjType_File
|
---|
| 1129 | ? VINF_SUCCESS : VERR_NOT_A_FILE;
|
---|
[42808] | 1130 | }
|
---|
| 1131 |
|
---|
[43162] | 1132 | LogFlowFuncLeaveRC(vrc);
|
---|
| 1133 | return vrc;
|
---|
[42808] | 1134 | }
|
---|
| 1135 |
|
---|
[43162] | 1136 | int GuestSession::fileQuerySizeInternal(const Utf8Str &strPath, int64_t *pllSize, int *pGuestRc)
|
---|
[42808] | 1137 | {
|
---|
| 1138 | AssertPtrReturn(pllSize, VERR_INVALID_POINTER);
|
---|
| 1139 |
|
---|
| 1140 | GuestFsObjData objData;
|
---|
[43162] | 1141 | int vrc = fileQueryInfoInternal(strPath, objData, pGuestRc);
|
---|
| 1142 | if (RT_SUCCESS(vrc))
|
---|
| 1143 | *pllSize = objData.mObjectSize;
|
---|
[42808] | 1144 |
|
---|
[43162] | 1145 | return vrc;
|
---|
[42808] | 1146 | }
|
---|
| 1147 |
|
---|
[43162] | 1148 | int GuestSession::fsQueryInfoInternal(const Utf8Str &strPath, GuestFsObjData &objData, int *pGuestRc)
|
---|
[42808] | 1149 | {
|
---|
| 1150 | LogFlowThisFunc(("strPath=%s\n", strPath.c_str()));
|
---|
| 1151 |
|
---|
[42846] | 1152 | /** @todo Merge this with IGuestFile::queryInfo(). */
|
---|
[42611] | 1153 | GuestProcessStartupInfo procInfo;
|
---|
[42530] | 1154 | procInfo.mCommand = Utf8Str(VBOXSERVICE_TOOL_STAT);
|
---|
[43162] | 1155 | procInfo.mFlags = ProcessCreateFlag_WaitForStdOut;
|
---|
[42530] | 1156 |
|
---|
| 1157 | /* Construct arguments. */
|
---|
| 1158 | procInfo.mArguments.push_back(Utf8Str("--machinereadable"));
|
---|
| 1159 | procInfo.mArguments.push_back(strPath);
|
---|
| 1160 |
|
---|
[43162] | 1161 | GuestProcessTool procTool; int guestRc;
|
---|
| 1162 | int vrc = procTool.Init(this, procInfo, false /* Async */, &guestRc);
|
---|
| 1163 | if (RT_SUCCESS(vrc))
|
---|
| 1164 | vrc = procTool.Wait(GUESTPROCESSTOOL_FLAG_NONE, &guestRc);
|
---|
| 1165 | if (RT_SUCCESS(vrc))
|
---|
[42530] | 1166 | {
|
---|
[43162] | 1167 | guestRc = procTool.TerminatedOk(NULL /* Exit code */);
|
---|
| 1168 | if (RT_SUCCESS(guestRc))
|
---|
[42530] | 1169 | {
|
---|
[43162] | 1170 | GuestProcessStreamBlock curBlock;
|
---|
| 1171 | vrc = procTool.GetCurrentBlock(OUTPUT_HANDLE_ID_STDOUT, curBlock);
|
---|
| 1172 | /** @todo Check for more / validate blocks! */
|
---|
| 1173 | if (RT_SUCCESS(vrc))
|
---|
| 1174 | vrc = objData.FromStat(curBlock);
|
---|
[42530] | 1175 | }
|
---|
| 1176 | }
|
---|
| 1177 |
|
---|
[45078] | 1178 | if ( vrc == VERR_GSTCTL_GUEST_ERROR
|
---|
[44863] | 1179 | && pGuestRc)
|
---|
[45078] | 1180 | {
|
---|
[43162] | 1181 | *pGuestRc = guestRc;
|
---|
[45078] | 1182 | }
|
---|
[42530] | 1183 |
|
---|
[43162] | 1184 | LogFlowFuncLeaveRC(vrc);
|
---|
[44863] | 1185 | return vrc;
|
---|
[42530] | 1186 | }
|
---|
| 1187 |
|
---|
[42160] | 1188 | const GuestCredentials& GuestSession::getCredentials(void)
|
---|
| 1189 | {
|
---|
| 1190 | return mData.mCredentials;
|
---|
| 1191 | }
|
---|
| 1192 |
|
---|
[42171] | 1193 | const GuestEnvironment& GuestSession::getEnvironment(void)
|
---|
| 1194 | {
|
---|
| 1195 | return mData.mEnvironment;
|
---|
| 1196 | }
|
---|
| 1197 |
|
---|
[42546] | 1198 | Utf8Str GuestSession::getName(void)
|
---|
| 1199 | {
|
---|
[44935] | 1200 | return mData.mSession.mName;
|
---|
[42546] | 1201 | }
|
---|
| 1202 |
|
---|
[44935] | 1203 | /* static */
|
---|
| 1204 | Utf8Str GuestSession::guestErrorToString(int guestRc)
|
---|
| 1205 | {
|
---|
| 1206 | Utf8Str strError;
|
---|
| 1207 |
|
---|
| 1208 | /** @todo pData->u32Flags: int vs. uint32 -- IPRT errors are *negative* !!! */
|
---|
| 1209 | switch (guestRc)
|
---|
| 1210 | {
|
---|
| 1211 | case VERR_INVALID_VM_HANDLE:
|
---|
| 1212 | strError += Utf8StrFmt(tr("VMM device is not available (is the VM running?)"));
|
---|
| 1213 | break;
|
---|
| 1214 |
|
---|
| 1215 | case VERR_HGCM_SERVICE_NOT_FOUND:
|
---|
| 1216 | strError += Utf8StrFmt(tr("The guest execution service is not available"));
|
---|
| 1217 | break;
|
---|
| 1218 |
|
---|
| 1219 | case VERR_AUTHENTICATION_FAILURE:
|
---|
| 1220 | strError += Utf8StrFmt(tr("The specified user was not able to logon on guest"));
|
---|
| 1221 | break;
|
---|
| 1222 |
|
---|
| 1223 | case VERR_TIMEOUT:
|
---|
| 1224 | strError += Utf8StrFmt(tr("The guest did not respond within time"));
|
---|
| 1225 | break;
|
---|
| 1226 |
|
---|
| 1227 | case VERR_CANCELLED:
|
---|
| 1228 | strError += Utf8StrFmt(tr("The session operation was canceled"));
|
---|
| 1229 | break;
|
---|
| 1230 |
|
---|
| 1231 | case VERR_PERMISSION_DENIED:
|
---|
| 1232 | strError += Utf8StrFmt(tr("Invalid user/password credentials"));
|
---|
| 1233 | break;
|
---|
| 1234 |
|
---|
| 1235 | case VERR_MAX_PROCS_REACHED:
|
---|
[45415] | 1236 | strError += Utf8StrFmt(tr("Maximum number of concurrent guest processes has been reached"));
|
---|
[44935] | 1237 | break;
|
---|
| 1238 |
|
---|
| 1239 | case VERR_NOT_EQUAL: /** @todo Imprecise to the user; can mean anything and all. */
|
---|
| 1240 | strError += Utf8StrFmt(tr("Unable to retrieve requested information"));
|
---|
| 1241 | break;
|
---|
| 1242 |
|
---|
| 1243 | case VERR_NOT_FOUND:
|
---|
| 1244 | strError += Utf8StrFmt(tr("The guest execution service is not ready (yet)"));
|
---|
| 1245 | break;
|
---|
| 1246 |
|
---|
| 1247 | default:
|
---|
| 1248 | strError += Utf8StrFmt("%Rrc", guestRc);
|
---|
| 1249 | break;
|
---|
| 1250 | }
|
---|
| 1251 |
|
---|
| 1252 | return strError;
|
---|
| 1253 | }
|
---|
| 1254 |
|
---|
[45415] | 1255 | /**
|
---|
| 1256 | * Checks if this session is ready state where it can handle
|
---|
| 1257 | * all session-bound actions (like guest processes, guest files).
|
---|
| 1258 | * Only used by official API methods. Will set an external
|
---|
| 1259 | * error when not ready.
|
---|
| 1260 | */
|
---|
| 1261 | HRESULT GuestSession::isReadyExternal(void)
|
---|
| 1262 | {
|
---|
| 1263 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1264 |
|
---|
| 1265 | /** @todo Be a bit more informative. */
|
---|
| 1266 | if (mData.mStatus != GuestSessionStatus_Started)
|
---|
| 1267 | return setError(E_UNEXPECTED, tr("Session is not in started state"));
|
---|
| 1268 |
|
---|
| 1269 | return S_OK;
|
---|
| 1270 | }
|
---|
| 1271 |
|
---|
[44863] | 1272 | /** No locking! */
|
---|
[45415] | 1273 | int GuestSession::onSessionStatusChange(PVBOXGUESTCTRLHOSTCBCTX pCbCtx, PVBOXGUESTCTRLHOSTCALLBACK pSvcCbData)
|
---|
[44863] | 1274 | {
|
---|
[45415] | 1275 | AssertPtrReturn(pCbCtx, VERR_INVALID_POINTER);
|
---|
[44863] | 1276 | /* pCallback is optional. */
|
---|
| 1277 | AssertPtrReturn(pSvcCbData, VERR_INVALID_POINTER);
|
---|
| 1278 |
|
---|
| 1279 | if (pSvcCbData->mParms < 3)
|
---|
| 1280 | return VERR_INVALID_PARAMETER;
|
---|
| 1281 |
|
---|
| 1282 | CALLBACKDATA_SESSION_NOTIFY dataCb;
|
---|
| 1283 | /* pSvcCb->mpaParms[0] always contains the context ID. */
|
---|
| 1284 | pSvcCbData->mpaParms[1].getUInt32(&dataCb.uType);
|
---|
| 1285 | pSvcCbData->mpaParms[2].getUInt32(&dataCb.uResult);
|
---|
| 1286 |
|
---|
[45415] | 1287 | LogFlowThisFunc(("ID=%RU32, uType=%RU32, guestRc=%Rrc\n",
|
---|
| 1288 | mData.mSession.mID, dataCb.uType, dataCb.uResult));
|
---|
[44863] | 1289 |
|
---|
| 1290 | int vrc = VINF_SUCCESS;
|
---|
| 1291 |
|
---|
[45415] | 1292 | GuestSessionStatus_T sessionStatus = GuestSessionStatus_Undefined;
|
---|
| 1293 |
|
---|
[44935] | 1294 | int guestRc = dataCb.uResult; /** @todo uint32_t vs. int. */
|
---|
| 1295 | switch (dataCb.uType)
|
---|
| 1296 | {
|
---|
| 1297 | case GUEST_SESSION_NOTIFYTYPE_ERROR:
|
---|
[45415] | 1298 | sessionStatus = GuestSessionStatus_Error;
|
---|
[44935] | 1299 | break;
|
---|
| 1300 |
|
---|
[45010] | 1301 | case GUEST_SESSION_NOTIFYTYPE_STARTED:
|
---|
[45415] | 1302 | sessionStatus = GuestSessionStatus_Started;
|
---|
[44935] | 1303 | break;
|
---|
| 1304 |
|
---|
[45010] | 1305 | case GUEST_SESSION_NOTIFYTYPE_TEN:
|
---|
| 1306 | case GUEST_SESSION_NOTIFYTYPE_TES:
|
---|
| 1307 | case GUEST_SESSION_NOTIFYTYPE_TEA:
|
---|
[45415] | 1308 | sessionStatus = GuestSessionStatus_Terminated;
|
---|
[44935] | 1309 | break;
|
---|
| 1310 |
|
---|
[45010] | 1311 | case GUEST_SESSION_NOTIFYTYPE_TOK:
|
---|
[45415] | 1312 | sessionStatus = GuestSessionStatus_TimedOutKilled;
|
---|
[45010] | 1313 | break;
|
---|
| 1314 |
|
---|
| 1315 | case GUEST_SESSION_NOTIFYTYPE_TOA:
|
---|
[45415] | 1316 | sessionStatus = GuestSessionStatus_TimedOutAbnormally;
|
---|
[45010] | 1317 | break;
|
---|
| 1318 |
|
---|
| 1319 | case GUEST_SESSION_NOTIFYTYPE_DWN:
|
---|
[45415] | 1320 | sessionStatus = GuestSessionStatus_Down;
|
---|
[45010] | 1321 | break;
|
---|
| 1322 |
|
---|
[45415] | 1323 | case GUEST_SESSION_NOTIFYTYPE_UNDEFINED:
|
---|
[44935] | 1324 | default:
|
---|
| 1325 | vrc = VERR_NOT_SUPPORTED;
|
---|
| 1326 | break;
|
---|
| 1327 | }
|
---|
| 1328 |
|
---|
| 1329 | if (RT_SUCCESS(vrc))
|
---|
| 1330 | {
|
---|
| 1331 | if (RT_FAILURE(guestRc))
|
---|
[45415] | 1332 | sessionStatus = GuestSessionStatus_Error;
|
---|
[44935] | 1333 | }
|
---|
| 1334 |
|
---|
[45415] | 1335 | /* Set the session status. */
|
---|
| 1336 | if (sessionStatus != GuestSessionStatus_Undefined)
|
---|
[44863] | 1337 | {
|
---|
[45415] | 1338 | int rc2 = setSessionStatus(sessionStatus, guestRc);
|
---|
| 1339 | if (RT_SUCCESS(vrc))
|
---|
| 1340 | vrc = rc2;
|
---|
[44863] | 1341 | }
|
---|
| 1342 |
|
---|
[45415] | 1343 | LogFlowThisFunc(("ID=%RU32, guestRc=%Rrc\n", mData.mSession.mID, guestRc));
|
---|
[44935] | 1344 |
|
---|
[44863] | 1345 | LogFlowFuncLeaveRC(vrc);
|
---|
| 1346 | return vrc;
|
---|
| 1347 | }
|
---|
| 1348 |
|
---|
[47469] | 1349 | int GuestSession::startSessionInternal(int *pGuestRc)
|
---|
[44863] | 1350 | {
|
---|
| 1351 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1352 |
|
---|
[45415] | 1353 | LogFlowThisFunc(("mID=%RU32, mName=%s, uProtocolVersion=%RU32, openFlags=%x, openTimeoutMS=%RU32\n",
|
---|
| 1354 | mData.mSession.mID, mData.mSession.mName.c_str(), mData.mProtocolVersion,
|
---|
| 1355 | mData.mSession.mOpenFlags, mData.mSession.mOpenTimeoutMS));
|
---|
[44863] | 1356 |
|
---|
[47469] | 1357 | /* Guest Additions < 4.3 don't support opening dedicated
|
---|
[44935] | 1358 | guest sessions. Simply return success here. */
|
---|
[44863] | 1359 | if (mData.mProtocolVersion < 2)
|
---|
| 1360 | {
|
---|
[44935] | 1361 | mData.mStatus = GuestSessionStatus_Started;
|
---|
| 1362 |
|
---|
| 1363 | LogFlowThisFunc(("Installed Guest Additions don't support opening dedicated sessions, skipping\n"));
|
---|
[44863] | 1364 | return VINF_SUCCESS;
|
---|
| 1365 | }
|
---|
| 1366 |
|
---|
[45415] | 1367 | if (mData.mStatus != GuestSessionStatus_Undefined)
|
---|
| 1368 | return VINF_SUCCESS;
|
---|
| 1369 |
|
---|
[44935] | 1370 | /** @todo mData.mSession.uFlags validation. */
|
---|
[44863] | 1371 |
|
---|
[44935] | 1372 | /* Set current session status. */
|
---|
| 1373 | mData.mStatus = GuestSessionStatus_Starting;
|
---|
| 1374 |
|
---|
[45780] | 1375 | int vrc;
|
---|
| 1376 |
|
---|
| 1377 | GuestWaitEvent *pEvent = NULL;
|
---|
| 1378 | std::list < VBoxEventType_T > eventTypes;
|
---|
| 1379 | try
|
---|
[44863] | 1380 | {
|
---|
[45780] | 1381 | eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
|
---|
[44863] | 1382 |
|
---|
[47469] | 1383 | vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
|
---|
| 1384 | eventTypes, &pEvent);
|
---|
[44863] | 1385 | }
|
---|
[45780] | 1386 | catch (std::bad_alloc)
|
---|
| 1387 | {
|
---|
| 1388 | vrc = VERR_NO_MEMORY;
|
---|
| 1389 | }
|
---|
[44863] | 1390 |
|
---|
[45780] | 1391 | if (RT_FAILURE(vrc))
|
---|
| 1392 | return vrc;
|
---|
| 1393 |
|
---|
| 1394 | VBOXHGCMSVCPARM paParms[8];
|
---|
| 1395 |
|
---|
| 1396 | int i = 0;
|
---|
| 1397 | paParms[i++].setUInt32(pEvent->ContextID());
|
---|
| 1398 | paParms[i++].setUInt32(mData.mProtocolVersion);
|
---|
| 1399 | paParms[i++].setPointer((void*)mData.mCredentials.mUser.c_str(),
|
---|
| 1400 | (ULONG)mData.mCredentials.mUser.length() + 1);
|
---|
| 1401 | paParms[i++].setPointer((void*)mData.mCredentials.mPassword.c_str(),
|
---|
| 1402 | (ULONG)mData.mCredentials.mPassword.length() + 1);
|
---|
| 1403 | paParms[i++].setPointer((void*)mData.mCredentials.mDomain.c_str(),
|
---|
| 1404 | (ULONG)mData.mCredentials.mDomain.length() + 1);
|
---|
| 1405 | paParms[i++].setUInt32(mData.mSession.mOpenFlags);
|
---|
| 1406 |
|
---|
| 1407 | vrc = sendCommand(HOST_SESSION_CREATE, i, paParms);
|
---|
[44863] | 1408 | if (RT_SUCCESS(vrc))
|
---|
| 1409 | {
|
---|
[45415] | 1410 | alock.release(); /* Drop write lock before waiting. */
|
---|
[44935] | 1411 |
|
---|
[45780] | 1412 | vrc = waitForStatusChange(pEvent, GuestSessionWaitForFlag_Start,
|
---|
| 1413 | 30 * 1000 /* 30s timeout */,
|
---|
| 1414 | NULL /* Session status */, pGuestRc);
|
---|
[44863] | 1415 | }
|
---|
| 1416 |
|
---|
[47469] | 1417 | unregisterWaitEvent(pEvent);
|
---|
[45780] | 1418 |
|
---|
[44863] | 1419 | LogFlowFuncLeaveRC(vrc);
|
---|
| 1420 | return vrc;
|
---|
| 1421 | }
|
---|
| 1422 |
|
---|
[45010] | 1423 | int GuestSession::startSessionAsync(void)
|
---|
[44935] | 1424 | {
|
---|
| 1425 | LogFlowThisFuncEnter();
|
---|
| 1426 |
|
---|
| 1427 | int vrc;
|
---|
| 1428 |
|
---|
| 1429 | try
|
---|
| 1430 | {
|
---|
| 1431 | /* Asynchronously open the session on the guest by kicking off a
|
---|
| 1432 | * worker thread. */
|
---|
| 1433 | std::auto_ptr<GuestSessionTaskInternalOpen> pTask(new GuestSessionTaskInternalOpen(this));
|
---|
| 1434 | AssertReturn(pTask->isOk(), pTask->rc());
|
---|
| 1435 |
|
---|
[45010] | 1436 | vrc = RTThreadCreate(NULL, GuestSession::startSessionThread,
|
---|
[44935] | 1437 | (void *)pTask.get(), 0,
|
---|
| 1438 | RTTHREADTYPE_MAIN_WORKER, 0,
|
---|
[45010] | 1439 | "gctlSesStart");
|
---|
[44935] | 1440 | if (RT_SUCCESS(vrc))
|
---|
| 1441 | {
|
---|
| 1442 | /* pTask is now owned by openSessionThread(), so release it. */
|
---|
| 1443 | pTask.release();
|
---|
| 1444 | }
|
---|
| 1445 | }
|
---|
| 1446 | catch(std::bad_alloc &)
|
---|
| 1447 | {
|
---|
| 1448 | vrc = VERR_NO_MEMORY;
|
---|
| 1449 | }
|
---|
| 1450 |
|
---|
| 1451 | LogFlowFuncLeaveRC(vrc);
|
---|
| 1452 | return vrc;
|
---|
| 1453 | }
|
---|
| 1454 |
|
---|
| 1455 | /* static */
|
---|
[45010] | 1456 | DECLCALLBACK(int) GuestSession::startSessionThread(RTTHREAD Thread, void *pvUser)
|
---|
[44935] | 1457 | {
|
---|
| 1458 | LogFlowFunc(("pvUser=%p\n", pvUser));
|
---|
| 1459 |
|
---|
| 1460 | std::auto_ptr<GuestSessionTaskInternalOpen> pTask(static_cast<GuestSessionTaskInternalOpen*>(pvUser));
|
---|
| 1461 | AssertPtr(pTask.get());
|
---|
| 1462 |
|
---|
| 1463 | const ComObjPtr<GuestSession> pSession(pTask->Session());
|
---|
| 1464 | Assert(!pSession.isNull());
|
---|
| 1465 |
|
---|
| 1466 | AutoCaller autoCaller(pSession);
|
---|
| 1467 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 1468 |
|
---|
[47469] | 1469 | int vrc = pSession->startSessionInternal(NULL /* Guest rc, ignored */);
|
---|
[44935] | 1470 | /* Nothing to do here anymore. */
|
---|
| 1471 |
|
---|
| 1472 | LogFlowFuncLeaveRC(vrc);
|
---|
| 1473 | return vrc;
|
---|
| 1474 | }
|
---|
| 1475 |
|
---|
[42897] | 1476 | int GuestSession::processRemoveFromList(GuestProcess *pProcess)
|
---|
[42105] | 1477 | {
|
---|
[45415] | 1478 | AssertPtrReturn(pProcess, VERR_INVALID_POINTER);
|
---|
[42897] | 1479 |
|
---|
[45415] | 1480 | LogFlowThisFunc(("pProcess=%p\n", pProcess));
|
---|
| 1481 |
|
---|
[42105] | 1482 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1483 |
|
---|
[42897] | 1484 | int rc = VERR_NOT_FOUND;
|
---|
| 1485 |
|
---|
| 1486 | ULONG uPID;
|
---|
| 1487 | HRESULT hr = pProcess->COMGETTER(PID)(&uPID);
|
---|
[45415] | 1488 | ComAssertComRC(hr);
|
---|
[42897] | 1489 |
|
---|
| 1490 | LogFlowFunc(("Closing process (PID=%RU32) ...\n", uPID));
|
---|
| 1491 |
|
---|
[45415] | 1492 | SessionProcesses::iterator itProcs = mData.mProcesses.begin();
|
---|
| 1493 | while (itProcs != mData.mProcesses.end())
|
---|
[42105] | 1494 | {
|
---|
[42160] | 1495 | if (pProcess == itProcs->second)
|
---|
[42105] | 1496 | {
|
---|
[42897] | 1497 | GuestProcess *pCurProc = itProcs->second;
|
---|
| 1498 | AssertPtr(pCurProc);
|
---|
[42634] | 1499 |
|
---|
[42897] | 1500 | hr = pCurProc->COMGETTER(PID)(&uPID);
|
---|
| 1501 | ComAssertComRC(hr);
|
---|
| 1502 |
|
---|
| 1503 | Assert(mData.mNumObjects);
|
---|
[45415] | 1504 | LogFlowFunc(("Removing process ID=%RU32 (Session: %RU32), guest PID=%RU32 (now total %ld processes, %ld objects)\n",
|
---|
| 1505 | pCurProc->getObjectID(), mData.mSession.mID, uPID, mData.mProcesses.size() - 1, mData.mNumObjects - 1));
|
---|
[42897] | 1506 |
|
---|
[47469] | 1507 | pCurProc->cancelWaitEvents();
|
---|
| 1508 |
|
---|
| 1509 | itProcs->second->Release();
|
---|
| 1510 |
|
---|
[42160] | 1511 | mData.mProcesses.erase(itProcs);
|
---|
[42897] | 1512 | mData.mNumObjects--;
|
---|
| 1513 |
|
---|
[45415] | 1514 | fireGuestProcessRegisteredEvent(mEventSource, this /* Session */, NULL /* Process */,
|
---|
| 1515 | uPID, false /* Process unregistered */);
|
---|
[42897] | 1516 | rc = VINF_SUCCESS;
|
---|
| 1517 | break;
|
---|
[42105] | 1518 | }
|
---|
[45415] | 1519 |
|
---|
| 1520 | itProcs++;
|
---|
[42105] | 1521 | }
|
---|
| 1522 |
|
---|
[42897] | 1523 | LogFlowFuncLeaveRC(rc);
|
---|
| 1524 | return rc;
|
---|
[42105] | 1525 | }
|
---|
| 1526 |
|
---|
[42611] | 1527 | /**
|
---|
| 1528 | * Creates but does *not* start the process yet. See GuestProcess::startProcess() or
|
---|
| 1529 | * GuestProcess::startProcessAsync() for that.
|
---|
| 1530 | *
|
---|
| 1531 | * @return IPRT status code.
|
---|
| 1532 | * @param procInfo
|
---|
| 1533 | * @param pProcess
|
---|
| 1534 | */
|
---|
| 1535 | int GuestSession::processCreateExInteral(GuestProcessStartupInfo &procInfo, ComObjPtr<GuestProcess> &pProcess)
|
---|
[42105] | 1536 | {
|
---|
[42436] | 1537 | LogFlowFunc(("mCmd=%s, mFlags=%x, mTimeoutMS=%RU32\n",
|
---|
| 1538 | procInfo.mCommand.c_str(), procInfo.mFlags, procInfo.mTimeoutMS));
|
---|
[42611] | 1539 | #ifdef DEBUG
|
---|
| 1540 | if (procInfo.mArguments.size())
|
---|
| 1541 | {
|
---|
| 1542 | LogFlowFunc(("Arguments:"));
|
---|
| 1543 | ProcessArguments::const_iterator it = procInfo.mArguments.begin();
|
---|
| 1544 | while (it != procInfo.mArguments.end())
|
---|
| 1545 | {
|
---|
| 1546 | LogFlow((" %s", (*it).c_str()));
|
---|
| 1547 | it++;
|
---|
| 1548 | }
|
---|
| 1549 | LogFlow(("\n"));
|
---|
| 1550 | }
|
---|
| 1551 | #endif
|
---|
[42436] | 1552 |
|
---|
[42105] | 1553 | /* Validate flags. */
|
---|
[42354] | 1554 | if (procInfo.mFlags)
|
---|
[42105] | 1555 | {
|
---|
[42354] | 1556 | if ( !(procInfo.mFlags & ProcessCreateFlag_IgnoreOrphanedProcesses)
|
---|
| 1557 | && !(procInfo.mFlags & ProcessCreateFlag_WaitForProcessStartOnly)
|
---|
| 1558 | && !(procInfo.mFlags & ProcessCreateFlag_Hidden)
|
---|
[42411] | 1559 | && !(procInfo.mFlags & ProcessCreateFlag_NoProfile)
|
---|
| 1560 | && !(procInfo.mFlags & ProcessCreateFlag_WaitForStdOut)
|
---|
| 1561 | && !(procInfo.mFlags & ProcessCreateFlag_WaitForStdErr))
|
---|
[42105] | 1562 | {
|
---|
| 1563 | return VERR_INVALID_PARAMETER;
|
---|
| 1564 | }
|
---|
| 1565 | }
|
---|
| 1566 |
|
---|
[43981] | 1567 | if ( (procInfo.mFlags & ProcessCreateFlag_WaitForProcessStartOnly)
|
---|
| 1568 | && ( (procInfo.mFlags & ProcessCreateFlag_WaitForStdOut)
|
---|
| 1569 | || (procInfo.mFlags & ProcessCreateFlag_WaitForStdErr)
|
---|
| 1570 | )
|
---|
| 1571 | )
|
---|
| 1572 | {
|
---|
| 1573 | return VERR_INVALID_PARAMETER;
|
---|
| 1574 | }
|
---|
| 1575 |
|
---|
[42105] | 1576 | /* Adjust timeout. If set to 0, we define
|
---|
| 1577 | * an infinite timeout. */
|
---|
[42272] | 1578 | if (procInfo.mTimeoutMS == 0)
|
---|
| 1579 | procInfo.mTimeoutMS = UINT32_MAX;
|
---|
[42105] | 1580 |
|
---|
| 1581 | /** @tood Implement process priority + affinity. */
|
---|
| 1582 |
|
---|
[42436] | 1583 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 1584 |
|
---|
[42272] | 1585 | int rc = VERR_MAX_PROCS_REACHED;
|
---|
[42897] | 1586 | if (mData.mNumObjects >= VBOX_GUESTCTRL_MAX_OBJECTS)
|
---|
[42272] | 1587 | return rc;
|
---|
[42160] | 1588 |
|
---|
| 1589 | /* Create a new (host-based) process ID and assign it. */
|
---|
[42634] | 1590 | uint32_t uNewProcessID = 0;
|
---|
[42214] | 1591 | ULONG uTries = 0;
|
---|
[42160] | 1592 |
|
---|
| 1593 | for (;;)
|
---|
| 1594 | {
|
---|
[42272] | 1595 | /* Is the context ID already used? */
|
---|
[42634] | 1596 | if (!processExists(uNewProcessID, NULL /* pProgress */))
|
---|
[42160] | 1597 | {
|
---|
| 1598 | /* Callback with context ID was not found. This means
|
---|
| 1599 | * we can use this context ID for our new callback we want
|
---|
| 1600 | * to add below. */
|
---|
| 1601 | rc = VINF_SUCCESS;
|
---|
| 1602 | break;
|
---|
| 1603 | }
|
---|
[42634] | 1604 | uNewProcessID++;
|
---|
[42897] | 1605 | if (uNewProcessID == VBOX_GUESTCTRL_MAX_OBJECTS)
|
---|
[42634] | 1606 | uNewProcessID = 0;
|
---|
[42160] | 1607 |
|
---|
[44935] | 1608 | if (++uTries == VBOX_GUESTCTRL_MAX_OBJECTS)
|
---|
[42160] | 1609 | break; /* Don't try too hard. */
|
---|
| 1610 | }
|
---|
| 1611 |
|
---|
[42693] | 1612 | if (RT_FAILURE(rc))
|
---|
| 1613 | return rc;
|
---|
[42105] | 1614 |
|
---|
[42693] | 1615 | /* Create the process object. */
|
---|
| 1616 | HRESULT hr = pProcess.createObject();
|
---|
| 1617 | if (FAILED(hr))
|
---|
| 1618 | return VERR_COM_UNEXPECTED;
|
---|
[42105] | 1619 |
|
---|
[45415] | 1620 | rc = pProcess->init(mParent->getConsole() /* Console */, this /* Session */,
|
---|
[42693] | 1621 | uNewProcessID, procInfo);
|
---|
| 1622 | if (RT_FAILURE(rc))
|
---|
| 1623 | return rc;
|
---|
[42436] | 1624 |
|
---|
[42693] | 1625 | /* Add the created process to our map. */
|
---|
| 1626 | mData.mProcesses[uNewProcessID] = pProcess;
|
---|
[42897] | 1627 | mData.mNumObjects++;
|
---|
| 1628 | Assert(mData.mNumObjects <= VBOX_GUESTCTRL_MAX_OBJECTS);
|
---|
[42105] | 1629 |
|
---|
[45415] | 1630 | fireGuestProcessRegisteredEvent(mEventSource, this /* Session */, pProcess,
|
---|
| 1631 | 0 /* PID */, true /* Process registered */);
|
---|
| 1632 |
|
---|
[42897] | 1633 | LogFlowFunc(("Added new process (Session: %RU32) with process ID=%RU32 (now total %ld processes, %ld objects)\n",
|
---|
[44935] | 1634 | mData.mSession.mID, uNewProcessID, mData.mProcesses.size(), mData.mNumObjects));
|
---|
[42693] | 1635 |
|
---|
[42105] | 1636 | return rc;
|
---|
[42160] | 1637 | }
|
---|
[42105] | 1638 |
|
---|
[42439] | 1639 | inline bool GuestSession::processExists(uint32_t uProcessID, ComObjPtr<GuestProcess> *pProcess)
|
---|
[42160] | 1640 | {
|
---|
[42214] | 1641 | SessionProcesses::const_iterator it = mData.mProcesses.find(uProcessID);
|
---|
| 1642 | if (it != mData.mProcesses.end())
|
---|
| 1643 | {
|
---|
| 1644 | if (pProcess)
|
---|
| 1645 | *pProcess = it->second;
|
---|
| 1646 | return true;
|
---|
| 1647 | }
|
---|
| 1648 | return false;
|
---|
[42105] | 1649 | }
|
---|
| 1650 |
|
---|
[42214] | 1651 | inline int GuestSession::processGetByPID(ULONG uPID, ComObjPtr<GuestProcess> *pProcess)
|
---|
| 1652 | {
|
---|
| 1653 | AssertReturn(uPID, false);
|
---|
| 1654 | /* pProcess is optional. */
|
---|
| 1655 |
|
---|
[42897] | 1656 | SessionProcesses::iterator itProcs = mData.mProcesses.begin();
|
---|
| 1657 | for (; itProcs != mData.mProcesses.end(); itProcs++)
|
---|
[42214] | 1658 | {
|
---|
[42897] | 1659 | ComObjPtr<GuestProcess> pCurProc = itProcs->second;
|
---|
[42214] | 1660 | AutoCaller procCaller(pCurProc);
|
---|
| 1661 | if (procCaller.rc())
|
---|
| 1662 | return VERR_COM_INVALID_OBJECT_STATE;
|
---|
| 1663 |
|
---|
[42897] | 1664 | ULONG uCurPID;
|
---|
| 1665 | HRESULT hr = pCurProc->COMGETTER(PID)(&uCurPID);
|
---|
| 1666 | ComAssertComRC(hr);
|
---|
| 1667 |
|
---|
| 1668 | if (uCurPID == uPID)
|
---|
[42214] | 1669 | {
|
---|
| 1670 | if (pProcess)
|
---|
| 1671 | *pProcess = pCurProc;
|
---|
| 1672 | return VINF_SUCCESS;
|
---|
| 1673 | }
|
---|
| 1674 | }
|
---|
| 1675 |
|
---|
| 1676 | return VERR_NOT_FOUND;
|
---|
| 1677 | }
|
---|
| 1678 |
|
---|
[44863] | 1679 | int GuestSession::sendCommand(uint32_t uFunction,
|
---|
| 1680 | uint32_t uParms, PVBOXHGCMSVCPARM paParms)
|
---|
| 1681 | {
|
---|
| 1682 | LogFlowThisFuncEnter();
|
---|
| 1683 |
|
---|
| 1684 | #ifndef VBOX_GUESTCTRL_TEST_CASE
|
---|
[45415] | 1685 | ComObjPtr<Console> pConsole = mParent->getConsole();
|
---|
[44863] | 1686 | Assert(!pConsole.isNull());
|
---|
| 1687 |
|
---|
| 1688 | /* Forward the information to the VMM device. */
|
---|
| 1689 | VMMDev *pVMMDev = pConsole->getVMMDev();
|
---|
| 1690 | AssertPtr(pVMMDev);
|
---|
| 1691 |
|
---|
| 1692 | LogFlowThisFunc(("uFunction=%RU32, uParms=%RU32\n", uFunction, uParms));
|
---|
| 1693 | int vrc = pVMMDev->hgcmHostCall(HGCMSERVICE_NAME, uFunction, uParms, paParms);
|
---|
| 1694 | if (RT_FAILURE(vrc))
|
---|
| 1695 | {
|
---|
| 1696 | /** @todo What to do here? */
|
---|
| 1697 | }
|
---|
| 1698 | #else
|
---|
| 1699 | /* Not needed within testcases. */
|
---|
| 1700 | int vrc = VINF_SUCCESS;
|
---|
| 1701 | #endif
|
---|
| 1702 | LogFlowFuncLeaveRC(vrc);
|
---|
| 1703 | return vrc;
|
---|
| 1704 | }
|
---|
| 1705 |
|
---|
[44935] | 1706 | /* static */
|
---|
| 1707 | HRESULT GuestSession::setErrorExternal(VirtualBoxBase *pInterface, int guestRc)
|
---|
| 1708 | {
|
---|
| 1709 | AssertPtr(pInterface);
|
---|
| 1710 | AssertMsg(RT_FAILURE(guestRc), ("Guest rc does not indicate a failure when setting error\n"));
|
---|
| 1711 |
|
---|
| 1712 | return pInterface->setError(VBOX_E_IPRT_ERROR, GuestSession::guestErrorToString(guestRc).c_str());
|
---|
| 1713 | }
|
---|
| 1714 |
|
---|
[45415] | 1715 | /* Does not do locking; caller is responsible for that! */
|
---|
| 1716 | int GuestSession::setSessionStatus(GuestSessionStatus_T sessionStatus, int sessionRc)
|
---|
| 1717 | {
|
---|
| 1718 | LogFlowThisFunc(("oldStatus=%ld, newStatus=%ld, sessionRc=%Rrc\n",
|
---|
| 1719 | mData.mStatus, sessionStatus, sessionRc));
|
---|
| 1720 |
|
---|
| 1721 | if (sessionStatus == GuestSessionStatus_Error)
|
---|
| 1722 | {
|
---|
| 1723 | AssertMsg(RT_FAILURE(sessionRc), ("Guest rc must be an error (%Rrc)\n", sessionRc));
|
---|
| 1724 | /* Do not allow overwriting an already set error. If this happens
|
---|
| 1725 | * this means we forgot some error checking/locking somewhere. */
|
---|
| 1726 | AssertMsg(RT_SUCCESS(mData.mRC), ("Guest rc already set (to %Rrc)\n", mData.mRC));
|
---|
| 1727 | }
|
---|
| 1728 | else
|
---|
| 1729 | AssertMsg(RT_SUCCESS(sessionRc), ("Guest rc must not be an error (%Rrc)\n", sessionRc));
|
---|
| 1730 |
|
---|
| 1731 | if (mData.mStatus != sessionStatus)
|
---|
| 1732 | {
|
---|
| 1733 | mData.mStatus = sessionStatus;
|
---|
| 1734 | mData.mRC = sessionRc;
|
---|
| 1735 |
|
---|
[45805] | 1736 | ComObjPtr<VirtualBoxErrorInfo> errorInfo;
|
---|
[45415] | 1737 | HRESULT hr = errorInfo.createObject();
|
---|
| 1738 | ComAssertComRC(hr);
|
---|
[45805] | 1739 | int rc2 = errorInfo->initEx(VBOX_E_IPRT_ERROR, sessionRc,
|
---|
| 1740 | COM_IIDOF(IGuestSession), getComponentName(),
|
---|
| 1741 | guestErrorToString(sessionRc));
|
---|
[45415] | 1742 | AssertRC(rc2);
|
---|
| 1743 |
|
---|
| 1744 | fireGuestSessionStateChangedEvent(mEventSource, this,
|
---|
| 1745 | mData.mSession.mID, sessionStatus, errorInfo);
|
---|
| 1746 | }
|
---|
| 1747 |
|
---|
| 1748 | return VINF_SUCCESS;
|
---|
| 1749 | }
|
---|
| 1750 |
|
---|
| 1751 | int GuestSession::signalWaiters(GuestSessionWaitResult_T enmWaitResult, int rc /*= VINF_SUCCESS */)
|
---|
| 1752 | {
|
---|
| 1753 | /*LogFlowThisFunc(("enmWaitResult=%d, rc=%Rrc, mWaitCount=%RU32, mWaitEvent=%p\n",
|
---|
| 1754 | enmWaitResult, rc, mData.mWaitCount, mData.mWaitEvent));*/
|
---|
| 1755 |
|
---|
| 1756 | /* Note: No write locking here -- already done in the caller. */
|
---|
| 1757 |
|
---|
| 1758 | int vrc = VINF_SUCCESS;
|
---|
| 1759 | /*if (mData.mWaitEvent)
|
---|
| 1760 | vrc = mData.mWaitEvent->Signal(enmWaitResult, rc);*/
|
---|
| 1761 | LogFlowFuncLeaveRC(vrc);
|
---|
| 1762 | return vrc;
|
---|
| 1763 | }
|
---|
| 1764 |
|
---|
[42566] | 1765 | int GuestSession::startTaskAsync(const Utf8Str &strTaskDesc,
|
---|
| 1766 | GuestSessionTask *pTask, ComObjPtr<Progress> &pProgress)
|
---|
| 1767 | {
|
---|
| 1768 | LogFlowThisFunc(("strTaskDesc=%s, pTask=%p\n", strTaskDesc.c_str(), pTask));
|
---|
| 1769 |
|
---|
| 1770 | AssertPtrReturn(pTask, VERR_INVALID_POINTER);
|
---|
| 1771 |
|
---|
[42693] | 1772 | /* Create the progress object. */
|
---|
| 1773 | HRESULT hr = pProgress.createObject();
|
---|
| 1774 | if (FAILED(hr))
|
---|
| 1775 | return VERR_COM_UNEXPECTED;
|
---|
[42566] | 1776 |
|
---|
[42693] | 1777 | hr = pProgress->init(static_cast<IGuestSession*>(this),
|
---|
| 1778 | Bstr(strTaskDesc).raw(),
|
---|
| 1779 | TRUE /* aCancelable */);
|
---|
| 1780 | if (FAILED(hr))
|
---|
| 1781 | return VERR_COM_UNEXPECTED;
|
---|
[42566] | 1782 |
|
---|
[42693] | 1783 | /* Initialize our worker task. */
|
---|
| 1784 | std::auto_ptr<GuestSessionTask> task(pTask);
|
---|
[42566] | 1785 |
|
---|
[42693] | 1786 | int rc = task->RunAsync(strTaskDesc, pProgress);
|
---|
| 1787 | if (RT_FAILURE(rc))
|
---|
| 1788 | return rc;
|
---|
[42566] | 1789 |
|
---|
[42693] | 1790 | /* Don't destruct on success. */
|
---|
| 1791 | task.release();
|
---|
[42566] | 1792 |
|
---|
| 1793 | LogFlowFuncLeaveRC(rc);
|
---|
| 1794 | return rc;
|
---|
| 1795 | }
|
---|
| 1796 |
|
---|
[42461] | 1797 | /**
|
---|
| 1798 | * Queries/collects information prior to establishing a guest session.
|
---|
| 1799 | * This is necessary to know which guest control protocol version to use,
|
---|
| 1800 | * among other things (later).
|
---|
| 1801 | *
|
---|
| 1802 | * @return IPRT status code.
|
---|
| 1803 | */
|
---|
| 1804 | int GuestSession::queryInfo(void)
|
---|
| 1805 | {
|
---|
| 1806 | /*
|
---|
| 1807 | * Try querying the guest control protocol version running on the guest.
|
---|
| 1808 | * This is done using the Guest Additions version
|
---|
| 1809 | */
|
---|
[45415] | 1810 | ComObjPtr<Guest> pGuest = mParent;
|
---|
[42461] | 1811 | Assert(!pGuest.isNull());
|
---|
| 1812 |
|
---|
| 1813 | uint32_t uVerAdditions = pGuest->getAdditionsVersion();
|
---|
[47469] | 1814 | uint32_t uVBoxMajor = VBOX_FULL_VERSION_GET_MAJOR(uVerAdditions);
|
---|
| 1815 | uint32_t uVBoxMinor = VBOX_FULL_VERSION_GET_MINOR(uVerAdditions);
|
---|
| 1816 |
|
---|
| 1817 | mData.mProtocolVersion = (
|
---|
| 1818 | /* VBox 5.0 and up. */
|
---|
| 1819 | uVBoxMajor >= 5
|
---|
| 1820 | /* VBox 4.3 and up. */
|
---|
| 1821 | || (uVBoxMajor == 4 && uVBoxMinor >= 3))
|
---|
[42461] | 1822 | ? 2 /* Guest control 2.0. */
|
---|
[44863] | 1823 | : 1; /* Legacy guest control (VBox < 4.3). */
|
---|
[42461] | 1824 | /* Build revision is ignored. */
|
---|
| 1825 |
|
---|
[47469] | 1826 | LogFlowThisFunc(("uVerAdditions=%RU32 (%RU32.%RU32), mProtocolVersion=%RU32\n",
|
---|
| 1827 | uVerAdditions, uVBoxMajor, uVBoxMinor, mData.mProtocolVersion));
|
---|
| 1828 |
|
---|
[42461] | 1829 | /* Tell the user but don't bitch too often. */
|
---|
| 1830 | static short s_gctrlLegacyWarning = 0;
|
---|
| 1831 | if (s_gctrlLegacyWarning++ < 3) /** @todo Find a bit nicer text. */
|
---|
| 1832 | LogRel((tr("Warning: Guest Additions are older (%ld.%ld) than host capabilities for guest control, please upgrade them. Using protocol version %ld now\n"),
|
---|
[47469] | 1833 | uVBoxMajor, uVBoxMinor, mData.mProtocolVersion));
|
---|
| 1834 |
|
---|
[42461] | 1835 | return VINF_SUCCESS;
|
---|
| 1836 | }
|
---|
| 1837 |
|
---|
[45010] | 1838 | int GuestSession::waitFor(uint32_t fWaitFlags, ULONG uTimeoutMS, GuestSessionWaitResult_T &waitResult, int *pGuestRc)
|
---|
| 1839 | {
|
---|
| 1840 | LogFlowThisFuncEnter();
|
---|
| 1841 |
|
---|
| 1842 | AssertReturn(fWaitFlags, VERR_INVALID_PARAMETER);
|
---|
| 1843 |
|
---|
[45415] | 1844 | /*LogFlowThisFunc(("fWaitFlags=0x%x, uTimeoutMS=%RU32, mStatus=%RU32, mWaitCount=%RU32, mWaitEvent=%p, pGuestRc=%p\n",
|
---|
| 1845 | fWaitFlags, uTimeoutMS, mData.mStatus, mData.mWaitCount, mData.mWaitEvent, pGuestRc));*/
|
---|
[45010] | 1846 |
|
---|
[47469] | 1847 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
[45010] | 1848 |
|
---|
| 1849 | /* Did some error occur before? Then skip waiting and return. */
|
---|
| 1850 | if (mData.mStatus == GuestSessionStatus_Error)
|
---|
| 1851 | {
|
---|
| 1852 | waitResult = GuestSessionWaitResult_Error;
|
---|
| 1853 | AssertMsg(RT_FAILURE(mData.mRC), ("No error rc (%Rrc) set when guest session indicated an error\n", mData.mRC));
|
---|
| 1854 | if (pGuestRc)
|
---|
| 1855 | *pGuestRc = mData.mRC; /* Return last set error. */
|
---|
[45078] | 1856 | return VERR_GSTCTL_GUEST_ERROR;
|
---|
[45010] | 1857 | }
|
---|
| 1858 |
|
---|
[47469] | 1859 | /* Guest Additions < 4.3 don't support session handling, skip. */
|
---|
| 1860 | if (mData.mProtocolVersion < 2)
|
---|
| 1861 | {
|
---|
| 1862 | waitResult = GuestSessionWaitResult_WaitFlagNotSupported;
|
---|
| 1863 |
|
---|
| 1864 | LogFlowThisFunc(("Installed Guest Additions don't support waiting for dedicated sessions, skipping\n"));
|
---|
| 1865 | return VINF_SUCCESS;
|
---|
| 1866 | }
|
---|
| 1867 |
|
---|
[45010] | 1868 | waitResult = GuestSessionWaitResult_None;
|
---|
| 1869 | if (fWaitFlags & GuestSessionWaitForFlag_Terminate)
|
---|
| 1870 | {
|
---|
| 1871 | switch (mData.mStatus)
|
---|
| 1872 | {
|
---|
| 1873 | case GuestSessionStatus_Terminated:
|
---|
| 1874 | case GuestSessionStatus_Down:
|
---|
| 1875 | waitResult = GuestSessionWaitResult_Terminate;
|
---|
| 1876 | break;
|
---|
| 1877 |
|
---|
| 1878 | case GuestSessionStatus_TimedOutKilled:
|
---|
| 1879 | case GuestSessionStatus_TimedOutAbnormally:
|
---|
| 1880 | waitResult = GuestSessionWaitResult_Timeout;
|
---|
| 1881 | break;
|
---|
| 1882 |
|
---|
| 1883 | case GuestSessionStatus_Error:
|
---|
| 1884 | /* Handled above. */
|
---|
| 1885 | break;
|
---|
| 1886 |
|
---|
| 1887 | case GuestSessionStatus_Started:
|
---|
| 1888 | waitResult = GuestSessionWaitResult_Start;
|
---|
| 1889 | break;
|
---|
| 1890 |
|
---|
| 1891 | case GuestSessionStatus_Undefined:
|
---|
| 1892 | case GuestSessionStatus_Starting:
|
---|
| 1893 | /* Do the waiting below. */
|
---|
| 1894 | break;
|
---|
| 1895 |
|
---|
| 1896 | default:
|
---|
| 1897 | AssertMsgFailed(("Unhandled session status %ld\n", mData.mStatus));
|
---|
| 1898 | return VERR_NOT_IMPLEMENTED;
|
---|
| 1899 | }
|
---|
| 1900 | }
|
---|
| 1901 | else if (fWaitFlags & GuestSessionWaitForFlag_Start)
|
---|
| 1902 | {
|
---|
| 1903 | switch (mData.mStatus)
|
---|
| 1904 | {
|
---|
| 1905 | case GuestSessionStatus_Started:
|
---|
| 1906 | case GuestSessionStatus_Terminating:
|
---|
| 1907 | case GuestSessionStatus_Terminated:
|
---|
| 1908 | case GuestSessionStatus_Down:
|
---|
| 1909 | waitResult = GuestSessionWaitResult_Start;
|
---|
| 1910 | break;
|
---|
| 1911 |
|
---|
| 1912 | case GuestSessionStatus_Error:
|
---|
| 1913 | waitResult = GuestSessionWaitResult_Error;
|
---|
| 1914 | break;
|
---|
| 1915 |
|
---|
| 1916 | case GuestSessionStatus_TimedOutKilled:
|
---|
| 1917 | case GuestSessionStatus_TimedOutAbnormally:
|
---|
| 1918 | waitResult = GuestSessionWaitResult_Timeout;
|
---|
| 1919 | break;
|
---|
| 1920 |
|
---|
| 1921 | case GuestSessionStatus_Undefined:
|
---|
| 1922 | case GuestSessionStatus_Starting:
|
---|
| 1923 | /* Do the waiting below. */
|
---|
| 1924 | break;
|
---|
| 1925 |
|
---|
| 1926 | default:
|
---|
| 1927 | AssertMsgFailed(("Unhandled session status %ld\n", mData.mStatus));
|
---|
| 1928 | return VERR_NOT_IMPLEMENTED;
|
---|
| 1929 | }
|
---|
| 1930 | }
|
---|
| 1931 |
|
---|
| 1932 | LogFlowThisFunc(("sessionStatus=%ld, sessionRc=%Rrc, waitResult=%ld\n",
|
---|
| 1933 | mData.mStatus, mData.mRC, waitResult));
|
---|
| 1934 |
|
---|
| 1935 | /* No waiting needed? Return immediately using the last set error. */
|
---|
| 1936 | if (waitResult != GuestSessionWaitResult_None)
|
---|
| 1937 | {
|
---|
| 1938 | if (pGuestRc)
|
---|
| 1939 | *pGuestRc = mData.mRC; /* Return last set error (if any). */
|
---|
[45078] | 1940 | return RT_SUCCESS(mData.mRC) ? VINF_SUCCESS : VERR_GSTCTL_GUEST_ERROR;
|
---|
[45010] | 1941 | }
|
---|
| 1942 |
|
---|
[45415] | 1943 | alock.release(); /* Release lock before waiting. */
|
---|
[45010] | 1944 |
|
---|
[45780] | 1945 | int vrc;
|
---|
| 1946 |
|
---|
| 1947 | GuestWaitEvent *pEvent = NULL;
|
---|
| 1948 | std::list < VBoxEventType_T > eventTypes;
|
---|
| 1949 | try
|
---|
| 1950 | {
|
---|
| 1951 | eventTypes.push_back(VBoxEventType_OnGuestSessionStateChanged);
|
---|
| 1952 |
|
---|
[47469] | 1953 | vrc = registerWaitEvent(mData.mSession.mID, 0 /* Object ID */,
|
---|
| 1954 | eventTypes, &pEvent);
|
---|
[45780] | 1955 | }
|
---|
| 1956 | catch (std::bad_alloc)
|
---|
| 1957 | {
|
---|
| 1958 | vrc = VERR_NO_MEMORY;
|
---|
| 1959 | }
|
---|
| 1960 |
|
---|
| 1961 | if (RT_FAILURE(vrc))
|
---|
| 1962 | return vrc;
|
---|
| 1963 |
|
---|
[45415] | 1964 | GuestSessionStatus_T sessionStatus;
|
---|
[45780] | 1965 | vrc = waitForStatusChange(pEvent, fWaitFlags,
|
---|
| 1966 | uTimeoutMS, &sessionStatus, pGuestRc);
|
---|
[45415] | 1967 | if (RT_SUCCESS(vrc))
|
---|
[45010] | 1968 | {
|
---|
[45415] | 1969 | switch (sessionStatus)
|
---|
| 1970 | {
|
---|
| 1971 | case GuestSessionStatus_Started:
|
---|
| 1972 | waitResult = GuestSessionWaitResult_Start;
|
---|
| 1973 | break;
|
---|
| 1974 |
|
---|
| 1975 | case GuestSessionStatus_Terminated:
|
---|
| 1976 | waitResult = GuestSessionWaitResult_Terminate;
|
---|
| 1977 | break;
|
---|
| 1978 |
|
---|
| 1979 | case GuestSessionStatus_TimedOutKilled:
|
---|
| 1980 | case GuestSessionStatus_TimedOutAbnormally:
|
---|
| 1981 | waitResult = GuestSessionWaitResult_Timeout;
|
---|
| 1982 | break;
|
---|
| 1983 |
|
---|
| 1984 | case GuestSessionStatus_Down:
|
---|
| 1985 | waitResult = GuestSessionWaitResult_Terminate;
|
---|
| 1986 | break;
|
---|
| 1987 |
|
---|
| 1988 | case GuestSessionStatus_Error:
|
---|
| 1989 | waitResult = GuestSessionWaitResult_Error;
|
---|
| 1990 | break;
|
---|
| 1991 |
|
---|
| 1992 | default:
|
---|
| 1993 | waitResult = GuestSessionWaitResult_Status;
|
---|
| 1994 | break;
|
---|
| 1995 | }
|
---|
[45010] | 1996 | }
|
---|
[45415] | 1997 |
|
---|
[47469] | 1998 | unregisterWaitEvent(pEvent);
|
---|
[45780] | 1999 |
|
---|
[45415] | 2000 | LogFlowFuncLeaveRC(vrc);
|
---|
| 2001 | return vrc;
|
---|
| 2002 | }
|
---|
| 2003 |
|
---|
[45780] | 2004 | int GuestSession::waitForStatusChange(GuestWaitEvent *pEvent, uint32_t fWaitFlags, uint32_t uTimeoutMS,
|
---|
| 2005 | GuestSessionStatus_T *pSessionStatus, int *pGuestRc)
|
---|
[45415] | 2006 | {
|
---|
[45780] | 2007 | AssertPtrReturn(pEvent, VERR_INVALID_POINTER);
|
---|
[45415] | 2008 |
|
---|
[45780] | 2009 | VBoxEventType_T evtType;
|
---|
| 2010 | ComPtr<IEvent> pIEvent;
|
---|
| 2011 | int vrc = waitForEvent(pEvent, uTimeoutMS,
|
---|
| 2012 | &evtType, pIEvent.asOutParam());
|
---|
| 2013 | if (RT_SUCCESS(vrc))
|
---|
[45010] | 2014 | {
|
---|
[45780] | 2015 | Assert(evtType == VBoxEventType_OnGuestSessionStateChanged);
|
---|
[45010] | 2016 |
|
---|
[45780] | 2017 | ComPtr<IGuestSessionStateChangedEvent> pChangedEvent = pIEvent;
|
---|
| 2018 | Assert(!pChangedEvent.isNull());
|
---|
[45010] | 2019 |
|
---|
[45780] | 2020 | GuestSessionStatus_T sessionStatus;
|
---|
| 2021 | pChangedEvent->COMGETTER(Status)(&sessionStatus);
|
---|
| 2022 | if (pSessionStatus)
|
---|
| 2023 | *pSessionStatus = sessionStatus;
|
---|
[45010] | 2024 |
|
---|
[45805] | 2025 | ComPtr<IVirtualBoxErrorInfo> errorInfo;
|
---|
[45780] | 2026 | HRESULT hr = pChangedEvent->COMGETTER(Error)(errorInfo.asOutParam());
|
---|
| 2027 | ComAssertComRC(hr);
|
---|
[45010] | 2028 |
|
---|
[45780] | 2029 | LONG lGuestRc;
|
---|
[45805] | 2030 | hr = errorInfo->COMGETTER(ResultDetail)(&lGuestRc);
|
---|
[45780] | 2031 | ComAssertComRC(hr);
|
---|
| 2032 | if (RT_FAILURE((int)lGuestRc))
|
---|
| 2033 | vrc = VERR_GSTCTL_GUEST_ERROR;
|
---|
| 2034 | if (pGuestRc)
|
---|
| 2035 | *pGuestRc = (int)lGuestRc;
|
---|
[45010] | 2036 |
|
---|
[45780] | 2037 | LogFlowThisFunc(("Status changed event for session ID=%RU32: %ld (%Rrc)\n",
|
---|
| 2038 | mData.mSession.mID, sessionStatus,
|
---|
| 2039 | RT_SUCCESS((int)lGuestRc) ? VINF_SUCCESS : (int)lGuestRc));
|
---|
[45010] | 2040 | }
|
---|
| 2041 |
|
---|
| 2042 | LogFlowFuncLeaveRC(vrc);
|
---|
| 2043 | return vrc;
|
---|
| 2044 | }
|
---|
| 2045 |
|
---|
[42084] | 2046 | // implementation of public methods
|
---|
| 2047 | /////////////////////////////////////////////////////////////////////////////
|
---|
| 2048 |
|
---|
| 2049 | STDMETHODIMP GuestSession::Close(void)
|
---|
| 2050 | {
|
---|
| 2051 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2052 | ReturnComNotImplemented();
|
---|
| 2053 | #else
|
---|
[42194] | 2054 | LogFlowThisFuncEnter();
|
---|
| 2055 |
|
---|
[42897] | 2056 | AutoCaller autoCaller(this);
|
---|
| 2057 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2058 |
|
---|
[45109] | 2059 | /* Close session on guest. */
|
---|
[47469] | 2060 | int guestRc = VINF_SUCCESS;
|
---|
[44863] | 2061 | int rc = closeSession(0 /* Flags */, 30 * 1000 /* Timeout */,
|
---|
| 2062 | &guestRc);
|
---|
[44935] | 2063 | /* On failure don't return here, instead do all the cleanup
|
---|
| 2064 | * work first and then return an error. */
|
---|
[44863] | 2065 |
|
---|
[42897] | 2066 | /* Remove ourselves from the session list. */
|
---|
[45415] | 2067 | int rc2 = mParent->sessionRemove(this);
|
---|
[44935] | 2068 | if (RT_SUCCESS(rc))
|
---|
| 2069 | rc = rc2;
|
---|
[42897] | 2070 |
|
---|
[47469] | 2071 | LogFlowThisFunc(("Returning rc=%Rrc, guestRc=%Rrc\n",
|
---|
| 2072 | rc, guestRc));
|
---|
[44935] | 2073 | if (RT_FAILURE(rc))
|
---|
| 2074 | {
|
---|
[45109] | 2075 | if (rc == VERR_GSTCTL_GUEST_ERROR)
|
---|
| 2076 | return GuestSession::setErrorExternal(this, guestRc);
|
---|
| 2077 |
|
---|
[44935] | 2078 | return setError(VBOX_E_IPRT_ERROR,
|
---|
[45415] | 2079 | tr("Closing guest session failed with %Rrc"), rc);
|
---|
[44935] | 2080 | }
|
---|
| 2081 |
|
---|
[42105] | 2082 | return S_OK;
|
---|
[42084] | 2083 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2084 | }
|
---|
| 2085 |
|
---|
[42566] | 2086 | STDMETHODIMP GuestSession::CopyFrom(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress)
|
---|
[42084] | 2087 | {
|
---|
| 2088 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2089 | ReturnComNotImplemented();
|
---|
| 2090 | #else
|
---|
[42566] | 2091 | CheckComArgStrNotEmptyOrNull(aSource);
|
---|
| 2092 | CheckComArgStrNotEmptyOrNull(aDest);
|
---|
| 2093 | CheckComArgOutPointerValid(aProgress);
|
---|
| 2094 |
|
---|
[42194] | 2095 | LogFlowThisFuncEnter();
|
---|
| 2096 |
|
---|
[42566] | 2097 | if (RT_UNLIKELY((aSource) == NULL || *(aSource) == '\0'))
|
---|
| 2098 | return setError(E_INVALIDARG, tr("No source specified"));
|
---|
| 2099 | if (RT_UNLIKELY((aDest) == NULL || *(aDest) == '\0'))
|
---|
| 2100 | return setError(E_INVALIDARG, tr("No destination specified"));
|
---|
| 2101 |
|
---|
[42084] | 2102 | AutoCaller autoCaller(this);
|
---|
| 2103 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2104 |
|
---|
[42566] | 2105 | uint32_t fFlags = CopyFileFlag_None;
|
---|
| 2106 | if (aFlags)
|
---|
| 2107 | {
|
---|
| 2108 | com::SafeArray<CopyFileFlag_T> flags(ComSafeArrayInArg(aFlags));
|
---|
| 2109 | for (size_t i = 0; i < flags.size(); i++)
|
---|
| 2110 | fFlags |= flags[i];
|
---|
| 2111 | }
|
---|
| 2112 |
|
---|
| 2113 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 2114 |
|
---|
| 2115 | HRESULT hr = S_OK;
|
---|
| 2116 |
|
---|
[43170] | 2117 | try
|
---|
[42566] | 2118 | {
|
---|
[43170] | 2119 | ComObjPtr<Progress> pProgress;
|
---|
| 2120 | SessionTaskCopyFrom *pTask = new SessionTaskCopyFrom(this /* GuestSession */,
|
---|
| 2121 | Utf8Str(aSource), Utf8Str(aDest), fFlags);
|
---|
| 2122 | int rc = startTaskAsync(Utf8StrFmt(tr("Copying \"%ls\" from guest to \"%ls\" on the host"), aSource, aDest),
|
---|
| 2123 | pTask, pProgress);
|
---|
| 2124 | if (RT_SUCCESS(rc))
|
---|
| 2125 | {
|
---|
| 2126 | /* Return progress to the caller. */
|
---|
| 2127 | hr = pProgress.queryInterfaceTo(aProgress);
|
---|
| 2128 | }
|
---|
| 2129 | else
|
---|
| 2130 | hr = setError(VBOX_E_IPRT_ERROR,
|
---|
| 2131 | tr("Starting task for copying file \"%ls\" from guest to \"%ls\" on the host failed: %Rrc"), rc);
|
---|
[42566] | 2132 | }
|
---|
[43170] | 2133 | catch(std::bad_alloc &)
|
---|
| 2134 | {
|
---|
| 2135 | hr = E_OUTOFMEMORY;
|
---|
| 2136 | }
|
---|
| 2137 |
|
---|
[42566] | 2138 | return hr;
|
---|
[42084] | 2139 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2140 | }
|
---|
| 2141 |
|
---|
[42566] | 2142 | STDMETHODIMP GuestSession::CopyTo(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(CopyFileFlag_T, aFlags), IProgress **aProgress)
|
---|
[42084] | 2143 | {
|
---|
| 2144 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2145 | ReturnComNotImplemented();
|
---|
| 2146 | #else
|
---|
[42566] | 2147 | CheckComArgStrNotEmptyOrNull(aSource);
|
---|
| 2148 | CheckComArgStrNotEmptyOrNull(aDest);
|
---|
| 2149 | CheckComArgOutPointerValid(aProgress);
|
---|
| 2150 |
|
---|
[42194] | 2151 | LogFlowThisFuncEnter();
|
---|
| 2152 |
|
---|
[42566] | 2153 | if (RT_UNLIKELY((aSource) == NULL || *(aSource) == '\0'))
|
---|
| 2154 | return setError(E_INVALIDARG, tr("No source specified"));
|
---|
| 2155 | if (RT_UNLIKELY((aDest) == NULL || *(aDest) == '\0'))
|
---|
| 2156 | return setError(E_INVALIDARG, tr("No destination specified"));
|
---|
| 2157 |
|
---|
[42084] | 2158 | AutoCaller autoCaller(this);
|
---|
| 2159 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2160 |
|
---|
[42566] | 2161 | uint32_t fFlags = CopyFileFlag_None;
|
---|
| 2162 | if (aFlags)
|
---|
| 2163 | {
|
---|
| 2164 | com::SafeArray<CopyFileFlag_T> flags(ComSafeArrayInArg(aFlags));
|
---|
| 2165 | for (size_t i = 0; i < flags.size(); i++)
|
---|
| 2166 | fFlags |= flags[i];
|
---|
| 2167 | }
|
---|
| 2168 |
|
---|
| 2169 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 2170 |
|
---|
| 2171 | HRESULT hr = S_OK;
|
---|
| 2172 |
|
---|
[43170] | 2173 | try
|
---|
[42566] | 2174 | {
|
---|
[43170] | 2175 | ComObjPtr<Progress> pProgress;
|
---|
| 2176 | SessionTaskCopyTo *pTask = new SessionTaskCopyTo(this /* GuestSession */,
|
---|
| 2177 | Utf8Str(aSource), Utf8Str(aDest), fFlags);
|
---|
[43493] | 2178 | AssertPtrReturn(pTask, E_OUTOFMEMORY);
|
---|
[43170] | 2179 | int rc = startTaskAsync(Utf8StrFmt(tr("Copying \"%ls\" from host to \"%ls\" on the guest"), aSource, aDest),
|
---|
| 2180 | pTask, pProgress);
|
---|
| 2181 | if (RT_SUCCESS(rc))
|
---|
| 2182 | {
|
---|
| 2183 | /* Return progress to the caller. */
|
---|
| 2184 | hr = pProgress.queryInterfaceTo(aProgress);
|
---|
| 2185 | }
|
---|
| 2186 | else
|
---|
| 2187 | hr = setError(VBOX_E_IPRT_ERROR,
|
---|
| 2188 | tr("Starting task for copying file \"%ls\" from host to \"%ls\" on the guest failed: %Rrc"), rc);
|
---|
[42566] | 2189 | }
|
---|
[43170] | 2190 | catch(std::bad_alloc &)
|
---|
| 2191 | {
|
---|
| 2192 | hr = E_OUTOFMEMORY;
|
---|
| 2193 | }
|
---|
| 2194 |
|
---|
| 2195 | return hr;
|
---|
[42084] | 2196 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2197 | }
|
---|
| 2198 |
|
---|
[42525] | 2199 | STDMETHODIMP GuestSession::DirectoryCreate(IN_BSTR aPath, ULONG aMode,
|
---|
[42808] | 2200 | ComSafeArrayIn(DirectoryCreateFlag_T, aFlags))
|
---|
[42084] | 2201 | {
|
---|
| 2202 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2203 | ReturnComNotImplemented();
|
---|
| 2204 | #else
|
---|
[42194] | 2205 | LogFlowThisFuncEnter();
|
---|
| 2206 |
|
---|
[42525] | 2207 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
| 2208 | return setError(E_INVALIDARG, tr("No directory to create specified"));
|
---|
| 2209 |
|
---|
[42084] | 2210 | AutoCaller autoCaller(this);
|
---|
| 2211 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2212 |
|
---|
[42525] | 2213 | uint32_t fFlags = DirectoryCreateFlag_None;
|
---|
| 2214 | if (aFlags)
|
---|
| 2215 | {
|
---|
| 2216 | com::SafeArray<DirectoryCreateFlag_T> flags(ComSafeArrayInArg(aFlags));
|
---|
| 2217 | for (size_t i = 0; i < flags.size(); i++)
|
---|
| 2218 | fFlags |= flags[i];
|
---|
| 2219 |
|
---|
[42611] | 2220 | if (fFlags)
|
---|
| 2221 | {
|
---|
| 2222 | if (!(fFlags & DirectoryCreateFlag_Parents))
|
---|
| 2223 | return setError(E_INVALIDARG, tr("Unknown flags (%#x)"), fFlags);
|
---|
| 2224 | }
|
---|
[42525] | 2225 | }
|
---|
| 2226 |
|
---|
| 2227 | HRESULT hr = S_OK;
|
---|
| 2228 |
|
---|
[43162] | 2229 | ComObjPtr <GuestDirectory> pDirectory; int guestRc;
|
---|
| 2230 | int rc = directoryCreateInternal(Utf8Str(aPath), (uint32_t)aMode, fFlags, &guestRc);
|
---|
[42808] | 2231 | if (RT_FAILURE(rc))
|
---|
[42525] | 2232 | {
|
---|
| 2233 | switch (rc)
|
---|
| 2234 | {
|
---|
[45078] | 2235 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[43162] | 2236 | hr = GuestProcess::setErrorExternal(this, guestRc);
|
---|
| 2237 | break;
|
---|
| 2238 |
|
---|
[42525] | 2239 | case VERR_INVALID_PARAMETER:
|
---|
| 2240 | hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Invalid parameters given"));
|
---|
| 2241 | break;
|
---|
| 2242 |
|
---|
| 2243 | case VERR_BROKEN_PIPE:
|
---|
| 2244 | hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Unexpectedly aborted"));
|
---|
| 2245 | break;
|
---|
| 2246 |
|
---|
| 2247 | case VERR_CANT_CREATE:
|
---|
| 2248 | hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: Could not create directory"));
|
---|
| 2249 | break;
|
---|
| 2250 |
|
---|
| 2251 | default:
|
---|
| 2252 | hr = setError(VBOX_E_IPRT_ERROR, tr("Directory creation failed: %Rrc"), rc);
|
---|
| 2253 | break;
|
---|
| 2254 | }
|
---|
| 2255 | }
|
---|
| 2256 |
|
---|
| 2257 | return hr;
|
---|
[42084] | 2258 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2259 | }
|
---|
| 2260 |
|
---|
[42765] | 2261 | STDMETHODIMP GuestSession::DirectoryCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aPath, BOOL aSecure, BSTR *aDirectory)
|
---|
[42084] | 2262 | {
|
---|
| 2263 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2264 | ReturnComNotImplemented();
|
---|
| 2265 | #else
|
---|
[42194] | 2266 | LogFlowThisFuncEnter();
|
---|
| 2267 |
|
---|
[42657] | 2268 | if (RT_UNLIKELY((aTemplate) == NULL || *(aTemplate) == '\0'))
|
---|
[43162] | 2269 | return setError(E_INVALIDARG, tr("No template specified"));
|
---|
| 2270 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
| 2271 | return setError(E_INVALIDARG, tr("No directory name specified"));
|
---|
| 2272 | CheckComArgOutPointerValid(aDirectory);
|
---|
[42657] | 2273 |
|
---|
[42084] | 2274 | AutoCaller autoCaller(this);
|
---|
| 2275 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2276 |
|
---|
[43162] | 2277 | HRESULT hr = S_OK;
|
---|
[42657] | 2278 |
|
---|
[43162] | 2279 | Utf8Str strName; int guestRc;
|
---|
| 2280 | int rc = objectCreateTempInternal(Utf8Str(aTemplate),
|
---|
| 2281 | Utf8Str(aPath),
|
---|
| 2282 | true /* Directory */, strName, &guestRc);
|
---|
| 2283 | if (RT_SUCCESS(rc))
|
---|
[42657] | 2284 | {
|
---|
[42783] | 2285 | strName.cloneTo(aDirectory);
|
---|
[42657] | 2286 | }
|
---|
[43162] | 2287 | else
|
---|
[42657] | 2288 | {
|
---|
[43162] | 2289 | switch (rc)
|
---|
| 2290 | {
|
---|
[45078] | 2291 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[43162] | 2292 | hr = GuestProcess::setErrorExternal(this, guestRc);
|
---|
| 2293 | break;
|
---|
| 2294 |
|
---|
| 2295 | default:
|
---|
| 2296 | hr = setError(VBOX_E_IPRT_ERROR, tr("Temporary directory creation \"%s\" with template \"%s\" failed: %Rrc"),
|
---|
| 2297 | Utf8Str(aPath).c_str(), Utf8Str(aTemplate).c_str(), rc);
|
---|
| 2298 | break;
|
---|
| 2299 | }
|
---|
[42657] | 2300 | }
|
---|
[43162] | 2301 |
|
---|
| 2302 | return hr;
|
---|
[42084] | 2303 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2304 | }
|
---|
| 2305 |
|
---|
[42090] | 2306 | STDMETHODIMP GuestSession::DirectoryExists(IN_BSTR aPath, BOOL *aExists)
|
---|
[42084] | 2307 | {
|
---|
| 2308 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2309 | ReturnComNotImplemented();
|
---|
| 2310 | #else
|
---|
[42194] | 2311 | LogFlowThisFuncEnter();
|
---|
| 2312 |
|
---|
[42531] | 2313 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
| 2314 | return setError(E_INVALIDARG, tr("No directory to check existence for specified"));
|
---|
| 2315 | CheckComArgOutPointerValid(aExists);
|
---|
| 2316 |
|
---|
[42084] | 2317 | AutoCaller autoCaller(this);
|
---|
| 2318 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2319 |
|
---|
[42531] | 2320 | HRESULT hr = S_OK;
|
---|
| 2321 |
|
---|
[43162] | 2322 | GuestFsObjData objData; int guestRc;
|
---|
| 2323 | int rc = directoryQueryInfoInternal(Utf8Str(aPath), objData, &guestRc);
|
---|
[42531] | 2324 | if (RT_SUCCESS(rc))
|
---|
| 2325 | {
|
---|
| 2326 | *aExists = objData.mType == FsObjType_Directory;
|
---|
| 2327 | }
|
---|
| 2328 | else
|
---|
| 2329 | {
|
---|
| 2330 | switch (rc)
|
---|
| 2331 | {
|
---|
[45078] | 2332 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[43162] | 2333 | hr = GuestProcess::setErrorExternal(this, guestRc);
|
---|
| 2334 | break;
|
---|
[42531] | 2335 |
|
---|
| 2336 | default:
|
---|
[43162] | 2337 | hr = setError(VBOX_E_IPRT_ERROR, tr("Querying directory existence \"%s\" failed: %Rrc"),
|
---|
| 2338 | Utf8Str(aPath).c_str(), rc);
|
---|
[42531] | 2339 | break;
|
---|
| 2340 | }
|
---|
| 2341 | }
|
---|
| 2342 |
|
---|
| 2343 | return hr;
|
---|
[42084] | 2344 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2345 | }
|
---|
| 2346 |
|
---|
[42673] | 2347 | STDMETHODIMP GuestSession::DirectoryOpen(IN_BSTR aPath, IN_BSTR aFilter, ComSafeArrayIn(DirectoryOpenFlag_T, aFlags), IGuestDirectory **aDirectory)
|
---|
[42084] | 2348 | {
|
---|
| 2349 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2350 | ReturnComNotImplemented();
|
---|
| 2351 | #else
|
---|
[42194] | 2352 | LogFlowThisFuncEnter();
|
---|
| 2353 |
|
---|
[42673] | 2354 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
| 2355 | return setError(E_INVALIDARG, tr("No directory to open specified"));
|
---|
| 2356 | if (RT_UNLIKELY((aFilter) != NULL && *(aFilter) != '\0'))
|
---|
[43162] | 2357 | return setError(E_INVALIDARG, tr("Directory filters are not implemented yet"));
|
---|
[42673] | 2358 | CheckComArgOutPointerValid(aDirectory);
|
---|
| 2359 |
|
---|
[42084] | 2360 | AutoCaller autoCaller(this);
|
---|
| 2361 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2362 |
|
---|
[42673] | 2363 | uint32_t fFlags = DirectoryOpenFlag_None;
|
---|
| 2364 | if (aFlags)
|
---|
| 2365 | {
|
---|
| 2366 | com::SafeArray<DirectoryOpenFlag_T> flags(ComSafeArrayInArg(aFlags));
|
---|
| 2367 | for (size_t i = 0; i < flags.size(); i++)
|
---|
| 2368 | fFlags |= flags[i];
|
---|
| 2369 |
|
---|
| 2370 | if (fFlags)
|
---|
| 2371 | return setError(E_INVALIDARG, tr("Open flags (%#x) not implemented yet"), fFlags);
|
---|
| 2372 | }
|
---|
| 2373 |
|
---|
| 2374 | HRESULT hr = S_OK;
|
---|
| 2375 |
|
---|
| 2376 | ComObjPtr <GuestDirectory> pDirectory;
|
---|
| 2377 | int rc = directoryOpenInternal(Utf8Str(aPath), Utf8Str(aFilter), fFlags, pDirectory);
|
---|
| 2378 | if (RT_SUCCESS(rc))
|
---|
| 2379 | {
|
---|
[43162] | 2380 | /* Return directory object to the caller. */
|
---|
| 2381 | hr = pDirectory.queryInterfaceTo(aDirectory);
|
---|
[42673] | 2382 | }
|
---|
| 2383 | else
|
---|
| 2384 | {
|
---|
| 2385 | switch (rc)
|
---|
| 2386 | {
|
---|
| 2387 | case VERR_INVALID_PARAMETER:
|
---|
[43162] | 2388 | hr = setError(VBOX_E_IPRT_ERROR, tr("Opening directory \"%s\" failed; invalid parameters given",
|
---|
| 2389 | Utf8Str(aPath).c_str()));
|
---|
[42673] | 2390 | break;
|
---|
| 2391 |
|
---|
| 2392 | default:
|
---|
[43162] | 2393 | hr = setError(VBOX_E_IPRT_ERROR, tr("Opening directory \"%s\" failed: %Rrc"),
|
---|
| 2394 | Utf8Str(aPath).c_str(),rc);
|
---|
[42673] | 2395 | break;
|
---|
| 2396 | }
|
---|
| 2397 | }
|
---|
| 2398 |
|
---|
| 2399 | return hr;
|
---|
[42084] | 2400 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2401 | }
|
---|
| 2402 |
|
---|
[42090] | 2403 | STDMETHODIMP GuestSession::DirectoryQueryInfo(IN_BSTR aPath, IGuestFsObjInfo **aInfo)
|
---|
[42084] | 2404 | {
|
---|
| 2405 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2406 | ReturnComNotImplemented();
|
---|
| 2407 | #else
|
---|
[42194] | 2408 | LogFlowThisFuncEnter();
|
---|
| 2409 |
|
---|
[42808] | 2410 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
| 2411 | return setError(E_INVALIDARG, tr("No directory to query information for specified"));
|
---|
| 2412 | CheckComArgOutPointerValid(aInfo);
|
---|
| 2413 |
|
---|
[42084] | 2414 | AutoCaller autoCaller(this);
|
---|
| 2415 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2416 |
|
---|
[42808] | 2417 | HRESULT hr = S_OK;
|
---|
| 2418 |
|
---|
[43162] | 2419 | GuestFsObjData objData; int guestRc;
|
---|
| 2420 | int vrc = directoryQueryInfoInternal(Utf8Str(aPath), objData, &guestRc);
|
---|
| 2421 | if (RT_SUCCESS(vrc))
|
---|
[42808] | 2422 | {
|
---|
| 2423 | if (objData.mType == FsObjType_Directory)
|
---|
| 2424 | {
|
---|
| 2425 | ComObjPtr<GuestFsObjInfo> pFsObjInfo;
|
---|
| 2426 | hr = pFsObjInfo.createObject();
|
---|
[43162] | 2427 | if (FAILED(hr)) return hr;
|
---|
[42808] | 2428 |
|
---|
[43162] | 2429 | vrc = pFsObjInfo->init(objData);
|
---|
| 2430 | if (RT_SUCCESS(vrc))
|
---|
| 2431 | {
|
---|
[42808] | 2432 | hr = pFsObjInfo.queryInterfaceTo(aInfo);
|
---|
[43162] | 2433 | if (FAILED(hr)) return hr;
|
---|
| 2434 | }
|
---|
[42808] | 2435 | }
|
---|
| 2436 | }
|
---|
| 2437 |
|
---|
[43162] | 2438 | if (RT_FAILURE(vrc))
|
---|
[42808] | 2439 | {
|
---|
[43162] | 2440 | switch (vrc)
|
---|
[42808] | 2441 | {
|
---|
[45078] | 2442 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[43162] | 2443 | hr = GuestProcess::setErrorExternal(this, guestRc);
|
---|
| 2444 | break;
|
---|
[42808] | 2445 |
|
---|
| 2446 | case VERR_NOT_A_DIRECTORY:
|
---|
[43162] | 2447 | hr = setError(VBOX_E_IPRT_ERROR, tr("Element \"%s\" exists but is not a directory",
|
---|
| 2448 | Utf8Str(aPath).c_str()));
|
---|
[42808] | 2449 | break;
|
---|
| 2450 |
|
---|
| 2451 | default:
|
---|
[43162] | 2452 | hr = setError(VBOX_E_IPRT_ERROR, tr("Querying directory information for \"%s\" failed: %Rrc"),
|
---|
| 2453 | Utf8Str(aPath).c_str(), vrc);
|
---|
[42808] | 2454 | break;
|
---|
| 2455 | }
|
---|
| 2456 | }
|
---|
| 2457 |
|
---|
| 2458 | return hr;
|
---|
[42084] | 2459 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2460 | }
|
---|
| 2461 |
|
---|
[42090] | 2462 | STDMETHODIMP GuestSession::DirectoryRemove(IN_BSTR aPath)
|
---|
[42084] | 2463 | {
|
---|
| 2464 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2465 | ReturnComNotImplemented();
|
---|
| 2466 | #else
|
---|
[42194] | 2467 | LogFlowThisFuncEnter();
|
---|
| 2468 |
|
---|
[42084] | 2469 | AutoCaller autoCaller(this);
|
---|
| 2470 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2471 |
|
---|
| 2472 | ReturnComNotImplemented();
|
---|
| 2473 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2474 | }
|
---|
| 2475 |
|
---|
[42094] | 2476 | STDMETHODIMP GuestSession::DirectoryRemoveRecursive(IN_BSTR aPath, ComSafeArrayIn(DirectoryRemoveRecFlag_T, aFlags), IProgress **aProgress)
|
---|
[42084] | 2477 | {
|
---|
| 2478 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2479 | ReturnComNotImplemented();
|
---|
| 2480 | #else
|
---|
[42194] | 2481 | LogFlowThisFuncEnter();
|
---|
| 2482 |
|
---|
[42084] | 2483 | AutoCaller autoCaller(this);
|
---|
| 2484 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2485 |
|
---|
| 2486 | ReturnComNotImplemented();
|
---|
| 2487 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2488 | }
|
---|
| 2489 |
|
---|
[42094] | 2490 | STDMETHODIMP GuestSession::DirectoryRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
|
---|
[42084] | 2491 | {
|
---|
| 2492 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2493 | ReturnComNotImplemented();
|
---|
| 2494 | #else
|
---|
[42194] | 2495 | LogFlowThisFuncEnter();
|
---|
| 2496 |
|
---|
[42084] | 2497 | AutoCaller autoCaller(this);
|
---|
| 2498 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2499 |
|
---|
| 2500 | ReturnComNotImplemented();
|
---|
| 2501 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2502 | }
|
---|
| 2503 |
|
---|
[42094] | 2504 | STDMETHODIMP GuestSession::DirectorySetACL(IN_BSTR aPath, IN_BSTR aACL)
|
---|
[42084] | 2505 | {
|
---|
| 2506 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2507 | ReturnComNotImplemented();
|
---|
| 2508 | #else
|
---|
[42194] | 2509 | LogFlowThisFuncEnter();
|
---|
| 2510 |
|
---|
[42084] | 2511 | AutoCaller autoCaller(this);
|
---|
| 2512 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2513 |
|
---|
| 2514 | ReturnComNotImplemented();
|
---|
| 2515 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2516 | }
|
---|
| 2517 |
|
---|
| 2518 | STDMETHODIMP GuestSession::EnvironmentClear(void)
|
---|
| 2519 | {
|
---|
| 2520 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2521 | ReturnComNotImplemented();
|
---|
| 2522 | #else
|
---|
[42194] | 2523 | LogFlowThisFuncEnter();
|
---|
| 2524 |
|
---|
[42084] | 2525 | AutoCaller autoCaller(this);
|
---|
| 2526 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2527 |
|
---|
[42171] | 2528 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 2529 |
|
---|
| 2530 | mData.mEnvironment.Clear();
|
---|
| 2531 |
|
---|
[42194] | 2532 | LogFlowFuncLeaveRC(S_OK);
|
---|
[42171] | 2533 | return S_OK;
|
---|
[42084] | 2534 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2535 | }
|
---|
| 2536 |
|
---|
[42194] | 2537 | STDMETHODIMP GuestSession::EnvironmentGet(IN_BSTR aName, BSTR *aValue)
|
---|
| 2538 | {
|
---|
| 2539 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2540 | ReturnComNotImplemented();
|
---|
| 2541 | #else
|
---|
| 2542 | LogFlowThisFuncEnter();
|
---|
| 2543 |
|
---|
| 2544 | if (RT_UNLIKELY((aName) == NULL || *(aName) == '\0'))
|
---|
| 2545 | return setError(E_INVALIDARG, tr("No value name specified"));
|
---|
| 2546 |
|
---|
| 2547 | CheckComArgOutPointerValid(aValue);
|
---|
| 2548 |
|
---|
| 2549 | AutoCaller autoCaller(this);
|
---|
| 2550 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2551 |
|
---|
| 2552 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 2553 |
|
---|
| 2554 | Bstr strValue(mData.mEnvironment.Get(Utf8Str(aName)));
|
---|
| 2555 | strValue.cloneTo(aValue);
|
---|
| 2556 |
|
---|
| 2557 | LogFlowFuncLeaveRC(S_OK);
|
---|
| 2558 | return S_OK;
|
---|
| 2559 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2560 | }
|
---|
| 2561 |
|
---|
[42094] | 2562 | STDMETHODIMP GuestSession::EnvironmentSet(IN_BSTR aName, IN_BSTR aValue)
|
---|
[42084] | 2563 | {
|
---|
| 2564 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2565 | ReturnComNotImplemented();
|
---|
| 2566 | #else
|
---|
[42194] | 2567 | LogFlowThisFuncEnter();
|
---|
| 2568 |
|
---|
| 2569 | if (RT_UNLIKELY((aName) == NULL || *(aName) == '\0'))
|
---|
| 2570 | return setError(E_INVALIDARG, tr("No value name specified"));
|
---|
| 2571 |
|
---|
[42084] | 2572 | AutoCaller autoCaller(this);
|
---|
| 2573 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2574 |
|
---|
[42171] | 2575 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 2576 |
|
---|
[42194] | 2577 | int rc = mData.mEnvironment.Set(Utf8Str(aName), Utf8Str(aValue));
|
---|
[42171] | 2578 |
|
---|
[42194] | 2579 | HRESULT hr = RT_SUCCESS(rc) ? S_OK : VBOX_E_IPRT_ERROR;
|
---|
| 2580 | LogFlowFuncLeaveRC(hr);
|
---|
| 2581 | return hr;
|
---|
[42084] | 2582 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2583 | }
|
---|
| 2584 |
|
---|
[42090] | 2585 | STDMETHODIMP GuestSession::EnvironmentUnset(IN_BSTR aName)
|
---|
[42084] | 2586 | {
|
---|
| 2587 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2588 | ReturnComNotImplemented();
|
---|
| 2589 | #else
|
---|
[42194] | 2590 | LogFlowThisFuncEnter();
|
---|
| 2591 |
|
---|
[42084] | 2592 | AutoCaller autoCaller(this);
|
---|
| 2593 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2594 |
|
---|
[42171] | 2595 | AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 2596 |
|
---|
| 2597 | mData.mEnvironment.Unset(Utf8Str(aName));
|
---|
| 2598 |
|
---|
[42194] | 2599 | LogFlowFuncLeaveRC(S_OK);
|
---|
[42171] | 2600 | return S_OK;
|
---|
[42084] | 2601 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2602 | }
|
---|
| 2603 |
|
---|
[42754] | 2604 | STDMETHODIMP GuestSession::FileCreateTemp(IN_BSTR aTemplate, ULONG aMode, IN_BSTR aPath, BOOL aSecure, IGuestFile **aFile)
|
---|
[42084] | 2605 | {
|
---|
| 2606 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2607 | ReturnComNotImplemented();
|
---|
| 2608 | #else
|
---|
[42194] | 2609 | LogFlowThisFuncEnter();
|
---|
| 2610 |
|
---|
[42084] | 2611 | AutoCaller autoCaller(this);
|
---|
| 2612 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2613 |
|
---|
| 2614 | ReturnComNotImplemented();
|
---|
| 2615 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2616 | }
|
---|
| 2617 |
|
---|
[42090] | 2618 | STDMETHODIMP GuestSession::FileExists(IN_BSTR aPath, BOOL *aExists)
|
---|
[42084] | 2619 | {
|
---|
| 2620 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2621 | ReturnComNotImplemented();
|
---|
| 2622 | #else
|
---|
[42194] | 2623 | LogFlowThisFuncEnter();
|
---|
| 2624 |
|
---|
[42531] | 2625 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
| 2626 | return setError(E_INVALIDARG, tr("No file to check existence for specified"));
|
---|
| 2627 | CheckComArgOutPointerValid(aExists);
|
---|
| 2628 |
|
---|
[42084] | 2629 | AutoCaller autoCaller(this);
|
---|
| 2630 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2631 |
|
---|
[43162] | 2632 | GuestFsObjData objData; int guestRc;
|
---|
| 2633 | int vrc = fileQueryInfoInternal(Utf8Str(aPath), objData, &guestRc);
|
---|
| 2634 | if (RT_SUCCESS(vrc))
|
---|
| 2635 | {
|
---|
| 2636 | *aExists = TRUE;
|
---|
| 2637 | return S_OK;
|
---|
| 2638 | }
|
---|
| 2639 |
|
---|
[42531] | 2640 | HRESULT hr = S_OK;
|
---|
| 2641 |
|
---|
[43162] | 2642 | switch (vrc)
|
---|
[42531] | 2643 | {
|
---|
[45078] | 2644 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[43162] | 2645 | hr = GuestProcess::setErrorExternal(this, guestRc);
|
---|
| 2646 | break;
|
---|
[42531] | 2647 |
|
---|
[43162] | 2648 | case VERR_NOT_A_FILE:
|
---|
| 2649 | *aExists = FALSE;
|
---|
| 2650 | break;
|
---|
| 2651 |
|
---|
| 2652 | default:
|
---|
| 2653 | hr = setError(VBOX_E_IPRT_ERROR, tr("Querying file information for \"%s\" failed: %Rrc"),
|
---|
| 2654 | Utf8Str(aPath).c_str(), vrc);
|
---|
| 2655 | break;
|
---|
[42531] | 2656 | }
|
---|
| 2657 |
|
---|
| 2658 | return hr;
|
---|
[42084] | 2659 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2660 | }
|
---|
| 2661 |
|
---|
[42657] | 2662 | STDMETHODIMP GuestSession::FileRemove(IN_BSTR aPath)
|
---|
[42618] | 2663 | {
|
---|
| 2664 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2665 | ReturnComNotImplemented();
|
---|
| 2666 | #else
|
---|
| 2667 | LogFlowThisFuncEnter();
|
---|
| 2668 |
|
---|
| 2669 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
| 2670 | return setError(E_INVALIDARG, tr("No file to remove specified"));
|
---|
| 2671 |
|
---|
| 2672 | AutoCaller autoCaller(this);
|
---|
| 2673 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2674 |
|
---|
[43162] | 2675 | HRESULT hr = S_OK;
|
---|
| 2676 |
|
---|
| 2677 | int guestRc;
|
---|
| 2678 | int vrc = fileRemoveInternal(Utf8Str(aPath), &guestRc);
|
---|
| 2679 | if (RT_FAILURE(vrc))
|
---|
[42618] | 2680 | {
|
---|
[43162] | 2681 | switch (vrc)
|
---|
| 2682 | {
|
---|
[45078] | 2683 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[43162] | 2684 | hr = GuestProcess::setErrorExternal(this, guestRc);
|
---|
| 2685 | break;
|
---|
| 2686 |
|
---|
| 2687 | default:
|
---|
| 2688 | hr = setError(VBOX_E_IPRT_ERROR, tr("Removing file \"%s\" failed: %Rrc"),
|
---|
| 2689 | Utf8Str(aPath).c_str(), vrc);
|
---|
| 2690 | break;
|
---|
| 2691 | }
|
---|
[42618] | 2692 | }
|
---|
[43162] | 2693 |
|
---|
| 2694 | return hr;
|
---|
[42618] | 2695 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2696 | }
|
---|
| 2697 |
|
---|
[42094] | 2698 | STDMETHODIMP GuestSession::FileOpen(IN_BSTR aPath, IN_BSTR aOpenMode, IN_BSTR aDisposition, ULONG aCreationMode, LONG64 aOffset, IGuestFile **aFile)
|
---|
[42084] | 2699 | {
|
---|
| 2700 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2701 | ReturnComNotImplemented();
|
---|
| 2702 | #else
|
---|
[42194] | 2703 | LogFlowThisFuncEnter();
|
---|
| 2704 |
|
---|
[42611] | 2705 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
| 2706 | return setError(E_INVALIDARG, tr("No file to open specified"));
|
---|
| 2707 | if (RT_UNLIKELY((aOpenMode) == NULL || *(aOpenMode) == '\0'))
|
---|
| 2708 | return setError(E_INVALIDARG, tr("No open mode specified"));
|
---|
| 2709 | if (RT_UNLIKELY((aDisposition) == NULL || *(aDisposition) == '\0'))
|
---|
| 2710 | return setError(E_INVALIDARG, tr("No disposition mode specified"));
|
---|
| 2711 |
|
---|
| 2712 | CheckComArgOutPointerValid(aFile);
|
---|
| 2713 |
|
---|
[42084] | 2714 | AutoCaller autoCaller(this);
|
---|
| 2715 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2716 |
|
---|
[45415] | 2717 | HRESULT hr = isReadyExternal();
|
---|
| 2718 | if (FAILED(hr))
|
---|
| 2719 | return hr;
|
---|
| 2720 |
|
---|
[42611] | 2721 | /** @todo Validate open mode. */
|
---|
| 2722 | /** @todo Validate disposition mode. */
|
---|
| 2723 |
|
---|
| 2724 | /** @todo Validate creation mode. */
|
---|
| 2725 | uint32_t uCreationMode = 0;
|
---|
| 2726 |
|
---|
[44863] | 2727 | GuestFileOpenInfo openInfo;
|
---|
| 2728 | openInfo.mFileName = Utf8Str(aPath);
|
---|
| 2729 | openInfo.mOpenMode = Utf8Str(aOpenMode);
|
---|
| 2730 | openInfo.mDisposition = Utf8Str(aDisposition);
|
---|
| 2731 | openInfo.mCreationMode = aCreationMode;
|
---|
| 2732 | openInfo.mInitialOffset = aOffset;
|
---|
| 2733 |
|
---|
[43162] | 2734 | ComObjPtr <GuestFile> pFile; int guestRc;
|
---|
[44863] | 2735 | int vrc = fileOpenInternal(openInfo, pFile, &guestRc);
|
---|
[43162] | 2736 | if (RT_SUCCESS(vrc))
|
---|
[42611] | 2737 | {
|
---|
| 2738 | /* Return directory object to the caller. */
|
---|
| 2739 | hr = pFile.queryInterfaceTo(aFile);
|
---|
| 2740 | }
|
---|
| 2741 | else
|
---|
| 2742 | {
|
---|
[43162] | 2743 | switch (vrc)
|
---|
[42611] | 2744 | {
|
---|
[45078] | 2745 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[45109] | 2746 | hr = GuestFile::setErrorExternal(this, guestRc);
|
---|
[43162] | 2747 | break;
|
---|
[42611] | 2748 |
|
---|
| 2749 | default:
|
---|
[45109] | 2750 | hr = setError(VBOX_E_IPRT_ERROR, tr("Opening guest file \"%s\" failed: %Rrc"),
|
---|
[43162] | 2751 | Utf8Str(aPath).c_str(), vrc);
|
---|
| 2752 | break;
|
---|
[42611] | 2753 | }
|
---|
| 2754 | }
|
---|
| 2755 |
|
---|
| 2756 | return hr;
|
---|
[42084] | 2757 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2758 | }
|
---|
| 2759 |
|
---|
[42090] | 2760 | STDMETHODIMP GuestSession::FileQueryInfo(IN_BSTR aPath, IGuestFsObjInfo **aInfo)
|
---|
[42084] | 2761 | {
|
---|
| 2762 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2763 | ReturnComNotImplemented();
|
---|
| 2764 | #else
|
---|
[42194] | 2765 | LogFlowThisFuncEnter();
|
---|
| 2766 |
|
---|
[42808] | 2767 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
| 2768 | return setError(E_INVALIDARG, tr("No file to query information for specified"));
|
---|
| 2769 | CheckComArgOutPointerValid(aInfo);
|
---|
| 2770 |
|
---|
[42084] | 2771 | AutoCaller autoCaller(this);
|
---|
| 2772 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2773 |
|
---|
[42808] | 2774 | HRESULT hr = S_OK;
|
---|
| 2775 |
|
---|
[43162] | 2776 | GuestFsObjData objData; int guestRc;
|
---|
| 2777 | int vrc = fileQueryInfoInternal(Utf8Str(aPath), objData, &guestRc);
|
---|
| 2778 | if (RT_SUCCESS(vrc))
|
---|
[42808] | 2779 | {
|
---|
| 2780 | ComObjPtr<GuestFsObjInfo> pFsObjInfo;
|
---|
| 2781 | hr = pFsObjInfo.createObject();
|
---|
[43162] | 2782 | if (FAILED(hr)) return hr;
|
---|
[42808] | 2783 |
|
---|
[43162] | 2784 | vrc = pFsObjInfo->init(objData);
|
---|
| 2785 | if (RT_SUCCESS(vrc))
|
---|
| 2786 | {
|
---|
[42808] | 2787 | hr = pFsObjInfo.queryInterfaceTo(aInfo);
|
---|
[43162] | 2788 | if (FAILED(hr)) return hr;
|
---|
| 2789 | }
|
---|
[42808] | 2790 | }
|
---|
| 2791 |
|
---|
[43162] | 2792 | if (RT_FAILURE(vrc))
|
---|
[42808] | 2793 | {
|
---|
[43162] | 2794 | switch (vrc)
|
---|
[42808] | 2795 | {
|
---|
[45078] | 2796 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[43162] | 2797 | hr = GuestProcess::setErrorExternal(this, guestRc);
|
---|
| 2798 | break;
|
---|
[42808] | 2799 |
|
---|
| 2800 | case VERR_NOT_A_FILE:
|
---|
| 2801 | hr = setError(VBOX_E_IPRT_ERROR, tr("Element exists but is not a file"));
|
---|
| 2802 | break;
|
---|
| 2803 |
|
---|
| 2804 | default:
|
---|
[43162] | 2805 | hr = setError(VBOX_E_IPRT_ERROR, tr("Querying file information failed: %Rrc"), vrc);
|
---|
[42808] | 2806 | break;
|
---|
| 2807 | }
|
---|
| 2808 | }
|
---|
| 2809 |
|
---|
| 2810 | return hr;
|
---|
[42084] | 2811 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2812 | }
|
---|
| 2813 |
|
---|
[42090] | 2814 | STDMETHODIMP GuestSession::FileQuerySize(IN_BSTR aPath, LONG64 *aSize)
|
---|
[42084] | 2815 | {
|
---|
| 2816 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2817 | ReturnComNotImplemented();
|
---|
| 2818 | #else
|
---|
[42194] | 2819 | LogFlowThisFuncEnter();
|
---|
| 2820 |
|
---|
[42530] | 2821 | if (RT_UNLIKELY((aPath) == NULL || *(aPath) == '\0'))
|
---|
| 2822 | return setError(E_INVALIDARG, tr("No file to query size for specified"));
|
---|
| 2823 | CheckComArgOutPointerValid(aSize);
|
---|
| 2824 |
|
---|
[42084] | 2825 | AutoCaller autoCaller(this);
|
---|
| 2826 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2827 |
|
---|
[42530] | 2828 | HRESULT hr = S_OK;
|
---|
| 2829 |
|
---|
[43162] | 2830 | int64_t llSize; int guestRc;
|
---|
| 2831 | int vrc = fileQuerySizeInternal(Utf8Str(aPath), &llSize, &guestRc);
|
---|
| 2832 | if (RT_SUCCESS(vrc))
|
---|
[42530] | 2833 | {
|
---|
| 2834 | *aSize = llSize;
|
---|
| 2835 | }
|
---|
| 2836 | else
|
---|
| 2837 | {
|
---|
[43162] | 2838 | switch (vrc)
|
---|
[42530] | 2839 | {
|
---|
[45078] | 2840 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[43162] | 2841 | hr = GuestProcess::setErrorExternal(this, guestRc);
|
---|
| 2842 | break;
|
---|
[42530] | 2843 |
|
---|
| 2844 | default:
|
---|
[43162] | 2845 | hr = setError(VBOX_E_IPRT_ERROR, tr("Querying file size failed: %Rrc"), vrc);
|
---|
[42530] | 2846 | break;
|
---|
| 2847 | }
|
---|
| 2848 | }
|
---|
| 2849 |
|
---|
| 2850 | return hr;
|
---|
[42084] | 2851 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2852 | }
|
---|
| 2853 |
|
---|
[42094] | 2854 | STDMETHODIMP GuestSession::FileRename(IN_BSTR aSource, IN_BSTR aDest, ComSafeArrayIn(PathRenameFlag_T, aFlags))
|
---|
[42084] | 2855 | {
|
---|
| 2856 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2857 | ReturnComNotImplemented();
|
---|
| 2858 | #else
|
---|
[42194] | 2859 | LogFlowThisFuncEnter();
|
---|
| 2860 |
|
---|
[42084] | 2861 | AutoCaller autoCaller(this);
|
---|
| 2862 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2863 |
|
---|
| 2864 | ReturnComNotImplemented();
|
---|
| 2865 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2866 | }
|
---|
| 2867 |
|
---|
[42094] | 2868 | STDMETHODIMP GuestSession::FileSetACL(IN_BSTR aPath, IN_BSTR aACL)
|
---|
[42084] | 2869 | {
|
---|
| 2870 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2871 | ReturnComNotImplemented();
|
---|
| 2872 | #else
|
---|
[42194] | 2873 | LogFlowThisFuncEnter();
|
---|
| 2874 |
|
---|
[42084] | 2875 | AutoCaller autoCaller(this);
|
---|
| 2876 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2877 |
|
---|
| 2878 | ReturnComNotImplemented();
|
---|
| 2879 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2880 | }
|
---|
| 2881 |
|
---|
[42090] | 2882 | STDMETHODIMP GuestSession::ProcessCreate(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
|
---|
[42105] | 2883 | ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS, IGuestProcess **aProcess)
|
---|
[42084] | 2884 | {
|
---|
| 2885 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2886 | ReturnComNotImplemented();
|
---|
| 2887 | #else
|
---|
[42194] | 2888 | LogFlowThisFuncEnter();
|
---|
[42084] | 2889 |
|
---|
[47469] | 2890 | com::SafeArray<LONG> affinityIgnored;
|
---|
[42105] | 2891 |
|
---|
[43162] | 2892 | return ProcessCreateEx(aCommand, ComSafeArrayInArg(aArguments), ComSafeArrayInArg(aEnvironment),
|
---|
[47469] | 2893 | ComSafeArrayInArg(aFlags), aTimeoutMS, ProcessPriority_Default, ComSafeArrayAsInParam(affinityIgnored), aProcess);
|
---|
[42084] | 2894 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 2895 | }
|
---|
| 2896 |
|
---|
[42090] | 2897 | STDMETHODIMP GuestSession::ProcessCreateEx(IN_BSTR aCommand, ComSafeArrayIn(IN_BSTR, aArguments), ComSafeArrayIn(IN_BSTR, aEnvironment),
|
---|
[42094] | 2898 | ComSafeArrayIn(ProcessCreateFlag_T, aFlags), ULONG aTimeoutMS,
|
---|
| 2899 | ProcessPriority_T aPriority, ComSafeArrayIn(LONG, aAffinity),
|
---|
[42105] | 2900 | IGuestProcess **aProcess)
|
---|
[42084] | 2901 | {
|
---|
| 2902 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 2903 | ReturnComNotImplemented();
|
---|
| 2904 | #else
|
---|
[42194] | 2905 | LogFlowThisFuncEnter();
|
---|
| 2906 |
|
---|
[42214] | 2907 | if (RT_UNLIKELY((aCommand) == NULL || *(aCommand) == '\0'))
|
---|
| 2908 | return setError(E_INVALIDARG, tr("No command to execute specified"));
|
---|
| 2909 | CheckComArgOutPointerValid(aProcess);
|
---|
| 2910 |
|
---|
[42084] | 2911 | AutoCaller autoCaller(this);
|
---|
| 2912 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 2913 |
|
---|
[45415] | 2914 | HRESULT hr = isReadyExternal();
|
---|
| 2915 | if (FAILED(hr))
|
---|
| 2916 | return hr;
|
---|
| 2917 |
|
---|
[42611] | 2918 | GuestProcessStartupInfo procInfo;
|
---|
[42160] | 2919 | procInfo.mCommand = Utf8Str(aCommand);
|
---|
| 2920 |
|
---|
[42272] | 2921 | if (aArguments)
|
---|
| 2922 | {
|
---|
| 2923 | com::SafeArray<IN_BSTR> arguments(ComSafeArrayInArg(aArguments));
|
---|
| 2924 | for (size_t i = 0; i < arguments.size(); i++)
|
---|
[42354] | 2925 | procInfo.mArguments.push_back(Utf8Str(arguments[i]));
|
---|
[42272] | 2926 | }
|
---|
[42111] | 2927 |
|
---|
[42171] | 2928 | int rc = VINF_SUCCESS;
|
---|
| 2929 |
|
---|
[42272] | 2930 | /*
|
---|
| 2931 | * Create the process environment:
|
---|
[42171] | 2932 | * - Apply the session environment in a first step, and
|
---|
| 2933 | * - Apply environment variables specified by this call to
|
---|
| 2934 | * have the chance of overwriting/deleting session entries.
|
---|
| 2935 | */
|
---|
[42272] | 2936 | procInfo.mEnvironment = mData.mEnvironment; /* Apply original session environment. */
|
---|
[42354] | 2937 |
|
---|
| 2938 | if (aEnvironment)
|
---|
[42272] | 2939 | {
|
---|
| 2940 | com::SafeArray<IN_BSTR> environment(ComSafeArrayInArg(aEnvironment));
|
---|
| 2941 | for (size_t i = 0; i < environment.size() && RT_SUCCESS(rc); i++)
|
---|
[42436] | 2942 | rc = procInfo.mEnvironment.Set(Utf8Str(environment[i]));
|
---|
[42272] | 2943 | }
|
---|
[42171] | 2944 |
|
---|
| 2945 | if (RT_SUCCESS(rc))
|
---|
[42160] | 2946 | {
|
---|
[42272] | 2947 | if (aFlags)
|
---|
| 2948 | {
|
---|
| 2949 | com::SafeArray<ProcessCreateFlag_T> flags(ComSafeArrayInArg(aFlags));
|
---|
| 2950 | for (size_t i = 0; i < flags.size(); i++)
|
---|
| 2951 | procInfo.mFlags |= flags[i];
|
---|
| 2952 | }
|
---|
[42160] | 2953 |
|
---|
[42171] | 2954 | procInfo.mTimeoutMS = aTimeoutMS;
|
---|
[42160] | 2955 |
|
---|
[42272] | 2956 | if (aAffinity)
|
---|
| 2957 | {
|
---|
| 2958 | com::SafeArray<LONG> affinity(ComSafeArrayInArg(aAffinity));
|
---|
| 2959 | for (size_t i = 0; i < affinity.size(); i++)
|
---|
[44863] | 2960 | {
|
---|
| 2961 | if (affinity[i])
|
---|
| 2962 | procInfo.mAffinity |= (uint64_t)1 << i;
|
---|
| 2963 | }
|
---|
[42272] | 2964 | }
|
---|
[42160] | 2965 |
|
---|
[42171] | 2966 | procInfo.mPriority = aPriority;
|
---|
[42160] | 2967 |
|
---|
[42354] | 2968 | ComObjPtr<GuestProcess> pProcess;
|
---|
| 2969 | rc = processCreateExInteral(procInfo, pProcess);
|
---|
| 2970 | if (RT_SUCCESS(rc))
|
---|
| 2971 | {
|
---|
| 2972 | /* Return guest session to the caller. */
|
---|
| 2973 | HRESULT hr2 = pProcess.queryInterfaceTo(aProcess);
|
---|
| 2974 | if (FAILED(hr2))
|
---|
| 2975 | rc = VERR_COM_OBJECT_NOT_FOUND;
|
---|
| 2976 |
|
---|
| 2977 | if (RT_SUCCESS(rc))
|
---|
| 2978 | rc = pProcess->startProcessAsync();
|
---|
| 2979 | }
|
---|
[42171] | 2980 | }
|
---|
[42194] | 2981 |
|
---|
[42354] | 2982 | if (RT_FAILURE(rc))
|
---|
| 2983 | {
|
---|
| 2984 | switch (rc)
|
---|
| 2985 | {
|
---|
| 2986 | case VERR_MAX_PROCS_REACHED:
|
---|
[45415] | 2987 | hr = setError(VBOX_E_IPRT_ERROR, tr("Maximum number of concurrent guest processes per session (%ld) reached"),
|
---|
[42897] | 2988 | VBOX_GUESTCTRL_MAX_OBJECTS);
|
---|
[42354] | 2989 | break;
|
---|
| 2990 |
|
---|
| 2991 | /** @todo Add more errors here. */
|
---|
| 2992 |
|
---|
[42436] | 2993 | default:
|
---|
[42354] | 2994 | hr = setError(VBOX_E_IPRT_ERROR, tr("Could not create guest process, rc=%Rrc"), rc);
|
---|
| 2995 | break;
|
---|
| 2996 | }
|
---|
| 2997 | }
|
---|
| 2998 |
|
---|
| 2999 | LogFlowFuncLeaveRC(rc);
|
---|
[42194] | 3000 | return hr;
|
---|
[42084] | 3001 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 3002 | }
|
---|
| 3003 |
|
---|
[42105] | 3004 | STDMETHODIMP GuestSession::ProcessGet(ULONG aPID, IGuestProcess **aProcess)
|
---|
[42084] | 3005 | {
|
---|
| 3006 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 3007 | ReturnComNotImplemented();
|
---|
| 3008 | #else
|
---|
[42214] | 3009 | LogFlowThisFunc(("aPID=%RU32\n", aPID));
|
---|
[42194] | 3010 |
|
---|
[42214] | 3011 | CheckComArgOutPointerValid(aProcess);
|
---|
| 3012 | if (aPID == 0)
|
---|
| 3013 | return setError(E_INVALIDARG, tr("No valid process ID (PID) specified"));
|
---|
| 3014 |
|
---|
[42084] | 3015 | AutoCaller autoCaller(this);
|
---|
| 3016 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 3017 |
|
---|
[42214] | 3018 | AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS);
|
---|
| 3019 |
|
---|
| 3020 | HRESULT hr = S_OK;
|
---|
| 3021 |
|
---|
| 3022 | ComObjPtr<GuestProcess> pProcess;
|
---|
| 3023 | int rc = processGetByPID(aPID, &pProcess);
|
---|
| 3024 | if (RT_FAILURE(rc))
|
---|
| 3025 | hr = setError(E_INVALIDARG, tr("No process with PID %RU32 found"), aPID);
|
---|
| 3026 |
|
---|
| 3027 | /* This will set (*aProcess) to NULL if pProgress is NULL. */
|
---|
| 3028 | HRESULT hr2 = pProcess.queryInterfaceTo(aProcess);
|
---|
| 3029 | if (SUCCEEDED(hr))
|
---|
| 3030 | hr = hr2;
|
---|
| 3031 |
|
---|
[42354] | 3032 | LogFlowThisFunc(("aProcess=%p, hr=%Rhrc\n", *aProcess, hr));
|
---|
[42214] | 3033 | return hr;
|
---|
[42084] | 3034 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 3035 | }
|
---|
| 3036 |
|
---|
[42094] | 3037 | STDMETHODIMP GuestSession::SymlinkCreate(IN_BSTR aSource, IN_BSTR aTarget, SymlinkType_T aType)
|
---|
[42084] | 3038 | {
|
---|
| 3039 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 3040 | ReturnComNotImplemented();
|
---|
| 3041 | #else
|
---|
[42194] | 3042 | LogFlowThisFuncEnter();
|
---|
| 3043 |
|
---|
[42084] | 3044 | AutoCaller autoCaller(this);
|
---|
| 3045 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 3046 |
|
---|
| 3047 | ReturnComNotImplemented();
|
---|
| 3048 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 3049 | }
|
---|
| 3050 |
|
---|
[42090] | 3051 | STDMETHODIMP GuestSession::SymlinkExists(IN_BSTR aSymlink, BOOL *aExists)
|
---|
[42084] | 3052 | {
|
---|
| 3053 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 3054 | ReturnComNotImplemented();
|
---|
| 3055 | #else
|
---|
[42194] | 3056 | LogFlowThisFuncEnter();
|
---|
| 3057 |
|
---|
[42084] | 3058 | AutoCaller autoCaller(this);
|
---|
| 3059 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 3060 |
|
---|
| 3061 | ReturnComNotImplemented();
|
---|
| 3062 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 3063 | }
|
---|
| 3064 |
|
---|
[42094] | 3065 | STDMETHODIMP GuestSession::SymlinkRead(IN_BSTR aSymlink, ComSafeArrayIn(SymlinkReadFlag_T, aFlags), BSTR *aTarget)
|
---|
[42084] | 3066 | {
|
---|
| 3067 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 3068 | ReturnComNotImplemented();
|
---|
| 3069 | #else
|
---|
[42194] | 3070 | LogFlowThisFuncEnter();
|
---|
| 3071 |
|
---|
[42084] | 3072 | AutoCaller autoCaller(this);
|
---|
| 3073 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 3074 |
|
---|
| 3075 | ReturnComNotImplemented();
|
---|
| 3076 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 3077 | }
|
---|
| 3078 |
|
---|
[42090] | 3079 | STDMETHODIMP GuestSession::SymlinkRemoveDirectory(IN_BSTR aPath)
|
---|
[42084] | 3080 | {
|
---|
| 3081 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 3082 | ReturnComNotImplemented();
|
---|
| 3083 | #else
|
---|
[42194] | 3084 | LogFlowThisFuncEnter();
|
---|
| 3085 |
|
---|
[42084] | 3086 | AutoCaller autoCaller(this);
|
---|
| 3087 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 3088 |
|
---|
| 3089 | ReturnComNotImplemented();
|
---|
| 3090 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 3091 | }
|
---|
| 3092 |
|
---|
[42090] | 3093 | STDMETHODIMP GuestSession::SymlinkRemoveFile(IN_BSTR aFile)
|
---|
[42084] | 3094 | {
|
---|
| 3095 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 3096 | ReturnComNotImplemented();
|
---|
| 3097 | #else
|
---|
[42194] | 3098 | LogFlowThisFuncEnter();
|
---|
| 3099 |
|
---|
[42084] | 3100 | AutoCaller autoCaller(this);
|
---|
| 3101 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 3102 |
|
---|
| 3103 | ReturnComNotImplemented();
|
---|
| 3104 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 3105 | }
|
---|
| 3106 |
|
---|
[45010] | 3107 | STDMETHODIMP GuestSession::WaitFor(ULONG aWaitFlags, ULONG aTimeoutMS, GuestSessionWaitResult_T *aReason)
|
---|
| 3108 | {
|
---|
| 3109 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 3110 | ReturnComNotImplemented();
|
---|
| 3111 | #else
|
---|
| 3112 | LogFlowThisFuncEnter();
|
---|
| 3113 |
|
---|
| 3114 | CheckComArgOutPointerValid(aReason);
|
---|
| 3115 |
|
---|
| 3116 | AutoCaller autoCaller(this);
|
---|
| 3117 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 3118 |
|
---|
| 3119 | /*
|
---|
| 3120 | * Note: Do not hold any locks here while waiting!
|
---|
| 3121 | */
|
---|
| 3122 | HRESULT hr = S_OK;
|
---|
| 3123 |
|
---|
| 3124 | int guestRc; GuestSessionWaitResult_T waitResult;
|
---|
| 3125 | int vrc = waitFor(aWaitFlags, aTimeoutMS, waitResult, &guestRc);
|
---|
| 3126 | if (RT_SUCCESS(vrc))
|
---|
| 3127 | {
|
---|
| 3128 | *aReason = waitResult;
|
---|
| 3129 | }
|
---|
| 3130 | else
|
---|
| 3131 | {
|
---|
| 3132 | switch (vrc)
|
---|
| 3133 | {
|
---|
[45078] | 3134 | case VERR_GSTCTL_GUEST_ERROR:
|
---|
[45010] | 3135 | hr = GuestSession::setErrorExternal(this, guestRc);
|
---|
| 3136 | break;
|
---|
| 3137 |
|
---|
| 3138 | case VERR_TIMEOUT:
|
---|
| 3139 | *aReason = GuestSessionWaitResult_Timeout;
|
---|
| 3140 | break;
|
---|
| 3141 |
|
---|
| 3142 | default:
|
---|
| 3143 | {
|
---|
| 3144 | const char *pszSessionName = mData.mSession.mName.c_str();
|
---|
| 3145 | hr = setError(VBOX_E_IPRT_ERROR,
|
---|
| 3146 | tr("Waiting for guest session \"%s\" failed: %Rrc"),
|
---|
| 3147 | pszSessionName ? pszSessionName : tr("Unnamed"), vrc);
|
---|
| 3148 | break;
|
---|
| 3149 | }
|
---|
| 3150 | }
|
---|
| 3151 | }
|
---|
| 3152 |
|
---|
| 3153 | LogFlowFuncLeaveRC(vrc);
|
---|
| 3154 | return hr;
|
---|
| 3155 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 3156 | }
|
---|
| 3157 |
|
---|
| 3158 | STDMETHODIMP GuestSession::WaitForArray(ComSafeArrayIn(GuestSessionWaitForFlag_T, aFlags), ULONG aTimeoutMS, GuestSessionWaitResult_T *aReason)
|
---|
| 3159 | {
|
---|
| 3160 | #ifndef VBOX_WITH_GUEST_CONTROL
|
---|
| 3161 | ReturnComNotImplemented();
|
---|
| 3162 | #else
|
---|
| 3163 | LogFlowThisFuncEnter();
|
---|
| 3164 |
|
---|
| 3165 | CheckComArgOutPointerValid(aReason);
|
---|
| 3166 |
|
---|
| 3167 | AutoCaller autoCaller(this);
|
---|
| 3168 | if (FAILED(autoCaller.rc())) return autoCaller.rc();
|
---|
| 3169 |
|
---|
| 3170 | /*
|
---|
| 3171 | * Note: Do not hold any locks here while waiting!
|
---|
| 3172 | */
|
---|
| 3173 | uint32_t fWaitFor = GuestSessionWaitForFlag_None;
|
---|
| 3174 | com::SafeArray<GuestSessionWaitForFlag_T> flags(ComSafeArrayInArg(aFlags));
|
---|
| 3175 | for (size_t i = 0; i < flags.size(); i++)
|
---|
| 3176 | fWaitFor |= flags[i];
|
---|
| 3177 |
|
---|
| 3178 | return WaitFor(fWaitFor, aTimeoutMS, aReason);
|
---|
| 3179 | #endif /* VBOX_WITH_GUEST_CONTROL */
|
---|
| 3180 | }
|
---|
| 3181 |
|
---|