Changeset 45874 in vbox
- Timestamp:
- May 2, 2013 12:16:42 PM (12 years ago)
- Location:
- trunk/src/VBox/Additions/common/VBoxService
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServicePropCache.cpp
r44529 r45874 217 217 { 218 218 AssertPtrReturn(pCache, VERR_INVALID_POINTER); 219 AssertPtrReturn(pszName, VERR_INVALID_POINTER); 220 219 221 Assert(pCache->uClientID); 220 AssertPtrReturn(pszName, VERR_INVALID_POINTER);221 222 222 223 /* … … 261 262 /* Write the update. */ 262 263 rc = vboxServicePropCacheWritePropF(pCache->uClientID, pNode->pszName, pNode->fFlags, pszValue); 263 VBoxServiceVerbose(4, " PropCache %p: Written \"%s\"=\"%s\" (flags: %x), rc=%Rrc\n",264 VBoxServiceVerbose(4, "[PropCache %p]: Written \"%s\"=\"%s\" (flags: %x), rc=%Rrc\n", 264 265 pCache, pNode->pszName, pszValue, pNode->fFlags, rc); 265 RTStrFree(pNode->pszValue); 266 pNode->pszValue = RTStrDup(pszValue); 267 if (!pNode->pszValue) 268 rc = VERR_NO_MEMORY; 266 if (RT_SUCCESS(rc)) /* Only update the node's value on successful write. */ 267 { 268 RTStrFree(pNode->pszValue); 269 pNode->pszValue = RTStrDup(pszValue); 270 if (!pNode->pszValue) 271 rc = VERR_NO_MEMORY; 272 } 269 273 } 270 274 else … … 276 280 if (pNode->pszValue) /* Did we have a value before? Then the value needs to be deleted. */ 277 281 { 278 /* Delete property (but do not remove from cache) if not deleted yet. */279 RTStrFree(pNode->pszValue);280 pNode->pszValue = NULL;281 282 rc = vboxServicePropCacheWritePropF(pCache->uClientID, pNode->pszName, 282 283 0, /* Flags */ NULL /* Value */); 283 VBoxServiceVerbose(4, " PropCache %p: Deleted \"%s\"=\"%s\" (flags: %x), rc=%Rrc\n",284 VBoxServiceVerbose(4, "[PropCache %p]: Deleted \"%s\"=\"%s\" (flags: %x), rc=%Rrc\n", 284 285 pCache, pNode->pszName, pNode->pszValue, pNode->fFlags, rc); 286 if (RT_SUCCESS(rc)) /* Only delete property value on successful Vbgl deletion. */ 287 { 288 /* Delete property (but do not remove from cache) if not deleted yet. */ 289 RTStrFree(pNode->pszValue); 290 pNode->pszValue = NULL; 291 } 285 292 } 286 293 else … … 291 298 RTCritSectLeave(&pCache->CritSect); 292 299 } 300 301 VBoxServiceVerbose(4, "[PropCache %p]: Updating \"%s\" resulted in rc=%Rrc\n", 302 pCache, pszName, rc); 293 303 294 304 /* Delete temp stuff. */ -
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
r45459 r45874 95 95 /** The guest property service client ID. */ 96 96 static uint32_t g_uVMInfoGuestPropSvcClientID = 0; 97 /** Number of logged in users in OS. */98 static uint32_t g_cVMInfoLoggedInUsers = UINT32_MAX;97 /** Number of currently logged in users in OS. */ 98 static uint32_t g_cVMInfoLoggedInUsers = 0; 99 99 /** The guest property cache. */ 100 100 static VBOXSERVICEVEPROPCACHE g_VMInfoPropCache; 101 static const char *g_pszPropCacheValLoggedInUsersList = "/VirtualBox/GuestInfo/OS/LoggedInUsersList"; 102 static const char *g_pszPropCacheValLoggedInUsers = "/VirtualBox/GuestInfo/OS/LoggedInUsers"; 103 static const char *g_pszPropCacheValNoLoggedInUsers = "/VirtualBox/GuestInfo/OS/NoLoggedInUsers"; 104 static const char *g_pszPropCacheValNetCount = "/VirtualBox/GuestInfo/Net/Count"; 101 105 /** The VM session ID. Changes whenever the VM is restored or reset. */ 102 106 static uint64_t g_idVMInfoSession; … … 212 216 * Declare some guest properties with flags and reset values. 213 217 */ 214 VBoxServicePropCacheUpdateEntry(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsersList", 215 VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_TRANSIENT, NULL /* Delete on exit */); 216 VBoxServicePropCacheUpdateEntry(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsers", 217 VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_TRANSIENT, "0"); 218 VBoxServicePropCacheUpdateEntry(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/NoLoggedInUsers", 219 VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_TRANSIENT, "true"); 220 VBoxServicePropCacheUpdateEntry(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/Net/Count", 221 VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATE, NULL /* Delete on exit */); 218 int rc2 = VBoxServicePropCacheUpdateEntry(&g_VMInfoPropCache, g_pszPropCacheValLoggedInUsersList, 219 VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_TRANSIENT, NULL /* Delete on exit */); 220 if (RT_FAILURE(rc2)) 221 VBoxServiceError("Failed to init property cache value \"%s\", rc=%Rrc\n", g_pszPropCacheValLoggedInUsersList, rc2); 222 223 rc2 = VBoxServicePropCacheUpdateEntry(&g_VMInfoPropCache, g_pszPropCacheValLoggedInUsers, 224 VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_TRANSIENT, "0"); 225 if (RT_FAILURE(rc2)) 226 VBoxServiceError("Failed to init property cache value \"%s\", rc=%Rrc\n", g_pszPropCacheValLoggedInUsers, rc2); 227 228 rc2 = VBoxServicePropCacheUpdateEntry(&g_VMInfoPropCache, g_pszPropCacheValNoLoggedInUsers, 229 VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_TRANSIENT, "true"); 230 if (RT_FAILURE(rc2)) 231 VBoxServiceError("Failed to init property cache value \"%s\", rc=%Rrc\n", g_pszPropCacheValNoLoggedInUsers, rc2); 232 233 rc2 = VBoxServicePropCacheUpdateEntry(&g_VMInfoPropCache, g_pszPropCacheValNetCount, 234 VBOXSERVICEPROPCACHEFLAG_TEMPORARY | VBOXSERVICEPROPCACHEFLAG_ALWAYS_UPDATE, NULL /* Delete on exit */); 235 if (RT_FAILURE(rc2)) 236 VBoxServiceError("Failed to init property cache value \"%s\", rc=%Rrc\n", g_pszPropCacheValNetCount, rc2); 222 237 } 223 238 return rc; … … 676 691 } 677 692 678 if ( pConnection 693 if ( pConnection 679 694 && dbus_error_is_set(&dbErr)) 680 695 dbus_error_free(&dbErr); … … 728 743 static int s_iVMInfoBitchedOOM = 0; 729 744 if (s_iVMInfoBitchedOOM++ < 3) 730 VBoxServiceVerbose(0, "Warning: Not enough memory available to enumerate users! Keeping old value (% u)\n",745 VBoxServiceVerbose(0, "Warning: Not enough memory available to enumerate users! Keeping old value (%RU32)\n", 731 746 g_cVMInfoLoggedInUsers); 732 747 cUsersInList = g_cVMInfoLoggedInUsers; … … 735 750 cUsersInList = 0; 736 751 } 752 else /* Preserve logged in users count. */ 753 g_cVMInfoLoggedInUsers = cUsersInList; 737 754 738 755 VBoxServiceVerbose(4, "cUsersInList=%RU32, pszUserList=%s, rc=%Rrc\n", 739 756 cUsersInList, pszUserList ? pszUserList : "<NULL>", rc); 740 757 741 if (pszUserList && cUsersInList > 0) 742 rc = VBoxServicePropCacheUpdate(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsersList", "%s", pszUserList); 758 if (pszUserList) 759 { 760 AssertMsg(cUsersInList, ("pszUserList contains users whereas cUsersInList is 0\n")); 761 rc = VBoxServicePropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValLoggedInUsersList, "%s", pszUserList); 762 } 743 763 else 744 rc = VBoxServicePropCacheUpdate(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsersList", NULL);764 rc = VBoxServicePropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValLoggedInUsersList, NULL); 745 765 if (RT_FAILURE(rc)) 746 { 747 VBoxServiceError("Error writing logged on users list, rc=%Rrc\n", rc); 748 cUsersInList = 0; /* Reset user count on error. */ 749 } 750 751 rc = VBoxServicePropCacheUpdate(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/LoggedInUsers", "%u", cUsersInList); 766 VBoxServiceError("Error writing logged in users list, rc=%Rrc\n", rc); 767 768 rc = VBoxServicePropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValLoggedInUsers, "%RU32", cUsersInList); 752 769 if (RT_FAILURE(rc)) 753 { 754 VBoxServiceError("Error writing logged on users count, rc=%Rrc\n", rc); 755 cUsersInList = 0; /* Reset user count on error. */ 756 } 757 758 if (g_cVMInfoLoggedInUsers != cUsersInList) 759 { 760 rc = VBoxServicePropCacheUpdate(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/OS/NoLoggedInUsers", 761 cUsersInList == 0 ? "true" : "false"); 762 if (RT_FAILURE(rc)) 763 VBoxServiceError("Error writing no logged in users beacon, rc=%Rrc\n", rc); 764 g_cVMInfoLoggedInUsers = cUsersInList; 765 } 770 VBoxServiceError("Error writing logged in users count, rc=%Rrc\n", rc); 771 772 rc = VBoxServicePropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValNoLoggedInUsers, 773 cUsersInList == 0 ? "true" : "false"); 774 if (RT_FAILURE(rc)) 775 VBoxServiceError("Error writing no logged in users beacon, rc=%Rrc\n", rc); 776 766 777 if (pszUserList) 767 778 RTStrFree(pszUserList); … … 869 880 char szIp[32]; 870 881 RTStrPrintf(szIp, sizeof(szIp), "%s", inet_ntoa(pAddress->sin_addr)); 871 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/% u/V4/IP", cIfacesReport);882 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIfacesReport); 872 883 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szIp); 873 884 874 885 pAddress = (sockaddr_in *) & (InterfaceList[i].iiBroadcastAddress); 875 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/% u/V4/Broadcast", cIfacesReport);886 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIfacesReport); 876 887 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr)); 877 888 878 889 pAddress = (sockaddr_in *)&(InterfaceList[i].iiNetmask); 879 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/% u/V4/Netmask", cIfacesReport);890 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfacesReport); 880 891 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr)); 881 892 882 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/% u/Status", cIfacesReport);893 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIfacesReport); 883 894 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, nFlags & IFF_UP ? "Up" : "Down"); 884 895 … … 889 900 break; 890 901 891 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/% u/MAC", cIfacesReport);902 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/MAC", cIfacesReport); 892 903 if (pAdp) 893 904 { … … 940 951 getnameinfo(pIfCurr->ifa_addr, sizeof(struct sockaddr_in), 941 952 szInetAddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); 942 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/% u/V4/IP", cIfacesReport);953 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIfacesReport); 943 954 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr); 944 955 … … 946 957 getnameinfo(pIfCurr->ifa_broadaddr, sizeof(struct sockaddr_in), 947 958 szInetAddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); 948 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/% u/V4/Broadcast", cIfacesReport);959 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIfacesReport); 949 960 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr); 950 961 … … 952 963 getnameinfo(pIfCurr->ifa_netmask, sizeof(struct sockaddr_in), 953 964 szInetAddr, NI_MAXHOST, NULL, 0, NI_NUMERICHOST); 954 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/% u/V4/Netmask", cIfacesReport);965 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfacesReport); 955 966 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szInetAddr); 956 967 … … 969 980 RTStrPrintf(szMac, sizeof(szMac), "%02X%02X%02X%02X%02X%02X", 970 981 pu8Mac[0], pu8Mac[1], pu8Mac[2], pu8Mac[3], pu8Mac[4], pu8Mac[5]); 971 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/% u/MAC", cIfacesReport);982 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/MAC", cIfacesReport); 972 983 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szMac); 973 984 break; … … 975 986 } 976 987 977 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/% u/Status", cIfacesReport);988 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIfacesReport); 978 989 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, pIfCurr->ifa_flags & IFF_UP ? "Up" : "Down"); 979 990 … … 1024 1035 pAddress = ((sockaddr_in *)&ifrequest[i].ifr_addr); 1025 1036 Assert(pAddress); 1026 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/% u/V4/IP", cIfacesReport);1037 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/IP", cIfacesReport); 1027 1038 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr)); 1028 1039 … … 1034 1045 } 1035 1046 pAddress = (sockaddr_in *)&ifrequest[i].ifr_broadaddr; 1036 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/% u/V4/Broadcast", cIfacesReport);1047 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Broadcast", cIfacesReport); 1037 1048 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr)); 1038 1049 … … 1049 1060 # endif 1050 1061 1051 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/% u/V4/Netmask", cIfacesReport);1062 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/V4/Netmask", cIfacesReport); 1052 1063 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", inet_ntoa(pAddress->sin_addr)); 1053 1064 … … 1106 1117 RTStrPrintf(szMac, sizeof(szMac), "%02X%02X%02X%02X%02X%02X", 1107 1118 pu8Mac[0], pu8Mac[1], pu8Mac[2], pu8Mac[3], pu8Mac[4], pu8Mac[5]); 1108 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/% u/MAC", cIfacesReport);1119 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/MAC", cIfacesReport); 1109 1120 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, "%s", szMac); 1110 1121 # endif /* !OS/2*/ 1111 1122 1112 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/% u/Status", cIfacesReport);1123 RTStrPrintf(szPropPath, sizeof(szPropPath), "/VirtualBox/GuestInfo/Net/%RU32/Status", cIfacesReport); 1113 1124 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, szPropPath, fIfUp ? "Up" : "Down"); 1114 1125 cIfacesReport++; … … 1117 1128 close(sd); 1118 1129 if (RT_FAILURE(rc)) 1119 VBoxServiceError("VMInfo/Network: Network enumeration for interface % ufailed with error %Rrc\n", cIfacesReport, rc);1130 VBoxServiceError("VMInfo/Network: Network enumeration for interface %RU32 failed with error %Rrc\n", cIfacesReport, rc); 1120 1131 1121 1132 #endif /* !RT_OS_WINDOWS */ … … 1129 1140 /* Get former count. */ 1130 1141 uint32_t cIfacesReportOld; 1131 rc = VBoxServiceReadPropUInt32(g_uVMInfoGuestPropSvcClientID, "/VirtualBox/GuestInfo/Net/Count", &cIfacesReportOld,1142 rc = VBoxServiceReadPropUInt32(g_uVMInfoGuestPropSvcClientID, g_pszPropCacheValNetCount, &cIfacesReportOld, 1132 1143 0 /* Min */, UINT32_MAX /* Max */); 1133 1144 if ( RT_SUCCESS(rc) 1134 1145 && cIfacesReportOld > cIfacesReport) /* Are some ifaces not around anymore? */ 1135 1146 { 1136 VBoxServiceVerbose(3, "VMInfo/Network: Stale interface data detected (% u old vs. %ucurrent)\n",1147 VBoxServiceVerbose(3, "VMInfo/Network: Stale interface data detected (%RU32 old vs. %RU32 current)\n", 1137 1148 cIfacesReportOld, cIfacesReport); 1138 1149 … … 1141 1152 { 1142 1153 VBoxServiceVerbose(3, "VMInfo/Network: Deleting stale data of interface %d ...\n", uIfaceDeleteIdx); 1143 rc = VBoxServicePropCacheUpdateByPath(&g_VMInfoPropCache, NULL /* Value, delete */, 0 /* Flags */, "/VirtualBox/GuestInfo/Net/% u", uIfaceDeleteIdx++);1154 rc = VBoxServicePropCacheUpdateByPath(&g_VMInfoPropCache, NULL /* Value, delete */, 0 /* Flags */, "/VirtualBox/GuestInfo/Net/%RU32", uIfaceDeleteIdx++); 1144 1155 } while (RT_SUCCESS(rc)); 1145 1156 } … … 1156 1167 * properties are no longer valid. 1157 1168 */ 1158 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, "/VirtualBox/GuestInfo/Net/Count", "%d",1169 VBoxServicePropCacheUpdate(&g_VMInfoPropCache, g_pszPropCacheValNetCount, "%RU32", 1159 1170 cIfacesReport); 1160 1171
Note:
See TracChangeset
for help on using the changeset viewer.