Changeset 86876 in vbox for trunk/src/VBox/Additions/common
- Timestamp:
- Nov 12, 2020 4:38:00 PM (4 years ago)
- svn:sync-xref-src-repo-rev:
- 141332
- Location:
- trunk/src/VBox/Additions/common
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR3LibGuestProp.cpp
r82968 r86876 38 38 #endif 39 39 #include <iprt/assert.h> 40 #include <iprt/mem.h> 40 41 #include <iprt/stdarg.h> 41 42 #include <VBox/err.h> … … 150 151 151 152 /** 153 * Checks if @a pszPropName exists. 154 * 155 * @returns \c true if the guest property exists, \c false if not. 156 * @param idClient The HGCM client ID for the guest property session. 157 * @param pszPropName The property name. 158 */ 159 VBGLR3DECL(bool) VbglR3GuestPropExist(uint32_t idClient, const char *pszPropName) 160 { 161 return RT_SUCCESS(VbglR3GuestPropReadEx(idClient, pszPropName, NULL /*ppszValue*/, NULL /* ppszFlags */, NULL /* puTimestamp */)); 162 } 163 164 165 /** 152 166 * Write a property value. 153 167 * … … 352 366 353 367 return VINF_SUCCESS; 368 } 369 370 /** 371 * Reads a guest property by returning allocated values. 372 * 373 * @returns VBox status code, fully bitched. 374 * 375 * @param idClient The HGCM client ID for the guest property session. 376 * @param pszPropName The property name. 377 * @param ppszValue Where to return the value. This is always set 378 * to NULL. Needs to be free'd using RTStrFree(). Optional. 379 * @param ppszFlags Where to return the value flags. 380 * Needs to be free'd using RTStrFree(). Optional. 381 * @param puTimestamp Where to return the timestamp. This is only set 382 * on success. Optional. 383 */ 384 VBGLR3DECL(int) VbglR3GuestPropReadEx(uint32_t idClient, 385 const char *pszPropName, char **ppszValue, char **ppszFlags, uint64_t *puTimestamp) 386 { 387 AssertPtrReturn(pszPropName, VERR_INVALID_POINTER); 388 389 uint32_t cbBuf = _1K; 390 void *pvBuf = NULL; 391 int rc = VINF_SUCCESS; /* MSC can't figure out the loop */ 392 393 if (ppszValue) 394 *ppszValue = NULL; 395 396 for (unsigned cTries = 0; cTries < 10; cTries++) 397 { 398 /* 399 * (Re-)Allocate the buffer and try read the property. 400 */ 401 RTMemFree(pvBuf); 402 pvBuf = RTMemAlloc(cbBuf); 403 if (!pvBuf) 404 { 405 rc = VERR_NO_MEMORY; 406 break; 407 } 408 char *pszValue; 409 char *pszFlags; 410 uint64_t uTimestamp; 411 rc = VbglR3GuestPropRead(idClient, pszPropName, pvBuf, cbBuf, &pszValue, &uTimestamp, &pszFlags, NULL); 412 if (RT_FAILURE(rc)) 413 { 414 if (rc == VERR_BUFFER_OVERFLOW) 415 { 416 /* try again with a bigger buffer. */ 417 cbBuf *= 2; 418 continue; 419 } 420 break; 421 } 422 423 if (ppszValue) 424 { 425 *ppszValue = RTStrDup(pszValue); 426 if (!*ppszValue) 427 { 428 rc = VERR_NO_MEMORY; 429 break; 430 } 431 } 432 433 if (puTimestamp) 434 *puTimestamp = uTimestamp; 435 if (ppszFlags) 436 *ppszFlags = RTStrDup(pszFlags); 437 break; /* done */ 438 } 439 440 if (pvBuf) 441 RTMemFree(pvBuf); 442 return rc; 354 443 } 355 444 -
trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp
r86823 r86876 905 905 if (RT_SUCCESS(rc)) 906 906 { 907 rc = V GSvcCheckPropExist(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/DRMResize");907 rc = VbglR3GuestPropExist(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/DRMResize"); 908 908 if (RT_SUCCESS(rc)) 909 909 { -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceTimeSync.cpp
r83974 r86876 210 210 rc = VGSvcReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 211 211 &g_TimeSyncSetThreshold, 0, 7*24*60*60*1000 /* a week */); 212 if ( RT_SUCCESS(rc) 213 || rc == VERR_NOT_FOUND) 214 { 215 rc = VGSvcCheckPropExist(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-start"); 216 if (RT_SUCCESS(rc)) 217 g_fTimeSyncSetOnStart = true; 218 } 219 if ( RT_SUCCESS(rc) 220 || rc == VERR_NOT_FOUND) 221 { 222 rc = VGSvcCheckPropExist(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-no-set-start"); 223 if (RT_SUCCESS(rc)) 224 g_fTimeSyncSetOnStart = false; 225 } 226 if ( RT_SUCCESS(rc) 227 || rc == VERR_NOT_FOUND) 228 { 229 rc = VGSvcCheckPropExist(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-on-restore"); 230 if (RT_SUCCESS(rc)) 231 g_fTimeSyncSetOnRestore = true; 232 } 233 if ( RT_SUCCESS(rc) 234 || rc == VERR_NOT_FOUND) 235 { 236 rc = VGSvcCheckPropExist(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-no-set-on-restore"); 237 if (RT_SUCCESS(rc)) 238 g_fTimeSyncSetOnRestore = false; 239 } 240 if ( RT_SUCCESS(rc) 241 || rc == VERR_NOT_FOUND) 242 { 243 uint32_t uValue; 244 rc = VGSvcReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-verbosity", 245 &uValue, 0 /*uMin*/, 255 /*uMax*/); 246 if (RT_SUCCESS(rc)) 247 g_cTimeSyncVerbosity = uValue; 248 } 212 213 if (VbglR3GuestPropExist(uGuestPropSvcClientID, 214 "/VirtualBox/GuestAdd/VBoxService/--timesync-set-start")) 215 g_fTimeSyncSetOnStart = true; 216 217 if (VbglR3GuestPropExist(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-no-set-start")) 218 g_fTimeSyncSetOnStart = false; 219 220 221 if (VbglR3GuestPropExist(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-on-restore")) 222 g_fTimeSyncSetOnRestore = true; 223 224 if (VbglR3GuestPropExist(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-no-set-on-restore")) 225 g_fTimeSyncSetOnRestore = false; 226 227 uint32_t uValue; 228 rc = VGSvcReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-verbosity", 229 &uValue, 0 /*uMin*/, 255 /*uMax*/); 230 if (RT_SUCCESS(rc)) 231 g_cTimeSyncVerbosity = uValue; 232 249 233 VbglR3GuestPropDisconnect(uGuestPropSvcClientID); 250 234 } -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceUtils.cpp
r82968 r86876 34 34 35 35 #ifdef VBOX_WITH_GUEST_PROPS 36 37 /**38 * Reads a guest property.39 *40 * @returns VBox status code, fully bitched.41 *42 * @param u32ClientId The HGCM client ID for the guest property session.43 * @param pszPropName The property name.44 * @param ppszValue Where to return the value. This is always set45 * to NULL. Free it using RTStrFree(). Optional.46 * @param ppszFlags Where to return the value flags. Free it47 * using RTStrFree(). Optional.48 * @param puTimestamp Where to return the timestamp. This is only set49 * on success. Optional.50 */51 int VGSvcReadProp(uint32_t u32ClientId, const char *pszPropName, char **ppszValue, char **ppszFlags, uint64_t *puTimestamp)52 {53 AssertPtrReturn(pszPropName, VERR_INVALID_POINTER);54 55 uint32_t cbBuf = _1K;56 void *pvBuf = NULL;57 int rc = VINF_SUCCESS; /* MSC can't figure out the loop */58 59 if (ppszValue)60 *ppszValue = NULL;61 62 for (unsigned cTries = 0; cTries < 10; cTries++)63 {64 /*65 * (Re-)Allocate the buffer and try read the property.66 */67 RTMemFree(pvBuf);68 pvBuf = RTMemAlloc(cbBuf);69 if (!pvBuf)70 {71 VGSvcError("Guest Property: Failed to allocate %zu bytes\n", cbBuf);72 rc = VERR_NO_MEMORY;73 break;74 }75 char *pszValue;76 char *pszFlags;77 uint64_t uTimestamp;78 rc = VbglR3GuestPropRead(u32ClientId, pszPropName, pvBuf, cbBuf, &pszValue, &uTimestamp, &pszFlags, NULL);79 if (RT_FAILURE(rc))80 {81 if (rc == VERR_BUFFER_OVERFLOW)82 {83 /* try again with a bigger buffer. */84 cbBuf *= 2;85 continue;86 }87 if (rc == VERR_NOT_FOUND)88 VGSvcVerbose(2, "Guest Property: %s not found\n", pszPropName);89 else90 VGSvcError("Guest Property: Failed to query '%s': %Rrc\n", pszPropName, rc);91 break;92 }93 94 VGSvcVerbose(2, "Guest Property: Read '%s' = '%s', timestamp %RU64n\n", pszPropName, pszValue, uTimestamp);95 if (ppszValue)96 {97 *ppszValue = RTStrDup(pszValue);98 if (!*ppszValue)99 {100 VGSvcError("Guest Property: RTStrDup failed for '%s'\n", pszValue);101 rc = VERR_NO_MEMORY;102 break;103 }104 }105 106 if (puTimestamp)107 *puTimestamp = uTimestamp;108 if (ppszFlags)109 *ppszFlags = RTStrDup(pszFlags);110 break; /* done */111 }112 113 if (pvBuf)114 RTMemFree(pvBuf);115 return rc;116 }117 118 119 36 /** 120 37 * Reads a guest property as a 32-bit value. … … 130 47 { 131 48 char *pszValue; 132 int rc = V GSvcReadProp(u32ClientId, pszPropName, &pszValue, NULL /* ppszFlags */, NULL /* puTimestamp */);49 int rc = VbglR3GuestPropReadEx(u32ClientId, pszPropName, &pszValue, NULL /* ppszFlags */, NULL /* puTimestamp */); 133 50 if (RT_SUCCESS(rc)) 134 51 { … … 143 60 return rc; 144 61 } 145 146 /**147 * Checks if @a pszPropName exists.148 *149 * @returns VBox status code.150 * @retval VINF_SUCCESS if it exists.151 * @retval VERR_NOT_FOUND if not found.152 *153 * @param u32ClientId The HGCM client ID for the guest property session.154 * @param pszPropName The property name.155 */156 int VGSvcCheckPropExist(uint32_t u32ClientId, const char *pszPropName)157 {158 return VGSvcReadProp(u32ClientId, pszPropName, NULL /*ppszValue*/, NULL /* ppszFlags */, NULL /* puTimestamp */);159 }160 161 62 162 63 /** … … 183 84 char *pszValue = NULL; 184 85 char *pszFlags = NULL; 185 int rc = V GSvcReadProp(u32ClientId, pszPropName, &pszValue, &pszFlags, puTimestamp);86 int rc = VbglR3GuestPropReadEx(u32ClientId, pszPropName, &pszValue, &pszFlags, puTimestamp); 186 87 if (RT_SUCCESS(rc)) 187 88 { -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceUtils.h
r82968 r86876 27 27 int VGSvcReadProp(uint32_t u32ClientId, const char *pszPropName, char **ppszValue, char **ppszFlags, uint64_t *puTimestamp); 28 28 int VGSvcReadPropUInt32(uint32_t u32ClientId, const char *pszPropName, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max); 29 int VGSvcCheckPropExist(uint32_t u32ClientId, const char *pszPropName);30 29 int VGSvcReadHostProp(uint32_t u32ClientId, const char *pszPropName, bool fReadOnly, char **ppszValue, char **ppszFlags, 31 30 uint64_t *puTimestamp);
Note:
See TracChangeset
for help on using the changeset viewer.