Changeset 101377 in vbox
- Timestamp:
- Oct 6, 2023 8:26:36 AM (17 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Additions/common/VBoxService/VBoxServiceVMInfo.cpp
r101235 r101377 580 580 * - whether we got the type the caller's looking for 581 581 */ 582 static bool vboxService_dbus_unpack_variant_reply(DBusError *error, DBusMessage *pReply, char pType, void *pValue) { 583 if (dbus_error_is_set(error)) { 582 static bool vboxService_dbus_unpack_variant_reply(DBusError *error, DBusMessage *pReply, char pType, void *pValue) 583 { 584 if (dbus_error_is_set(error)) 585 { 584 586 VGSvcError("dbus_unpack_variant_reply: dbus returned error '%s'\n", error->message); 585 587 dbus_error_free(error); 586 } else if (pReply) { 588 } 589 else if (pReply) 590 { 587 591 DBusMessageIter iterMsg; 588 592 int iterType; 589 593 dbus_message_iter_init(pReply, &iterMsg); 590 594 iterType = dbus_message_iter_get_arg_type(&iterMsg); 591 if (iterType == DBUS_TYPE_VARIANT) { 595 if (iterType == DBUS_TYPE_VARIANT) 596 { 592 597 DBusMessageIter iterValueMsg; 593 598 int iterValueType; 594 599 dbus_message_iter_recurse(&iterMsg, &iterValueMsg); 595 600 iterValueType = dbus_message_iter_get_arg_type(&iterValueMsg); 596 if (iterValueType == pType) { 601 if (iterValueType == pType) 602 { 597 603 dbus_message_iter_get_basic(&iterValueMsg, pValue); 598 604 return true; … … 610 616 static void vboxService_dbus_message_discard(DBusMessage **ppMsg) 611 617 { 612 if (ppMsg && *ppMsg) { 613 #if defined(ICKY_REFCOUNT_GRUBBING) 614 { 615 /* The DBusMessage Refcount private field isn't externally accessible. 616 * We want to check it for debug / assert purposes. 617 */ 618 uint32_t *pcRefCnt = (uint32_t *)(*ppMsg); 619 if (*p == 0) { 620 VGSvcVerbose(1, "dbus_message_discard: unref %p whose refcnt is 0 (expected 1) -- this would have been a double-free\n", ppMsg); 621 *ppMsg = NULL; 622 return; 623 } else if (*p != 1) { 624 VGSvcVerbose(1, "dbus_message_discard: unref %p whose refcnt is %d (expected 1)\n", ppMsg, *p); 625 } 626 } 627 #endif /* ICKY_REFCOUNT_GRUBBING */ 618 if (ppMsg && *ppMsg) 619 { 620 /** @todo any clean-ish way to verify DBus internal refcount == 1 here? */ 628 621 dbus_message_unref(*ppMsg); 629 622 *ppMsg = NULL; … … 743 736 && !dbus_error_is_set(&dbErr)) 744 737 { 745 / // @todo is there some Less Horrible Way(tm) to access dbus?738 /** @todo is there some Less Horrible Way(tm) to access dbus? */ 746 739 /* Get all available sessions. */ 747 740 /* like `busctl call org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager ListSessions` */ … … 763 756 int messageIterType; 764 757 dbus_message_iter_init(pReplySessions, &messageIterMsg); 765 while ((messageIterType = dbus_message_iter_get_arg_type (&messageIterMsg)) != DBUS_TYPE_INVALID) { 766 if (messageIterType == DBUS_TYPE_ARRAY) { 758 while ((messageIterType = dbus_message_iter_get_arg_type (&messageIterMsg)) != DBUS_TYPE_INVALID) 759 { 760 if (messageIterType == DBUS_TYPE_ARRAY) 761 { 767 762 /* "ListSessions" returns an array, which we must iterate to get the array elements */ 768 763 DBusMessageIter arrayIterMsg; 769 764 int arrayIterType; 770 765 dbus_message_iter_recurse(&messageIterMsg, &arrayIterMsg); 771 while ((arrayIterType = dbus_message_iter_get_arg_type (&arrayIterMsg)) != DBUS_TYPE_INVALID) { 772 if (arrayIterType == DBUS_TYPE_STRUCT) { 766 while ((arrayIterType = dbus_message_iter_get_arg_type (&arrayIterMsg)) != DBUS_TYPE_INVALID) 767 { 768 if (arrayIterType == DBUS_TYPE_STRUCT) 769 { 773 770 /* The array elements are structs, which we must iterate to get the struct elements */ 774 771 DBusMessageIter structIterMsg; 775 772 int structIterType; 776 773 dbus_message_iter_recurse(&arrayIterMsg, &structIterMsg); 777 while ((structIterType = dbus_message_iter_get_arg_type (&structIterMsg)) != DBUS_TYPE_INVALID) { 778 if (structIterType == DBUS_TYPE_OBJECT_PATH) { 774 while ((structIterType = dbus_message_iter_get_arg_type (&structIterMsg)) != DBUS_TYPE_INVALID) 775 { 776 if (structIterType == DBUS_TYPE_OBJECT_PATH) 777 { 779 778 /* We are interested only in the "object path" struct element */ 780 779 const char *objectPath; … … 787 786 "Get"); 788 787 if ( pMsgSession 789 && dbus_message_get_type(pMsgSession) == DBUS_MESSAGE_TYPE_METHOD_CALL) { 788 && dbus_message_get_type(pMsgSession) == DBUS_MESSAGE_TYPE_METHOD_CALL) 789 { 790 790 const char *pPropertyActive = "Active"; 791 791 vboxService_dbus_message_append_args(pMsgSession, … … 805 805 DBUS_TYPE_BOOLEAN, 806 806 &sessionPropertyActiveValue) 807 && sessionPropertyActiveValue) { 807 && sessionPropertyActiveValue) 808 { 808 809 DBusMessage *pMsgSession2 = dbus_message_new_method_call(SYSTEMD_LOGIN_INTERFACE, 809 810 objectPath, … … 812 813 const char *pPropertyName = "Name"; 813 814 if ( pMsgSession2 814 && dbus_message_get_type(pMsgSession2) == DBUS_MESSAGE_TYPE_METHOD_CALL) { 815 && dbus_message_get_type(pMsgSession2) == DBUS_MESSAGE_TYPE_METHOD_CALL) 816 { 815 817 vboxService_dbus_message_append_args(pMsgSession2, 816 818 DBUS_TYPE_STRING, &pInterface,
Note:
See TracChangeset
for help on using the changeset viewer.