<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;
        mso-ligatures:standardcontextual;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri",sans-serif;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal">Hello DBus community,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I am working on the DBus project which is monitoring the active network state change. I encounter a technique challenge and need help here.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I subscribe to the DBus and listen for the signal of active network state change:<o:p></o:p></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">       
</span><span style="font-size:10.5pt;font-family:Consolas;color:#4EC9B0;mso-ligatures:none">DBus_Subscriber</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">
</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">subscription_request_signal</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">(</span><span style="font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-ligatures:none">&</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">dbus_manager_</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">,
</span><span style="font-size:10.5pt;font-family:Consolas;color:#CE9178;mso-ligatures:none">"org.freedesktop.NetworkManager.Connection.Active"</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">,<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">               
</span><span style="font-size:10.5pt;font-family:Consolas;color:#CE9178;mso-ligatures:none">"signal"</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">,<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">               
</span><span style="font-size:10.5pt;font-family:Consolas;color:#CE9178;mso-ligatures:none">"StateChanged"</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">,<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">               
</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">input</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">,
</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">signal_callback</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">,
</span><span style="font-size:10.5pt;font-family:Consolas;color:#CE9178;mso-ligatures:none">"signal_callback"</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">);<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">In the callback, I use a vector of shared pointer as the args to receive the payload from DBus:<o:p></o:p></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-ligatures:none">void</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">
</span><span style="font-size:10.5pt;font-family:Consolas;color:#4EC9B0;mso-ligatures:none">Network_Manager</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">::</span><span style="font-size:10.5pt;font-family:Consolas;color:#DCDCAA;mso-ligatures:none">dbusNetworkConnectivitySignalCallback</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">(</span><span style="font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-ligatures:none">char*</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">
</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">signature</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">,
</span><span style="font-size:10.5pt;font-family:Consolas;color:#4EC9B0;mso-ligatures:none">std</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">::</span><span style="font-size:10.5pt;font-family:Consolas;color:#4EC9B0;mso-ligatures:none">vector</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none"><</span><span style="font-size:10.5pt;font-family:Consolas;color:#4EC9B0;mso-ligatures:none">std</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">::</span><span style="font-size:10.5pt;font-family:Consolas;color:#4EC9B0;mso-ligatures:none">shared_ptr</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none"><</span><span style="font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-ligatures:none">void</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">>>
</span><span style="font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-ligatures:none">&</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">args</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">)<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">The args is passed to the following dbus library function to receive the payload:<o:p></o:p></p>
<p class="MsoNormal">arr is the same args from the callback function, arrary_ptr is the local shared_pointer.<o:p></o:p></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#6A9955;mso-ligatures:none">                    // Reads a basic-typed value from the message iterator.</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">                   
</span><span style="font-size:10.5pt;font-family:Consolas;color:#DCDCAA;mso-ligatures:none">dbus_message_iter_get_basic</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">(</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">args</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">,
</span><span style="font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-ligatures:none">&</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">array_ptr</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">);<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">                   
</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">arr</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">-></span><span style="font-size:10.5pt;font-family:Consolas;color:#DCDCAA;mso-ligatures:none">push_back</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">(</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">array_ptr</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">);<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">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.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#6A9955;mso-ligatures:none">    // #1 using std::stringstream</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">   
</span><span style="font-size:10.5pt;font-family:Consolas;color:#4EC9B0;mso-ligatures:none">std</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">::</span><span style="font-size:10.5pt;font-family:Consolas;color:#4EC9B0;mso-ligatures:none">stringstream</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">
</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">reason_ss</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">   
</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">reason_ss</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">
</span><span style="font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-ligatures:none"><<</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">
</span><span style="font-size:10.5pt;font-family:Consolas;color:#4EC9B0;mso-ligatures:none">std</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">::</span><span style="font-size:10.5pt;font-family:Consolas;color:#DCDCAA;mso-ligatures:none">static_pointer_cast</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none"><</span><span style="font-size:10.5pt;font-family:Consolas;color:#4EC9B0;mso-ligatures:none">uint32_t</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">>(</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">args</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">.</span><span style="font-size:10.5pt;font-family:Consolas;color:#DCDCAA;mso-ligatures:none">back</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">());<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">   
</span><span style="font-size:10.5pt;font-family:Consolas;color:#569CD6;mso-ligatures:none">INFO</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">(</span><span style="font-size:10.5pt;font-family:Consolas;color:#CE9178;mso-ligatures:none">"stringstream
 signal reason: "</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">
</span><span style="font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-ligatures:none">+</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">
</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">reason_ss</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">.</span><span style="font-size:10.5pt;font-family:Consolas;color:#DCDCAA;mso-ligatures:none">str</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">());<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">   
<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#6A9955;mso-ligatures:none">    // #2 using uint32_t</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none"><o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">   
</span><span style="font-size:10.5pt;font-family:Consolas;color:#4EC9B0;mso-ligatures:none">std</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">::</span><span style="font-size:10.5pt;font-family:Consolas;color:#4EC9B0;mso-ligatures:none">shared_ptr</span><span style="font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-ligatures:none"><</span><span style="font-size:10.5pt;font-family:Consolas;color:#4EC9B0;mso-ligatures:none">uint32_t</span><span style="font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-ligatures:none">></span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">
</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">retval_ptr</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">   
</span><span style="font-size:10.5pt;font-family:Consolas;color:#4EC9B0;mso-ligatures:none">uint32_t</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">
</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">reason_uint</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">;<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">   
</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">retval_ptr</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">
</span><span style="font-size:10.5pt;font-family:Consolas;color:#DCDCAA;mso-ligatures:none">=</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">
</span><span style="font-size:10.5pt;font-family:Consolas;color:#4EC9B0;mso-ligatures:none">std</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">::</span><span style="font-size:10.5pt;font-family:Consolas;color:#DCDCAA;mso-ligatures:none">static_pointer_cast</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none"><</span><span style="font-size:10.5pt;font-family:Consolas;color:#4EC9B0;mso-ligatures:none">uint32_t</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">>(</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">args</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">.</span><span style="font-size:10.5pt;font-family:Consolas;color:#DCDCAA;mso-ligatures:none">back</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">());<o:p></o:p></span></p>
<p class="MsoNormal" style="line-height:14.25pt;background:#1F1F1F"><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">   
</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">reason_uint</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">
</span><span style="font-size:10.5pt;font-family:Consolas;color:#D4D4D4;mso-ligatures:none">=</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">
</span><span style="font-size:10.5pt;font-family:Consolas;color:#DCDCAA;mso-ligatures:none">*</span><span style="font-size:10.5pt;font-family:Consolas;color:#9CDCFE;mso-ligatures:none">retval_ptr</span><span style="font-size:10.5pt;font-family:Consolas;color:#CCCCCC;mso-ligatures:none">;<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">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.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Any input will be highly appreciated!<o:p></o:p></p>
<p class="MsoNormal">-Frank H<o:p></o:p></p>
</div>
<span style="font-family: Calibri, Arial, Sans-serif; font-size: 9pt; line-height: 11pt; color: #6e8194;"><strong>Confidentiality Notice</strong>: 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.</span>
</body>
</html>