Help Needed

Frank Huang frank.huang at amwell.com
Thu Jan 4 21:36:05 UTC 2024


Hello DBus community,

I am working on the DBus project which is monitoring the active network state change. I encounter a technique challenge and need help here.

I subscribe to the DBus and listen for the signal of active network state change:
        DBus_Subscriber subscription_request_signal(&dbus_manager_, "org.freedesktop.NetworkManager.Connection.Active",
                "signal",
                "StateChanged",
                input, signal_callback, "signal_callback");

In the callback, I use a vector of shared pointer as the args to receive the payload from DBus:
void Network_Manager::dbusNetworkConnectivitySignalCallback(char* signature, std::vector<std::shared_ptr<void>> &args)

The args is passed to the following dbus library function to receive the payload:
arr is the same args from the callback function, arrary_ptr is the local shared_pointer.
                    // Reads a basic-typed value from the message iterator.
                    dbus_message_iter_get_basic(args, &array_ptr);
                    arr->push_back(array_ptr);


In the two block of code below, #1 and #2 are accessing the same shared pointer, #1 is working, #2 hit the segfault kernel crash by the last line of code which try to access what the shared pointer is pointing to. I have added the debug code to verify that the retval_ptr is not nullptr, and checked the size of the args which is valid.

    // #1 using std::stringstream
    std::stringstream reason_ss;
    reason_ss << std::static_pointer_cast<uint32_t>(args.back());
    INFO("stringstream signal reason: " + reason_ss.str());

    // #2 using uint32_t
    std::shared_ptr<uint32_t> retval_ptr;
    uint32_t reason_uint;
    retval_ptr = std::static_pointer_cast<uint32_t>(args.back());
    reason_uint = *retval_ptr;

I have tried to understand the data structure in our DBus document from the DBus official site but could not find the smoking gun of the segfault issue. Could anyone point me out why the #2 doesn't work? We want to use #2 in our code base.

Any input will be highly appreciated!
-Frank H
Confidentiality Notice: Amwell is a registered trademark of American Well Corporation. This email is the property of American Well, Inc This e-mail message, including any attachments, is for the sole use of the intended recipient(s) and may contain confidential and/or privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply e-mail and destroy all copies of the original message.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/dbus/attachments/20240104/88a42400/attachment-0001.htm>


More information about the dbus mailing list