Changeset 25390 in vbox
- Timestamp:
- Dec 15, 2009 11:16:26 AM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 56015
- Location:
- trunk/src/VBox/Additions/common/VBoxService
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxService.cpp
r25159 r25390 382 382 { 383 383 int rc = VINF_SUCCESS; 384 385 384 /* 386 385 * Init globals and such. 387 386 */ 388 387 RTR3Init(); 388 389 /* 390 * Connect to the kernel part before daemonizing so we can fail 391 * and complain if there is some kind of problem. We need to initialize 392 * the guest lib *before* we do the pre-init just in case one of services 393 * needs do to some initial stuff with it. 394 */ 395 VBoxServiceVerbose(2, "Calling VbgR3Init()\n"); 396 rc = VbglR3Init(); 397 if (RT_FAILURE(rc)) 398 return VBoxServiceError("VbglR3Init failed with rc=%Rrc.\n", rc); 399 400 /* Do pre-init of services. */ 389 401 g_pszProgName = RTPathFilename(argv[0]); 390 402 for (unsigned j = 0; j < RT_ELEMENTS(g_aServices); j++) … … 537 549 if (iMain == ~0U) 538 550 return VBoxServiceSyntax("At least one service must be enabled.\n"); 539 540 /*541 * Connect to the kernel part before daemonizing so we can fail542 * and complain if there is some kind of problem.543 */544 VBoxServiceVerbose(2, "Calling VbgR3Init()\n");545 rc = VbglR3Init();546 if (RT_FAILURE(rc))547 return VBoxServiceError("VbglR3Init failed with rc=%Rrc.\n", rc);548 551 549 552 VBoxServiceVerbose(0, "Started. Verbose level = %d\n", g_cVerbosity); -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceExec.cpp
r25159 r25390 134 134 static int VBoxServiceExecReadHostProp(const char *pszPropName, char **ppszValue, uint64_t *puTimestamp) 135 135 { 136 size_t cbBuf = _1K; 137 void *pvBuf = NULL; 138 int rc; 139 140 *ppszValue = NULL; 141 142 for (unsigned cTries = 0; cTries < 10; cTries++) 136 char *pszFlags, *pszValue; 137 uint64_t uTimestamp; 138 int rc = VBoxServiceReadProp(g_uExecGuestPropSvcClientID, pszPropName, ppszValue, &pszFlags, puTimestamp); 139 if (RT_SUCCESS(rc)) 143 140 { 144 /*145 * (Re-)Allocate the buffer and try read the property.146 */147 RTMemFree(pvBuf);148 pvBuf = RTMemAlloc(cbBuf);149 if (!pvBuf)150 {151 VBoxServiceError("Exec: Failed to allocate %zu bytes\n", cbBuf);152 rc = VERR_NO_MEMORY;153 break;154 }155 char *pszValue;156 char *pszFlags;157 uint64_t uTimestamp;158 rc = VbglR3GuestPropRead(g_uExecGuestPropSvcClientID, pszPropName,159 pvBuf, cbBuf,160 &pszValue, &uTimestamp, &pszFlags, NULL);161 if (RT_FAILURE(rc))162 {163 if (rc == VERR_BUFFER_OVERFLOW)164 {165 /* try again with a bigger buffer. */166 cbBuf *= 2;167 continue;168 }169 if (rc == VERR_NOT_FOUND)170 VBoxServiceVerbose(2, "Exec: %s not found\n", pszPropName);171 else172 VBoxServiceError("Exec: Failed to query \"%s\": %Rrc\n", pszPropName, rc);173 break;174 }175 176 141 /* 177 142 * Validate it and set return values on success. … … 184 149 VBoxServiceError("Exec: Flag validation failed for \"%s\": %Rrc; flags=\"%s\"\n", 185 150 pszPropName, rc, pszFlags); 186 break;187 151 } 188 VBoxServiceVerbose(2, "Exec: Read \"%s\" = \"%s\", timestamp %RU64n\n", 189 pszPropName, pszValue, uTimestamp); 190 *ppszValue = RTStrDup(pszValue); 191 if (!*ppszValue) 152 else 192 153 { 193 VBoxServiceError("Exec: RTStrDup failed for \"%s\"\n", pszValue); 194 rc = VERR_NO_MEMORY; 195 break; 154 VBoxServiceVerbose(2, "Exec: Read \"%s\" = \"%s\", timestamp %RU64n\n", 155 pszPropName, pszValue, uTimestamp); 156 *ppszValue = RTStrDup(pszValue); 157 if (!*ppszValue) 158 { 159 VBoxServiceError("Exec: RTStrDup failed for \"%s\"\n", pszValue); 160 rc = VERR_NO_MEMORY; 161 } 162 if (puTimestamp) 163 *puTimestamp = uTimestamp; 196 164 } 197 198 if (puTimestamp) 199 *puTimestamp = uTimestamp; 200 break; /* done */ 165 RTStrFree(pszFlags); 201 166 } 202 203 RTMemFree(pvBuf);204 167 return rc; 205 168 } -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceTimeSync.cpp
r25159 r25390 101 101 #include <VBox/VBoxGuestLib.h> 102 102 #include "VBoxServiceInternal.h" 103 #include "VBoxServiceUtils.h" 103 104 104 105 … … 151 152 static DECLCALLBACK(int) VBoxServiceTimeSyncPreInit(void) 152 153 { 154 #ifdef VBOX_WITH_GUEST_PROPS 155 /** @todo Merge this function with VBoxServiceTimeSyncOption() to generalize 156 * the "command line args override guest property values" behavior. 157 158 /* 159 * Read the service options from the VM's guest properties. 160 * Note that these options can be overriden by the command line options later. 161 */ 162 uint32_t uGuestPropSvcClientID; 163 int rc = VbglR3GuestPropConnect(&uGuestPropSvcClientID); 164 if (RT_FAILURE(rc)) 165 { 166 VBoxServiceError("Failed to connect to the guest property service! Error: %Rrc\n", rc); 167 } 168 else 169 { 170 rc = VBoxServiceReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-interval", 171 &g_TimeSyncInterval, 1, UINT32_MAX - 1); 172 if ( RT_SUCCESS(rc) 173 || rc == VERR_NOT_FOUND) 174 { 175 rc = VBoxServiceReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-min-adjust", 176 &g_TimeSyncMinAdjust, 0, 3600000); 177 } 178 if ( RT_SUCCESS(rc) 179 || rc == VERR_NOT_FOUND) 180 { 181 rc = VBoxServiceReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-latency-factor", 182 &g_TimeSyncLatencyFactor, 1, 1024); 183 } 184 if ( RT_SUCCESS(rc) 185 || rc == VERR_NOT_FOUND) 186 { 187 rc = VBoxServiceReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-max-latency", 188 &g_TimeSyncMaxLatency, 1, 3600000); 189 } 190 if ( RT_SUCCESS(rc) 191 || rc == VERR_NOT_FOUND) 192 { 193 rc = VBoxServiceReadPropUInt32(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-threshold", 194 &g_TimeSyncSetThreshold, 0, 7*24*60*1000 /* a week */); 195 } 196 if ( RT_SUCCESS(rc) 197 || rc == VERR_NOT_FOUND) 198 { 199 char *pszValue; 200 rc = VBoxServiceReadProp(uGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--timesync-set-start", 201 &pszValue, NULL /* ppszFlags */, NULL /* puTimestamp */); 202 if (RT_SUCCESS(rc)) 203 { 204 g_fTimeSyncSetNext = true; 205 RTStrFree(pszValue); 206 } 207 } 208 209 VbglR3GuestPropDisconnect(uGuestPropSvcClientID); 210 } 211 212 if (rc == VERR_NOT_FOUND) /* If a value is not found, don't be sad! */ 213 rc = VINF_SUCCESS; 214 return rc; 215 #else 216 /* Nothing to do here yet. */ 153 217 return VINF_SUCCESS; 218 #endif 154 219 } 155 220 -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceUtils.cpp
r24866 r25390 37 37 38 38 #ifdef VBOX_WITH_GUEST_PROPS 39 /** 40 * Reads a guest property. 41 * 42 * @returns VBox status code, fully bitched. 43 * 44 * @param u32ClientId The HGCM client ID for the guest property session. 45 * @param pszPropName The property name. 46 * @param ppszValue Where to return the value. This is always set 47 * to NULL. Free it using RTStrFree(). 48 * @param ppszFlags Where to return the value flags. Free it 49 * using RTStrFree(). Optional. 50 * @param puTimestamp Where to return the timestamp. This is only set 51 * on success. Optional. 52 */ 53 int VBoxServiceReadProp(uint32_t u32ClientId, const char *pszPropName, char **ppszValue, char **ppszFlags, uint64_t *puTimestamp) 54 { 55 size_t cbBuf = _1K; 56 void *pvBuf = NULL; 57 int rc; 58 59 *ppszValue = NULL; 60 61 for (unsigned cTries = 0; cTries < 10; cTries++) 62 { 63 /* 64 * (Re-)Allocate the buffer and try read the property. 65 */ 66 RTMemFree(pvBuf); 67 pvBuf = RTMemAlloc(cbBuf); 68 if (!pvBuf) 69 { 70 VBoxServiceError("Guest Property: Failed to allocate %zu bytes\n", cbBuf); 71 rc = VERR_NO_MEMORY; 72 break; 73 } 74 char *pszValue; 75 char *pszFlags; 76 uint64_t uTimestamp; 77 rc = VbglR3GuestPropRead(u32ClientId, pszPropName, 78 pvBuf, cbBuf, 79 &pszValue, &uTimestamp, &pszFlags, NULL); 80 if (RT_FAILURE(rc)) 81 { 82 if (rc == VERR_BUFFER_OVERFLOW) 83 { 84 /* try again with a bigger buffer. */ 85 cbBuf *= 2; 86 continue; 87 } 88 if (rc == VERR_NOT_FOUND) 89 VBoxServiceVerbose(2, "Guest Property: %s not found\n", pszPropName); 90 else 91 VBoxServiceError("Guest Property: Failed to query \"%s\": %Rrc\n", pszPropName, rc); 92 break; 93 } 94 95 VBoxServiceVerbose(2, "Guest Property: Read \"%s\" = \"%s\", timestamp %RU64n\n", 96 pszPropName, pszValue, uTimestamp); 97 *ppszValue = RTStrDup(pszValue); 98 if (!*ppszValue) 99 { 100 VBoxServiceError("Guest Property: RTStrDup failed for \"%s\"\n", pszValue); 101 rc = VERR_NO_MEMORY; 102 break; 103 } 104 105 if (puTimestamp) 106 *puTimestamp = uTimestamp; 107 if (ppszFlags) 108 *ppszFlags = RTStrDup(pszFlags); 109 break; /* done */ 110 } 111 112 RTMemFree(pvBuf); 113 return rc; 114 } 115 116 117 /** 118 * Reads a guest property as a 32-bit value. 119 * 120 * @returns VBox status code, fully bitched. 121 * 122 * @param u32ClientId The HGCM client ID for the guest property session. 123 * @param pszPropName The property name. 124 * @param pu32 Where to store the 32-bit value. 125 * 126 */ 127 int VBoxServiceReadPropUInt32(uint32_t u32ClientId, const char *pszPropName, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max) 128 { 129 char *pszValue; 130 int rc = VBoxServiceReadProp(u32ClientId, pszPropName, &pszValue, 131 NULL /* ppszFlags */, NULL /* puTimestamp */); 132 if (RT_SUCCESS(rc)) 133 { 134 AssertPtr(pu32); 135 char *pszNext; 136 rc = RTStrToUInt32Ex(pszValue, &pszNext, 0, pu32); 137 if ( RT_SUCCESS(rc) 138 && (*pu32 < u32Min || *pu32 > u32Max)) 139 { 140 VBoxServiceError("The guest property value %s = %RU32 is out of range [%RU32..%RU32].\n", 141 pszPropName, *pu32, u32Min, u32Max); 142 } 143 RTStrFree(pszValue); 144 } 145 return rc; 146 } 147 148 39 149 /** 40 150 * Wrapper around VbglR3GuestPropWriteValue that does value formatting and -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceUtils.h
r23575 r25390 26 26 27 27 #ifdef VBOX_WITH_GUEST_PROPS 28 /** Reads a guest property. */ 29 int VBoxServiceReadProp(uint32_t u32ClientId, const char *pszPropName, char **ppszValue, char **ppszFlags, uint64_t *puTimestamp); 30 /** Reads a guest property as a 32-bit value. */ 31 int VBoxServiceReadPropUInt32(uint32_t u32ClientId, const char *pszPropName, uint32_t *pu32, uint32_t u32Min, uint32_t u32Max); 32 /** Wrapper around VbglR3GuestPropWriteValue that does value formatting and logging. */ 28 33 int VBoxServiceWritePropF(uint32_t u32ClientId, const char *pszName, const char *pszValueFormat, ...); 29 34 #endif
Note:
See TracChangeset
for help on using the changeset viewer.