<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=us-ascii">
<meta name="Generator" content="Microsoft Exchange Server">
<!-- converted from rtf -->
<style><!-- .EmailQuote { margin-left: 1pt; padding-left: 4pt; border-left: #800000 2px solid; } --></style>
</head>
<body>
<font face="Arial, sans-serif" size="2">
<div>Hello,</div>
<div>I have the following simple C application which does both continuously sending messages to a dbus Server and receiving asynchronous messages from this server using dbus signals time by time.</div>
<div>Application crashes after having sent  2 -30 messages to the server with segmentation fault.</div>
<div><font face="Monospace" color="#005032">Application also works fine, when it doesn’t call g_main_loop_run in the end. But then no signals can be received.</font></div>
<div>After that I used <font face="Monospace" color="#005032">g_timeout_add(500,f_DbusSend,NULL)</font><font face="Monospace" color="#005032"> </font><font face="Monospace" color="#005032">to send the messages and it works.</font></div>
<div><font face="Monospace" color="#005032">Has anybody got an idea what I’m doing wrong? Do I have to sync dbus_proxy_calls with g_main_loop? If so, has anybody an idea how to do that?</font></div>
<div><font face="Calibri, sans-serif" size="2"> </font></div>
<div><font face="Monospace" color="#7F0055"><b>#include</b><font color="#000000"> </font><font color="#2A00FF"><stdio.h></font></font></div>
<div><font face="Monospace" color="#7F0055"><b>#include</b><font color="#000000"> </font><font color="#2A00FF"><unistd.h></font></font></div>
<div><font face="Monospace" color="#7F0055"><b>#include</b><font color="#000000"> </font><font color="#2A00FF"><pthread.h></font></font></div>
<div><font face="Monospace" color="#7F0055"><b>#include</b><font color="#000000"> </font><font color="#2A00FF"><glib.h></font></font></div>
<div><font face="Monospace" color="#7F0055"><b>#include</b><font color="#000000"> </font><font color="#2A00FF"><dbus/dbus-glib.h></font></font></div>
<div><font face="Calibri, sans-serif" size="2"> </font></div>
<div><font face="Monospace" color="#7F0055"><b>static</b><font color="#000000"> </font><font color="#005032">GMainLoop</font><font color="#000000">* z_o_MainLoop=NULL;</font></font></div>
<div><font face="Monospace" color="#7F0055"><b>static</b><font color="#000000"> </font><font color="#005032">DBusGConnection</font><font color="#000000"> *bus = NULL;</font></font></div>
<div><font face="Monospace" color="#005032">DBusGProxy<font color="#000000"> *z_o_DBusGProxy = NULL;</font></font></div>
<div><font face="Monospace" color="#7F0055"><b>static</b><font color="#000000"> </font><font color="#005032">pthread_t</font><font color="#000000"> o_GMainLoopThreadId;</font></font></div>
<div><font face="Monospace" color="#7F0055"><u><b>static</b></u><font color="#000000"><u> </u></font><font color="#005032"><u>pthread_t</u></font><font color="#000000"><u> o_SendThreadId;</u></font></font></div>
<div><font face="Monospace" color="#7F0055"><b>static</b><font color="#000000"> </font><font color="#005032">GError</font><font color="#000000">* error;</font></font></div>
<div><font face="Calibri, sans-serif" size="2"> </font></div>
<div><font face="Monospace" color="#7F0055"><b>void</b><font color="#000000">* </font><font color="#000000"><b>f_RunGMainLoop</b></font><font color="#000000">(</font><b>void</b><font color="#000000">* z_MainLoopAdr)</font></font></div>
<div><font face="Monospace">{</font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#642880"><b>g_main_loop_run</b></font><font face="Monospace" size="2">(z_o_MainLoop);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#642880"><b>printf</b></font><font face="Monospace" size="2">(</font><font face="Monospace" size="2" color="#2A00FF">"f_RunMailLoop finished\n"</font><font face="Monospace" size="2">);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#7F0055"><b>return</b></font><font face="Monospace" size="2"> z_MainLoopAdr;</font></font></div>
<div><font face="Monospace">}</font></div>
<div><font face="Monospace" color="#005032">gboolean<font color="#000000"> </font><font color="#000000"><b>f_DbusSend</b></font><font color="#000000">(</font><font color="#7F0055"><b>void</b></font><font color="#000000">* z_o_UserData)</font></font></div>
<div><font face="Monospace">{</font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#7F0055"><b>int</b></font><font face="Monospace" size="2"> i_PrgNr = 0, i_counterOK=1,i_counterNOK=2;</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#3F7F5F">//while(1){</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                <font face="Monospace" size="2" color="#642880"><b>printf</b></font><font face="Monospace" size="2">(</font><font face="Monospace" size="2" color="#2A00FF">"Sending Counter %d, </font><font face="Monospace" size="2" color="#2A00FF"><u>Ok</u></font><font face="Monospace" size="2" color="#2A00FF">:
%d, </font><font face="Monospace" size="2" color="#2A00FF"><u>Nok</u></font><font face="Monospace" size="2" color="#2A00FF">: %d, </font><font face="Monospace" size="2" color="#2A00FF"><u>Proxy</u></font><font face="Monospace" size="2" color="#2A00FF">: %d...
"</font><font face="Monospace" size="2">, i_PrgNr,i_counterOK,i_counterNOK, *z_o_DBusGProxy);</font></font></div>
<div><font face="Calibri, sans-serif" size="2"> </font></div>
<div><font face="Calibri, sans-serif" size="2">                <font face="Monospace" size="2" color="#7F0055"><b>bool</b></font><font face="Monospace" size="2"> b_RetVal = </font><font face="Monospace" size="2" color="#642880"><b>dbus_g_proxy_call</b></font><font face="Monospace" size="2">(z_o_DBusGProxy,
</font><font face="Monospace" size="2" color="#2A00FF">"</font><font face="Monospace" size="2" color="#2A00FF"><u>fbatchcntrset</u></font><font face="Monospace" size="2" color="#2A00FF">"</font><font face="Monospace" size="2">,&error, G_TYPE_INT, i_PrgNr,</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                                <font face="Monospace" size="2">                          G_TYPE_INT, i_counterOK++,</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                                <font face="Monospace" size="2">                          G_TYPE_INT, i_counterNOK,</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                                <font face="Monospace" size="2">                          </font><font face="Monospace" size="2"><span style="background-color:#C0C0C0">G_TYPE_INVALID</span></font><font face="Monospace" size="2">,
</font><font face="Monospace" size="2"><span style="background-color:#C0C0C0">G_TYPE_INVALID</span></font><font face="Monospace" size="2">);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                <font face="Monospace" size="2" color="#7F0055"><b>if</b></font><font face="Monospace" size="2">(b_RetVal){</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                        <font face="Monospace" size="2" color="#642880"><b>printf</b></font><font face="Monospace" size="2">(</font><font face="Monospace" size="2" color="#2A00FF">"OK\n"</font><font face="Monospace" size="2">);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                <font face="Monospace" size="2">}</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                <font face="Monospace" size="2" color="#7F0055"><b>else</b></font><font face="Monospace" size="2">{</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                        <font face="Monospace" size="2" color="#642880"><b>printf</b></font><font face="Monospace" size="2">(</font><font face="Monospace" size="2" color="#2A00FF">"Error - %s\n"</font><font face="Monospace" size="2">,
error-></font><font face="Monospace" size="2" color="#0000C0">message</font><font face="Monospace" size="2">);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                        <font face="Monospace" size="2" color="#642880"><b>g_error_free</b></font><font face="Monospace" size="2">(error);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                <font face="Monospace" size="2">}</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                <font face="Monospace" size="2" color="#3F7F5F">/*</font><font face="Monospace" size="2" color="#3F7F5F"><u>usleep</u></font><font face="Monospace" size="2" color="#3F7F5F">(500000);</font></font></div>
<div><font face="Calibri, sans-serif" size="2" color="#3F7F5F">        <font face="Monospace" size="2">}*/</font></font></div>
<div><font face="Monospace"><u>}</u></font></div>
<div><font face="Monospace" color="#3F7F5F">//signal <u>callback</u></font></div>
<div><font face="Monospace" color="#7F0055"><b>void</b><font color="#000000"> </font><font color="#000000"><b>f_DbusCallbackCfgFileChanged</b></font><font color="#000000">(</font><font color="#005032">DBusGProxy</font><font color="#000000"> *proxy, </font><b>const</b><font color="#000000">
</font><b>char</b><font color="#000000">* z_c_FilePath, </font><font color="#005032">gpointer</font><font color="#000000"> user_data)</font></font></div>
<div><font face="Monospace">{</font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#642880"><b>printf</b></font><font face="Monospace" size="2">(</font><font face="Monospace" size="2" color="#2A00FF">"f_DbusCallbackCfgFileChanged - %s\n"</font><font face="Monospace" size="2">,
z_c_FilePath);</font></font></div>
<div><font face="Monospace">}</font></div>
<div><font face="Monospace" color="#7F0055"><b>int</b><font color="#000000"> </font><font color="#000000"><b>main</b></font><font color="#000000"> (</font><b>void</b><font color="#000000">)</font></font></div>
<div><font face="Monospace">{</font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#642880"><b>g_type_init</b></font><font face="Monospace" size="2"> ();</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#3F7F5F">//new main loop</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2">z_o_MainLoop = </font><font face="Monospace" size="2" color="#642880"><b>g_main_loop_new</b></font><font face="Monospace" size="2">(NULL, FALSE);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2">bus = </font><font face="Monospace" size="2" color="#642880"><b>dbus_g_bus_get</b></font><font face="Monospace" size="2">(</font><font face="Monospace" size="2" color="#0000C0"><i>DBUS_BUS_SYSTEM</i></font><font face="Monospace" size="2">,
&error);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#7F0055"><b>if</b></font><font face="Monospace" size="2"> (!bus){</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                <font face="Monospace" size="2" color="#642880"><b>printf</b></font><font face="Monospace" size="2">(</font><font face="Monospace" size="2" color="#2A00FF">"dbus_g_bus_get - %s\n"</font><font face="Monospace" size="2">,error-></font><font face="Monospace" size="2" color="#0000C0">message</font><font face="Monospace" size="2">);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                <font face="Monospace" size="2" color="#642880"><b>g_error_free</b></font><font face="Monospace" size="2">(error);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                <font face="Monospace" size="2" color="#642880"><b>g_main_loop_unref</b></font><font face="Monospace" size="2">(z_o_MainLoop);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                <font face="Monospace" size="2" color="#7F0055"><b>return</b></font><font face="Monospace" size="2"> -1;</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2">}</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#642880"><b>printf</b></font><font face="Monospace" size="2">(</font><font face="Monospace" size="2" color="#2A00FF">"dbus_g_bus_get - OK\n"</font><font face="Monospace" size="2">);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2">z_o_DBusGProxy = </font><font face="Monospace" size="2" color="#642880"><b>dbus_g_proxy_new_for_name</b></font><font face="Monospace" size="2">(bus, </font><font face="Monospace" size="2" color="#2A00FF">"com.rexroth.akku.SysService"</font><font face="Monospace" size="2">,
</font><font face="Monospace" size="2" color="#2A00FF">"/SysObj"</font><font face="Monospace" size="2">, </font><font face="Monospace" size="2" color="#2A00FF">"com.rexroth.akku.SysInterface"</font><font face="Monospace" size="2">);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#7F0055"><b>if</b></font><font face="Monospace" size="2">( z_o_DBusGProxy==NULL){</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                <font face="Monospace" size="2" color="#642880"><b>printf</b></font><font face="Monospace" size="2">(</font><font face="Monospace" size="2" color="#2A00FF">"dbus_g_proxy_new_for_name - error\n"</font><font face="Monospace" size="2">);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                <font face="Monospace" size="2" color="#642880"><b>g_main_loop_unref</b></font><font face="Monospace" size="2">(z_o_MainLoop);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                <font face="Monospace" size="2" color="#7F0055"><b>return</b></font><font face="Monospace" size="2"> -1;</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2">}</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#642880"><b>printf</b></font><font face="Monospace" size="2">(</font><font face="Monospace" size="2" color="#2A00FF">"dbus_g_proxy_new_for_name_owner - OK\n"</font><font face="Monospace" size="2">);</font></font></div>
<div><font face="Calibri, sans-serif" size="2"> </font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#3F7F5F">//register </font><font face="Monospace" size="2" color="#3F7F5F"><u>config</u></font><font face="Monospace" size="2" color="#3F7F5F"> file changed signal</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#642880"><b>dbus_g_proxy_add_signal</b></font><font face="Monospace" size="2">(z_o_DBusGProxy, </font><font face="Monospace" size="2" color="#2A00FF">"</font><font face="Monospace" size="2" color="#2A00FF"><u>cfgfilechanged</u></font><font face="Monospace" size="2" color="#2A00FF">"</font><font face="Monospace" size="2">,
G_TYPE_STRING, </font><font face="Monospace" size="2"><span style="background-color:#C0C0C0">G_TYPE_INVALID</span></font><font face="Monospace" size="2">);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#642880"><b>dbus_g_proxy_connect_signal</b></font><font face="Monospace" size="2">(z_o_DBusGProxy, </font><font face="Monospace" size="2" color="#2A00FF">"</font><font face="Monospace" size="2" color="#2A00FF"><u>cfgfilechanged</u></font><font face="Monospace" size="2" color="#2A00FF">"</font><font face="Monospace" size="2">,  
G_CALLBACK(&f_DbusCallbackCfgFileChanged), NULL, NULL);</font></font></div>
<div><font face="Calibri, sans-serif" size="2"> </font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#3F7F5F">//run </font><font face="Monospace" size="2" color="#3F7F5F"><u>mainloop</u></font><font face="Monospace" size="2" color="#3F7F5F"> in separate thread</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#642880"><b>pthread_create</b></font><font face="Monospace" size="2">(&o_GMainLoopThreadId,NULL,f_RunGMainLoop,z_o_MainLoop);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#3F7F5F">//</font><font face="Monospace" size="2" color="#3F7F5F"><u>continously</u></font><font face="Monospace" size="2" color="#3F7F5F"> send </font><font face="Monospace" size="2" color="#3F7F5F"><u>msg</u></font><font face="Monospace" size="2" color="#3F7F5F">
to server</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#3F7F5F">//g_timeout_add(500,f_DbusSend,NULL);</font></font></div>
<div><font face="Calibri, sans-serif" size="2"> </font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#3F7F5F">//g_main_loop_run(z_o_MainLoop);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#7F0055"><b>while</b></font><font face="Monospace" size="2">(1){</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                <font face="Monospace" size="2">f_DbusSend(NULL);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">                <font face="Monospace" size="2" color="#642880"><b>usleep</b></font><font face="Monospace" size="2">(500000);</font></font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2">}</font></font></div>
<div><font face="Calibri, sans-serif" size="2"> </font></div>
<div><font face="Calibri, sans-serif" size="2">        <font face="Monospace" size="2" color="#7F0055"><b>return</b></font><font face="Monospace" size="2"> 0;</font></font></div>
<div><font face="Monospace">}</font></div>
<div><font face="Calibri, sans-serif" size="2"> </font></div>
</font>
</body>
</html>