<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 "Receiving a Signal" 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'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 <dbus/dbus.h><br>#include <stdbool.h><br>#include <unistd.h><br>#include <stdio.h><br>#include <stdlib.h><br>#include<string.h></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(&err);<br> conn = dbus_bus_get(DBUS_BUS_SYSTEM, &err);<br> ret = dbus_bus_request_name(conn, "com.example.app.Sink", DBUS_NAME_FLAG_REPLACE_EXISTING , &err);<br>
dbus_bus_add_match(conn, "type='signal',interface='com.example.app.Signal'", &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, "com.example.app.Signal", "Test"))<br> {<br> fprintf(stdout,"\n#####################################################\n");<br>
sequence_number++;<br> fprintf(stdout,"\nSignal Sequence Number: %d\n",sequence_number);<br> fflush(stdout);<br> if (dbus_message_iter_init(msg, &args))<br> {<br>
dbus_message_iter_get_basic(&args,&sigvalue1);<br> dbus_message_iter_next(&args);<br> dbus_message_iter_get_basic(&args,&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='com.example.app.Sink' --type=signal
/com/example/app/Signal com.example.app.Signal.Test
string:"192.168.47.100" boolean:true</font></address>
<address><font face="Courier New"><font face="Times New Roman" size="3">or<br></font><br>dbus-send
--system --dest='com.example.app.Sink' --type=signal
/com/example/app/Signal com.example.app.Signal.Test
string:"192.168.47.100" 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"><!DOCTYPE busconfig PUBLIC "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"<br> "</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">"><br>
<busconfig><br> <policy user="root"><br> <allow own="com.example.app.Source"/><br> <allow send_interface="com.example.app.Signal"/><br> <allow send_destination="com.example.app.Sink"/><br>
</policy><br> <policy user="root"><br> <allow own="com.example.app.Sink"/><br> </policy><br> <policy context="default"><br> <deny own="com.example.app.Source"/><br>
<deny send_destination="com.example.app.Sink"/><br> <deny send_interface="com.example.app.Signal"/><br> </policy><br></busconfig><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>