Changeset 80873 in vbox
- Timestamp:
- Sep 17, 2019 11:55:26 PM (5 years ago)
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/GuestCtrlImplPrivate.h
r80828 r80873 195 195 * 196 196 * @returns IPRT status code. 197 * @param rArray The array with the putenv style strings. 198 * @sa RTEnvPutEnvEx 199 */ 200 int applyPutEnvArray(const std::vector<com::Utf8Str> &rArray) 201 { 202 size_t cArray = rArray.size(); 197 * @param rArray The array with the putenv style strings. 198 * @param pidxError Where to return the index causing trouble on 199 * failure. Optional. 200 * @sa RTEnvPutEx 201 */ 202 int applyPutEnvArray(const std::vector<com::Utf8Str> &rArray, size_t *pidxError = NULL) 203 { 204 size_t const cArray = rArray.size(); 203 205 for (size_t i = 0; i < cArray; i++) 204 206 { 205 207 int rc = RTEnvPutEx(m_hEnv, rArray[i].c_str()); 206 208 if (RT_FAILURE(rc)) 209 { 210 if (pidxError) 211 *pidxError = i; 207 212 return rc; 213 } 208 214 } 209 215 return VINF_SUCCESS; -
trunk/src/VBox/Main/src-client/GuestSessionImpl.cpp
r80828 r80873 437 437 LogFlowThisFuncEnter(); 438 438 439 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 440 441 int vrc = mData.mEnvironmentChanges.queryPutEnvArray(&aEnvironmentChanges); 439 int vrc; 440 { 441 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 442 vrc = mData.mEnvironmentChanges.queryPutEnvArray(&aEnvironmentChanges); 443 } 442 444 443 445 LogFlowFuncLeaveRC(vrc); … … 449 451 LogFlowThisFuncEnter(); 450 452 451 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 452 453 mData.mEnvironmentChanges.reset(); 454 int vrc = mData.mEnvironmentChanges.applyPutEnvArray(aEnvironmentChanges); 453 int vrc; 454 size_t idxError = ~(size_t)0; 455 { 456 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 457 mData.mEnvironmentChanges.reset(); 458 vrc = mData.mEnvironmentChanges.applyPutEnvArray(aEnvironmentChanges, &idxError); 459 } 455 460 456 461 LogFlowFuncLeaveRC(vrc); 457 return Global::vboxStatusCodeToCOM(vrc); 462 if (RT_SUCCESS(vrc)) 463 return S_OK; 464 if (vrc == VERR_ENV_INVALID_VAR_NAME) 465 return setError(E_INVALIDARG, tr("Invalid environment variable name '%s', index %zu"), 466 aEnvironmentChanges[idxError].c_str(), idxError); 467 return setErrorBoth(Global::vboxStatusCodeToCOM(vrc), vrc, tr("Failed to apply '%s', index %zu (%Rrc)"), 468 aEnvironmentChanges[idxError].c_str(), idxError, vrc); 458 469 } 459 470 … … 486 497 aProcesses.resize(mData.mProcesses.size()); 487 498 size_t i = 0; 488 for (SessionProcesses::iterator it = mData.mProcesses.begin();489 it != mData.mProcesses.end();490 ++it, ++i)499 for (SessionProcesses::iterator it = mData.mProcesses.begin(); 500 it != mData.mProcesses.end(); 501 ++it, ++i) 491 502 { 492 503 it->second.queryInterfaceTo(aProcesses[i].asOutParam()); … … 3601 3612 HRESULT GuestSession::environmentScheduleSet(const com::Utf8Str &aName, const com::Utf8Str &aValue) 3602 3613 { 3603 AutoCaller autoCaller(this); 3604 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 3605 3614 LogFlowThisFuncEnter(); 3615 int vrc; 3616 { 3617 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3618 vrc = mData.mEnvironmentChanges.setVariable(aName, aValue); 3619 } 3606 3620 HRESULT hrc; 3607 if (RT_LIKELY(aName.isNotEmpty())) 3608 { 3609 if (RT_LIKELY(strchr(aName.c_str(), '=') == NULL)) 3610 { 3611 LogFlowThisFuncEnter(); 3612 3613 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3614 int vrc = mData.mEnvironmentChanges.setVariable(aName, aValue); 3615 if (RT_SUCCESS(vrc)) 3616 hrc = S_OK; 3617 else 3618 hrc = setErrorVrc(vrc); 3619 } 3620 else 3621 hrc = setError(E_INVALIDARG, tr("The equal char is not allowed in environment variable names")); 3622 } 3621 if (RT_SUCCESS(vrc)) 3622 hrc = S_OK; 3623 else if (vrc == VERR_ENV_INVALID_VAR_NAME) 3624 hrc = setError(E_INVALIDARG, tr("Invalid environment variable name '%s'"), aName.c_str()); 3623 3625 else 3624 hrc = setError (E_INVALIDARG, tr("No variable name specified"));3626 hrc = setErrorVrc(vrc, tr("Failed to schedule setting environment variable '%s' to '%s'"), aName.c_str(), aValue.c_str()); 3625 3627 3626 3628 LogFlowThisFuncLeave(); … … 3630 3632 HRESULT GuestSession::environmentScheduleUnset(const com::Utf8Str &aName) 3631 3633 { 3632 AutoCaller autoCaller(this); 3633 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 3634 3634 LogFlowThisFuncEnter(); 3635 int vrc; 3636 { 3637 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3638 vrc = mData.mEnvironmentChanges.unsetVariable(aName); 3639 } 3635 3640 HRESULT hrc; 3636 if (RT_LIKELY(aName.isNotEmpty())) 3637 { 3638 if (RT_LIKELY(strchr(aName.c_str(), '=') == NULL)) 3639 { 3640 LogFlowThisFuncEnter(); 3641 3642 AutoWriteLock alock(this COMMA_LOCKVAL_SRC_POS); 3643 int vrc = mData.mEnvironmentChanges.unsetVariable(aName); 3644 if (RT_SUCCESS(vrc)) 3645 hrc = S_OK; 3646 else 3647 hrc = setErrorVrc(vrc); 3648 } 3649 else 3650 hrc = setError(E_INVALIDARG, tr("The equal char is not allowed in environment variable names")); 3651 } 3641 if (RT_SUCCESS(vrc)) 3642 hrc = S_OK; 3643 else if (vrc == VERR_ENV_INVALID_VAR_NAME) 3644 hrc = setError(E_INVALIDARG, tr("Invalid environment variable name '%s'"), aName.c_str()); 3652 3645 else 3653 hrc = setError (E_INVALIDARG, tr("No variable name specified"));3646 hrc = setErrorVrc(vrc, tr("Failed to schedule unsetting environment variable '%s'"), aName.c_str()); 3654 3647 3655 3648 LogFlowThisFuncLeave(); … … 3659 3652 HRESULT GuestSession::environmentGetBaseVariable(const com::Utf8Str &aName, com::Utf8Str &aValue) 3660 3653 { 3661 AutoCaller autoCaller(this);3662 if (FAILED(autoCaller.rc())) return autoCaller.rc();3654 LogFlowThisFuncEnter(); 3655 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 3663 3656 3664 3657 HRESULT hrc; 3665 if (RT_LIKELY(aName.isNotEmpty())) 3666 { 3667 if (RT_LIKELY(strchr(aName.c_str(), '=') == NULL)) 3668 { 3669 LogFlowThisFuncEnter(); 3670 3671 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 3672 if (mData.mpBaseEnvironment) 3673 { 3674 int vrc = mData.mpBaseEnvironment->getVariable(aName, &aValue); 3675 if (RT_SUCCESS(vrc)) 3676 hrc = S_OK; 3677 else 3678 hrc = setErrorVrc(vrc); 3679 } 3680 else if (mData.mProtocolVersion < 99999) 3681 hrc = setError(VBOX_E_NOT_SUPPORTED, tr("The base environment feature is not supported by the guest additions")); 3682 else 3683 hrc = setError(VBOX_E_INVALID_OBJECT_STATE, tr("The base environment has not yet been reported by the guest")); 3684 } 3658 if (mData.mpBaseEnvironment) 3659 { 3660 int vrc = mData.mpBaseEnvironment->getVariable(aName, &aValue); 3661 if (RT_SUCCESS(vrc)) 3662 hrc = S_OK; 3663 else if (vrc == VERR_ENV_INVALID_VAR_NAME) 3664 hrc = setError(E_INVALIDARG, tr("Invalid environment variable name '%s'"), aName.c_str()); 3685 3665 else 3686 hrc = setError(E_INVALIDARG, tr("The equal char is not allowed in environment variable names")); 3687 } 3666 hrc = setErrorVrc(vrc); 3667 } 3668 else if (mData.mProtocolVersion < 99999) 3669 hrc = setError(VBOX_E_NOT_SUPPORTED, tr("The base environment feature is not supported by the guest additions")); 3688 3670 else 3689 hrc = setError( E_INVALIDARG, tr("No variable name specified"));3671 hrc = setError(VBOX_E_INVALID_OBJECT_STATE, tr("The base environment has not yet been reported by the guest")); 3690 3672 3691 3673 LogFlowThisFuncLeave(); … … 3695 3677 HRESULT GuestSession::environmentDoesBaseVariableExist(const com::Utf8Str &aName, BOOL *aExists) 3696 3678 { 3697 AutoCaller autoCaller(this); 3698 if (FAILED(autoCaller.rc())) return autoCaller.rc(); 3699 3679 LogFlowThisFuncEnter(); 3700 3680 *aExists = FALSE; 3681 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 3701 3682 3702 3683 HRESULT hrc; 3703 if (RT_LIKELY(aName.isNotEmpty())) 3704 { 3705 if (RT_LIKELY(strchr(aName.c_str(), '=') == NULL)) 3706 { 3707 LogFlowThisFuncEnter(); 3708 3709 AutoReadLock alock(this COMMA_LOCKVAL_SRC_POS); 3710 if (mData.mpBaseEnvironment) 3711 { 3712 hrc = S_OK; 3713 *aExists = mData.mpBaseEnvironment->doesVariableExist(aName); 3714 } 3715 else if (mData.mProtocolVersion < 99999) 3716 hrc = setError(VBOX_E_NOT_SUPPORTED, tr("The base environment feature is not supported by the guest additions")); 3717 else 3718 hrc = setError(VBOX_E_INVALID_OBJECT_STATE, tr("The base environment has not yet been reported by the guest")); 3719 } 3720 else 3721 hrc = setError(E_INVALIDARG, tr("The equal char is not allowed in environment variable names")); 3722 } 3684 if (mData.mpBaseEnvironment) 3685 { 3686 hrc = S_OK; 3687 *aExists = mData.mpBaseEnvironment->doesVariableExist(aName); 3688 } 3689 else if (mData.mProtocolVersion < 99999) 3690 hrc = setError(VBOX_E_NOT_SUPPORTED, tr("The base environment feature is not supported by the guest additions")); 3723 3691 else 3724 hrc = setError( E_INVALIDARG, tr("No variable name specified"));3692 hrc = setError(VBOX_E_INVALID_OBJECT_STATE, tr("The base environment has not yet been reported by the guest")); 3725 3693 3726 3694 LogFlowThisFuncLeave(); … … 4212 4180 int vrc = procInfo.mEnvironmentChanges.copy(mData.mEnvironmentChanges); 4213 4181 if (RT_SUCCESS(vrc)) 4214 vrc = procInfo.mEnvironmentChanges.applyPutEnvArray(aEnvironment); 4215 if (RT_SUCCESS(vrc)) 4216 { 4217 /* Convert the flag array into a mask. */ 4218 if (aFlags.size()) 4219 for (size_t i = 0; i < aFlags.size(); i++) 4220 procInfo.mFlags |= aFlags[i]; 4221 4222 procInfo.mTimeoutMS = aTimeoutMS; 4223 4224 /** @todo use RTCPUSET instead of archaic 64-bit variables! */ 4225 if (aAffinity.size()) 4226 for (size_t i = 0; i < aAffinity.size(); i++) 4227 if (aAffinity[i]) 4228 procInfo.mAffinity |= (uint64_t)1 << i; 4229 4230 procInfo.mPriority = aPriority; 4231 4232 /* 4233 * Create a guest process object. 4234 */ 4235 ComObjPtr<GuestProcess> pProcess; 4236 vrc = i_processCreateEx(procInfo, pProcess); 4182 { 4183 size_t idxError = ~(size_t)0; 4184 vrc = procInfo.mEnvironmentChanges.applyPutEnvArray(aEnvironment, &idxError); 4237 4185 if (RT_SUCCESS(vrc)) 4238 4186 { 4239 ComPtr<IGuestProcess> pIProcess; 4240 hr = pProcess.queryInterfaceTo(pIProcess.asOutParam()); 4241 if (SUCCEEDED(hr)) 4187 /* Convert the flag array into a mask. */ 4188 if (aFlags.size()) 4189 for (size_t i = 0; i < aFlags.size(); i++) 4190 procInfo.mFlags |= aFlags[i]; 4191 4192 procInfo.mTimeoutMS = aTimeoutMS; 4193 4194 /** @todo use RTCPUSET instead of archaic 64-bit variables! */ 4195 if (aAffinity.size()) 4196 for (size_t i = 0; i < aAffinity.size(); i++) 4197 if (aAffinity[i]) 4198 procInfo.mAffinity |= (uint64_t)1 << i; 4199 4200 procInfo.mPriority = aPriority; 4201 4202 /* 4203 * Create a guest process object. 4204 */ 4205 ComObjPtr<GuestProcess> pProcess; 4206 vrc = i_processCreateEx(procInfo, pProcess); 4207 if (RT_SUCCESS(vrc)) 4242 4208 { 4243 /* 4244 * Start the process. 4245 */ 4246 vrc = pProcess->i_startProcessAsync(); 4247 if (RT_SUCCESS(vrc)) 4209 ComPtr<IGuestProcess> pIProcess; 4210 hr = pProcess.queryInterfaceTo(pIProcess.asOutParam()); 4211 if (SUCCEEDED(hr)) 4248 4212 { 4249 aGuestProcess = pIProcess; 4250 4251 LogFlowFuncLeaveRC(vrc); 4252 return S_OK; 4213 /* 4214 * Start the process. 4215 */ 4216 vrc = pProcess->i_startProcessAsync(); 4217 if (RT_SUCCESS(vrc)) 4218 { 4219 aGuestProcess = pIProcess; 4220 4221 LogFlowFuncLeaveRC(vrc); 4222 return S_OK; 4223 } 4224 4225 hr = setErrorVrc(vrc, tr("Failed to start guest process: %Rrc"), vrc); 4253 4226 } 4254 4255 hr = setErrorVrc(vrc, tr("Failed to start guest process: %Rrc"), vrc);4256 4227 } 4257 } 4258 else if (vrc == VERR_GSTCTL_MAX_CID_OBJECTS_REACHED) 4259 hr = setErrorVrc(vrc, tr("Maximum number of concurrent guest processes per session (%u) reached"), 4260 VBOX_GUESTCTRL_MAX_OBJECTS); 4228 else if (vrc == VERR_GSTCTL_MAX_CID_OBJECTS_REACHED) 4229 hr = setErrorVrc(vrc, tr("Maximum number of concurrent guest processes per session (%u) reached"), 4230 VBOX_GUESTCTRL_MAX_OBJECTS); 4231 else 4232 hr = setErrorVrc(vrc, tr("Failed to create guest process object: %Rrc"), vrc); 4233 } 4261 4234 else 4262 hr = setErrorVrc(vrc, tr("Failed to create guest process object: %Rrc"), vrc); 4235 hr = setErrorBoth(vrc == VERR_ENV_INVALID_VAR_NAME ? E_INVALIDARG : Global::vboxStatusCodeToCOM(vrc), vrc, 4236 tr("Failed to apply environment variable '%s', index %u (%Rrc)'"), 4237 aEnvironment[idxError].c_str(), idxError, vrc); 4263 4238 } 4264 4239 else
Note:
See TracChangeset
for help on using the changeset viewer.