Changeset 47335 in vbox
- Timestamp:
- Jul 23, 2013 10:53:37 AM (12 years ago)
- svn:sync-xref-src-repo-rev:
- 87480
- Location:
- trunk/src/VBox/Additions/common/VBoxService
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceInternal.h
r46506 r47335 174 174 #endif 175 175 176 extern RTEXITCODE VBoxServiceSyntax(const char *pszFormat, ...);177 extern RTEXITCODE VBoxServiceError(const char *pszFormat, ...);178 extern void VBoxServiceVerbose(int iLevel, const char *pszFormat, ...);179 extern int VBoxServiceArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32,180 uint32_t u32Min, uint32_t u32Max);181 extern int VBoxServiceStartServices(void);182 extern int VBoxServiceStopServices(void);183 extern void VBoxServiceMainWait(void);184 extern int VBoxServiceReportStatus(VBoxGuestFacilityStatus enmStatus);185 #ifdef RT_OS_WINDOWS 186 extern RTEXITCODE VBoxServiceWinInstall(void);187 extern RTEXITCODE VBoxServiceWinUninstall(void);188 extern RTEXITCODE VBoxServiceWinEnterCtrlDispatcher(void);189 extern void VBoxServiceWinSetStopPendingStatus(uint32_t uCheckPoint);176 extern RTEXITCODE VBoxServiceSyntax(const char *pszFormat, ...); 177 extern RTEXITCODE VBoxServiceError(const char *pszFormat, ...); 178 extern void VBoxServiceVerbose(int iLevel, const char *pszFormat, ...); 179 extern int VBoxServiceArgUInt32(int argc, char **argv, const char *psz, int *pi, uint32_t *pu32, 180 uint32_t u32Min, uint32_t u32Max); 181 extern int VBoxServiceStartServices(void); 182 extern int VBoxServiceStopServices(void); 183 extern void VBoxServiceMainWait(void); 184 extern int VBoxServiceReportStatus(VBoxGuestFacilityStatus enmStatus); 185 #ifdef RT_OS_WINDOWS 186 extern RTEXITCODE VBoxServiceWinInstall(void); 187 extern RTEXITCODE VBoxServiceWinUninstall(void); 188 extern RTEXITCODE VBoxServiceWinEnterCtrlDispatcher(void); 189 extern void VBoxServiceWinSetStopPendingStatus(uint32_t uCheckPoint); 190 190 #endif 191 191 192 192 #ifdef VBOXSERVICE_TOOLBOX 193 extern bool VBoxServiceToolboxMain(int argc, char **argv, RTEXITCODE *prcExit);193 extern bool VBoxServiceToolboxMain(int argc, char **argv, RTEXITCODE *prcExit); 194 194 #endif 195 195 196 196 #ifdef RT_OS_WINDOWS 197 197 # ifdef VBOX_WITH_GUEST_PROPS 198 extern int VBoxServiceVMInfoWinWriteUsers(char **ppszUserList, uint32_t *pcUsersInList);199 extern int VBoxServiceWinGetComponentVersions(uint32_t uiClientID);198 extern int VBoxServiceVMInfoWinWriteUsers(PVBOXSERVICEVEPROPCACHE pCache, char **ppszUserList, uint32_t *pcUsersInList); 199 extern int VBoxServiceWinGetComponentVersions(uint32_t uiClientID); 200 200 # endif /* VBOX_WITH_GUEST_PROPS */ 201 201 #endif /* RT_OS_WINDOWS */ -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceUtils.cpp
r44570 r47335 152 152 * Reads a guest property from the host side. 153 153 * 154 * @returns VBox status code, fully bitched. 155 * 154 * @returns IPRT status code, fully bitched. 156 155 * @param u32ClientId The HGCM client ID for the guest property session. 157 156 * @param pszPropName The property name. -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo-win.cpp
r47294 r47335 25 25 #endif 26 26 #include <Windows.h> 27 #include <wtsapi32.h> /* For WTS* calls. */28 #include <psapi.h> /* EnumProcesses. */29 #include <Ntsecapi.h> /* Needed for process security information. */27 #include <wtsapi32.h> /* For WTS* calls. */ 28 #include <psapi.h> /* EnumProcesses. */ 29 #include <Ntsecapi.h> /* Needed for process security information. */ 30 30 31 31 #include <iprt/assert.h> … … 41 41 #include "VBoxServiceInternal.h" 42 42 #include "VBoxServiceUtils.h" 43 #include "VBoxServiceVMInfo.h" 43 44 #include "../../WINNT/VBoxTray/VBoxTrayMsg.h" /* For IPC. */ 44 45 … … 92 93 int VBoxServiceVMInfoWinProcessesEnumerate(PVBOXSERVICEVMINFOPROC *ppProc, DWORD *pdwCount); 93 94 void VBoxServiceVMInfoWinProcessesFree(DWORD cProcs, PVBOXSERVICEVMINFOPROC paProcs); 94 int vboxServiceVMInfoWinWriteLastInput( const char *pszUser, const char *pszDomain);95 int vboxServiceVMInfoWinWriteLastInput(PVBOXSERVICEVEPROPCACHE pCache, const char *pszUser, const char *pszDomain); 95 96 96 97 typedef BOOL WINAPI FNQUERYFULLPROCESSIMAGENAME(HANDLE, DWORD, LPTSTR, PDWORD); … … 808 809 809 810 810 static int vboxServiceVMInfoWinWriteLastInput(const char *pszUser, const char *pszDomain) 811 { 811 static int vboxServiceVMInfoWinWriteLastInput(PVBOXSERVICEVEPROPCACHE pCache, 812 const char *pszUser, const char *pszDomain) 813 { 814 AssertPtrReturn(pCache, VERR_INVALID_POINTER); 812 815 AssertPtrReturn(pszUser, VERR_INVALID_POINTER); 813 816 … … 833 836 if (RT_SUCCESS(rc)) 834 837 { 835 VBoxGuestUserState userState = ipcRes.uLastInputMs < 5000 /** @todo Make this configurable. */838 VBoxGuestUserState userState = ipcRes.uLastInputMs < g_uVMInfoUserIdleThreshold 836 839 ? VBoxGuestUserState_InUse 837 840 : VBoxGuestUserState_Idle; 838 if (ipcRes.uLastInputMs) 841 842 rc = vboxServiceUserUpdateF(pCache, pszUser, pszDomain, "UsageState", 843 userState == VBoxGuestUserState_InUse 844 ? "InUse" : "Idle"); 845 846 /* 847 * Note: vboxServiceUserUpdateF can return VINF_NO_CHANGE in case there wasn't anything 848 * to update. So only report the user's status to host when we really got something 849 * new. 850 */ 851 if (rc == VINF_SUCCESS) 839 852 { 840 853 VBoxServiceVerbose(4, "User \"%s\" (domain \"%s\") is idle for %RU32ms\n", 841 854 pszUser, pszDomain ? pszDomain : "<None>", ipcRes.uLastInputMs); 842 855 843 rc = VbglR3GuestUserReportState(pszUser, pszDomain, userState, 844 NULL /* No details */, 0); 856 #if 0 /* Do we want to write the idle time as well? */ 857 /* Also write the user's current idle time, if there is any. */ 858 if (userState == VBoxGuestUserState_Idle) 859 rc = vboxServiceUserUpdateF(pCache, pszUser, pszDomain, "IdleTimeMs", 860 "%RU32", ipcRes.uLastInputMs); 861 else 862 rc = vboxServiceUserUpdateF(pCache, pszUser, pszDomain, "IdleTimeMs", 863 NULL /* Delete property */); 864 865 if (RT_SUCCESS(rc)) 866 #endif 867 rc = VbglR3GuestUserReportState(pszUser, pszDomain, userState, 868 NULL /* No details */, 0); 845 869 } 846 870 } … … 883 907 * 884 908 * @returns VBox status code. 909 * @param pCachce Property cache to use for storing some of the lookup 910 * data in between calls. 885 911 * @param ppszUserList Where to store the user list (separated by commas). 886 912 * Must be freed with RTStrFree(). 887 913 * @param pcUsersInList Where to store the number of users in the list. 888 914 */ 889 int VBoxServiceVMInfoWinWriteUsers(char **ppszUserList, uint32_t *pcUsersInList) 890 { 915 int VBoxServiceVMInfoWinWriteUsers(PVBOXSERVICEVEPROPCACHE pCache, 916 char **ppszUserList, uint32_t *pcUsersInList) 917 { 918 AssertPtrReturn(pCache, VERR_INVALID_POINTER); 891 919 AssertPtrReturn(ppszUserList, VERR_INVALID_POINTER); 892 920 AssertPtrReturn(pcUsersInList, VERR_INVALID_POINTER); … … 1081 1109 /* Do idle detection. */ 1082 1110 if (RT_SUCCESS(rc)) 1083 rc = vboxServiceVMInfoWinWriteLastInput(p szUser, pszDomain);1111 rc = vboxServiceVMInfoWinWriteLastInput(pCache, pszUser, pszDomain); 1084 1112 } 1085 1113 else -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
r45874 r47335 103 103 static const char *g_pszPropCacheValNoLoggedInUsers = "/VirtualBox/GuestInfo/OS/NoLoggedInUsers"; 104 104 static const char *g_pszPropCacheValNetCount = "/VirtualBox/GuestInfo/Net/Count"; 105 /** A guest user's guest property root key. */ 106 static const char *g_pszPropCacheValUser = "/VirtualBox/GuestInfo/User/"; 105 107 /** The VM session ID. Changes whenever the VM is restored or reset. */ 106 108 static uint64_t g_idVMInfoSession; … … 109 111 /** The current LA client info. */ 110 112 static VBOXSERVICELACLIENTINFO g_LAClientInfo; 113 /** User idle threshold. This specifies the minimum time a user is considered 114 * being idle and then will be reported to the host. Default is 5s. */ 115 uint32_t g_uVMInfoUserIdleThreshold = 5 * 1000; 111 116 112 117 … … 157 162 static DECLCALLBACK(int) VBoxServiceVMInfoOption(const char **ppszShort, int argc, char **argv, int *pi) 158 163 { 164 /** @todo Use RTGetOpt here. */ 165 159 166 int rc = -1; 160 167 if (ppszShort) … … 163 170 rc = VBoxServiceArgUInt32(argc, argv, "", pi, 164 171 &g_cMsVMInfoInterval, 1, UINT32_MAX - 1); 172 else if (!strcmp(argv[*pi], "--vminfo-user-idle-threshold")) 173 rc = VBoxServiceArgUInt32(argc, argv, "", pi, 174 &g_uVMInfoUserIdleThreshold, 1, UINT32_MAX - 1); 165 175 return rc; 166 176 } … … 235 245 if (RT_FAILURE(rc2)) 236 246 VBoxServiceError("Failed to init property cache value \"%s\", rc=%Rrc\n", g_pszPropCacheValNetCount, rc2); 247 248 /* 249 * Get configuration guest properties from the host. 250 * Note: All properties should have sensible defaults in case the lookup here fails. 251 */ 252 char *pszValue; 253 rc2 = VBoxServiceReadHostProp(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestAdd/VBoxService/--vminfo-user-idle-threshold", true /* Read only */, 254 &pszValue, NULL /* Flags */, NULL /* Timestamp */); 255 if (RT_SUCCESS(rc2)) 256 { 257 AssertPtr(pszValue); 258 g_uVMInfoUserIdleThreshold = RT_CLAMP(RTStrToInt32(pszValue), 1000, UINT32_MAX - 1); 259 } 237 260 } 238 261 return rc; … … 337 360 } 338 361 } 362 } 363 364 365 /** 366 * Updates a per-guest user guest property inside the given property cache. 367 * 368 * @return IPRT status code. 369 * @param pCache Pointer to guest property cache to update user in. 370 * @param pszUser Name of guest user to update. 371 * @param pszDomain Domain of guest user to update. Optional. 372 * @param pszKey Key name of guest property to update. 373 * @param pszValueFormat Guest property value to set. Pass NULL for deleting 374 * the property. 375 */ 376 int vboxServiceUserUpdateF(PVBOXSERVICEVEPROPCACHE pCache, const char *pszUser, const char *pszDomain, 377 const char *pszKey, const char *pszValueFormat, ...) 378 { 379 AssertPtrReturn(pCache, VERR_INVALID_POINTER); 380 AssertPtrReturn(pszUser, VERR_INVALID_POINTER); 381 /* pszDomain is optional. */ 382 AssertPtrReturn(pszKey, VERR_INVALID_POINTER); 383 /* pszValueFormat is optional. */ 384 385 int rc = VINF_SUCCESS; 386 387 char *pszName; 388 if (pszDomain) 389 if (!RTStrAPrintf(&pszName, "%s%s@%s/%s", g_pszPropCacheValUser, pszUser, pszDomain, pszKey)) 390 rc = VERR_NO_MEMORY; 391 else 392 if (!RTStrAPrintf(&pszName, "%s%s/%s", g_pszPropCacheValUser, pszUser, pszKey)) 393 rc = VERR_NO_MEMORY; 394 395 char *pszValue = NULL; 396 if ( RT_SUCCESS(rc) 397 && pszValueFormat) 398 { 399 va_list va; 400 va_start(va, pszValueFormat); 401 if (RTStrAPrintfV(&pszValue, pszValueFormat, va) < 0) 402 rc = VERR_NO_MEMORY; 403 va_end(va); 404 if ( RT_SUCCESS(rc) 405 && !pszValue) 406 rc = VERR_NO_STR_MEMORY; 407 } 408 409 if (RT_SUCCESS(rc)) 410 rc = VBoxServicePropCacheUpdate(pCache, pszName, pszValue); 411 if (rc == VINF_SUCCESS) /* VBoxServicePropCacheUpdate will also return VINF_NO_CHANGE. */ 412 { 413 /** @todo Combine updating flags w/ updating the actual value. */ 414 rc = VBoxServicePropCacheUpdateEntry(pCache, pszName, 415 VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_TRANSIENT, 416 NULL /* Delete on exit */); 417 } 418 419 RTStrFree(pszValue); 420 RTStrFree(pszName); 421 return rc; 339 422 } 340 423 … … 431 514 #ifdef RT_OS_WINDOWS 432 515 # ifndef TARGET_NT4 433 rc = VBoxServiceVMInfoWinWriteUsers(&pszUserList, &cUsersInList); 516 rc = VBoxServiceVMInfoWinWriteUsers(&g_VMInfoPropCache, 517 &pszUserList, &cUsersInList); 434 518 # else 435 519 rc = VERR_NOT_IMPLEMENTED; … … 1391 1475 "Virtual Machine Information", 1392 1476 /* pszUsage. */ 1393 " [--vminfo-interval <ms>] "1477 " [--vminfo-interval <ms>] [--vminfo-user-idle-threshold <ms>]" 1394 1478 , 1395 1479 /* pszOptions. */ 1396 1480 " --vminfo-interval Specifies the interval at which to retrieve the\n" 1397 1481 " VM information. The default is 10000 ms.\n" 1482 " --vminfo-user-idle-threshold <ms>\n" 1483 " Specifies the user idle threshold (in ms) for\n" 1484 " considering a guest user being as idle. The default\n" 1485 " is 5000 (5 seconds).\n" 1398 1486 , 1399 1487 /* methods */
Note:
See TracChangeset
for help on using the changeset viewer.