<p dir="ltr" style=""><font size="2"><font size="2">Hello,<br><br>I was trying to trigger some task when DHCP does an DHCPACK on an IP. This I thought of achieving by using dbus signals.<br><br>I picked up the code from the following page --<font size="2"> </font></font><font size="2"><a href="https://webmail.wipro.com/exchweb/bin/redir.asp?URL=http://dbus.freedesktop.org/doc/dbus/libdbus-tutorial.html" target="_blank">http://dbus.freedesktop.org/doc/dbus/libdbus-tutorial.html</a></font><font size="3"><font size="2"> Read the &quot;Receiving a Signal&quot; section and modified it to my own requirements.<br>
<br>As
for sending the signal I used the dbus-send command from DHCP server (
Inserting few statements in ISC DHCP&#39;s dhcpd.conf file by which on
commit or on release the dbus-send command in triggered )<br>I am
facing a problem, where some Signals do not reach the dbus server
program. It happens once in 40-50 signals. But my application would not
want to lose the Signals.<br><br>Part of my Code</font><br></font></font><font size="2">dbus-server.c</font></p>
<address dir="ltr" style=""><font face="Courier New" size="2">#include &lt;dbus/dbus.h&gt;<br>#include &lt;stdbool.h&gt;<br>#include &lt;unistd.h&gt;<br>#include &lt;stdio.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include&lt;string.h&gt;</font></address><font size="2">
</font><address dir="ltr" style=""><font size="2"><font face="Courier New">void receive()<br>{<br>   DBusMessage* msg;<br>   DBusMessageIter args;<br>   DBusConnection* conn;<br>   DBusError err;<br>   int ret, ipcheck;<br>
   char *sigvalue1, *message;<br>   dbus_bool_t sigvalue2;<br>   bool request_type;<br>   static int sequence_number = 0;<br>   dbus_error_init(&amp;err);<br>   conn = dbus_bus_get(DBUS_BUS_SYSTEM, &amp;err);<br>   ret = dbus_bus_request_name(conn, &quot;com.example.app.Sink&quot;,  DBUS_NAME_FLAG_REPLACE_EXISTING , &amp;err);<br>
   dbus_bus_add_match(conn, &quot;type=&#39;signal&#39;,interface=&#39;com.example.app.Signal&#39;&quot;, &amp;err);<br>   dbus_connection_flush(conn);<br>   // All the checks were made to see if the connection is established. </font></font></address>
<address dir="ltr" style=""><font size="2"><font face="Courier New">   </font><font face="Courier New">while (true)<br>   {<br>       dbus_connection_read_write(conn, 0);<br>       msg = dbus_connection_pop_message(conn);<br>
       if (NULL == msg) {<br>           sleep(1);<br>           continue;<br>       }<br>       if (dbus_message_is_signal(msg, &quot;com.example.app.Signal&quot;, &quot;Test&quot;))<br>       {<br>           fprintf(stdout,&quot;\n#####################################################\n&quot;);<br>
           sequence_number++;<br>           fprintf(stdout,&quot;\nSignal Sequence Number: %d\n&quot;,sequence_number);<br>           fflush(stdout);<br>           if (dbus_message_iter_init(msg, &amp;args))<br>           {<br>
                dbus_message_iter_get_basic(&amp;args,&amp;sigvalue1);<br>                dbus_message_iter_next(&amp;args);<br>                dbus_message_iter_get_basic(&amp;args,&amp;sigvalue2);<br>                fflush(stdout);<br>
                if( sigvalue2 )<br>                    request_type=true;<br>                else<br>                    request_type=false;<br>                if ( request_type )<br>                {<br>                    // DO SOMETHING<br>
                    dbus_message_unref(msg);<br>                    continue;<br>                }<br>                else<br>                {<br>                    // DO SOMETHING ELSE<br>                    dbus_message_unref(msg);<br>
                    continue;<br>                }<br>           }<br>       }<br>       dbus_message_unref(msg);<br>    } // end of while loop<br> }<br></font></font></address>
<p dir="ltr" style=""><font size="2"><br><font size="3">A dbus-send command is sent using --</font></font></p><font size="2"><font size="3">
</font><address><font face="Courier New">dbus-send
--system --dest=&#39;com.example.app.Sink&#39; --type=signal
/com/example/app/Signal com.example.app.Signal.Test
string:&quot;192.168.47.100&quot; boolean:true</font></address>
<address><font face="Courier New"><font face="Times New Roman" size="3">or<br></font><br>dbus-send
--system --dest=&#39;com.example.app.Sink&#39; --type=signal
/com/example/app/Signal com.example.app.Signal.Test
string:&quot;192.168.47.100&quot; boolean:false<br></font></address>
<p><font size="3">I have an xml conf file in /etc/dbus-1/system.d/app.conf</font></p></font>
<address><font face="Courier New" size="2">&lt;!DOCTYPE busconfig PUBLIC &quot;-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN&quot;<br> &quot;</font><a href="https://webmail.wipro.com/exchweb/bin/redir.asp?URL=http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd" target="_blank"><font face="Courier New" size="2">http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd</font></a><font face="Courier New" size="2">&quot;&gt;<br>
&lt;busconfig&gt;<br>    &lt;policy user=&quot;root&quot;&gt;<br>            &lt;allow own=&quot;com.example.app.Source&quot;/&gt;<br>            &lt;allow send_interface=&quot;com.example.app.Signal&quot;/&gt;<br>            &lt;allow send_destination=&quot;com.example.app.Sink&quot;/&gt;<br>
    &lt;/policy&gt;<br>    &lt;policy user=&quot;root&quot;&gt;<br>            &lt;allow own=&quot;com.example.app.Sink&quot;/&gt;<br>    &lt;/policy&gt;<br>    &lt;policy context=&quot;default&quot;&gt;<br>            &lt;deny own=&quot;com.example.app.Source&quot;/&gt;<br>
            &lt;deny send_destination=&quot;com.example.app.Sink&quot;/&gt;<br>            &lt;deny send_interface=&quot;com.example.app.Signal&quot;/&gt;<br>    &lt;/policy&gt;<br>&lt;/busconfig&gt;<br></font></address>
<p><br>I modified the dbus-server.c code to change the following</p><font size="2">
<p><i><font face="Courier New">dbus_connection_read_write(conn, 0);  </font></i></p>
<p><i><font face="Courier New">dbus_connection_read_write(conn, 1);  </font></i></p>
<p><i><font face="Courier New">dbus_connection_read_write(conn, 2);</font></i></p><p></p>Apart from that I also tried<br></font><i><font size="2"><font face="Courier New">if (NULL == msg) {<br>    usleep(1000);<br>    continue;<br>
}</font></font></i><br><font size="2">
<p><font face="Courier New"><font face="Times New Roman" size="3">But
none had the required effect. Is there any glitch which is left which
makes it lose the Signal ? I have picked most part of the code from the
example provided on the tutorial, so I assume it should work. Please
provide any leads as to what is making the Signal to be lost.</font></font></p></font><br>-- <br>Regards,<br>Abhijeet<br>