dhcpcd-dbus introspection patch
Emil Renner Berthing
Wed Jun 03 16:51:54 2009
Hi
I've been playing a bit with dhcpcd-dbus/dhcpcd-ui and I really like the idea
that the dhcp daemon should keep track of the state of your network
interfaces.
However dhcpcd-dbus version 0.4.0 doesn't seem to respond to introspection
properly. It only sends the first sizeof(xml) bytes of the reply, where xml is
a char pointer. That is 4 or 8 bytes depending on your architecture.
Also there are some XML formatting errors, but I've fixed it in the
attached patch.
Next up I'd like to figure out why dhcpcd thinks a network cable is
connected when I first modprobe e1000e, the module of my ethernet card (eth0),
even though cat /sys/class/net/eth0/carrier returns 0.
/Emil
diff -Naur dhcpcd-dbus-0.4.0.old/dhcpcd-dbus.c dhcpcd-dbus-0.4.0/dhcpcd-dbus.c
--- dhcpcd-dbus-0.4.0.old/dhcpcd-dbus.c 2009-04-20 12:09:07.000000000 +0200
+++ dhcpcd-dbus-0.4.0/dhcpcd-dbus.c 2009-06-03 18:17:51.000000000 +0200
@@ -45,7 +45,7 @@
DBusConnection *connection;
-static const char *dhcpcd_introspection_xml =
+static const char dhcpcd_introspection_xml[] =
" <method name=\"GetVersion\">\n"
" <arg name=\"version\" direction=\"out\" type=\"s\"/>\n"
" </method>\n"
@@ -85,10 +85,10 @@
" <arg name=\"config\" direction=\"in\" type=\"aa(ss)\"/>\n"
" </method>\n"
" <signal name=\"Event\">\n"
- " <arg name=\"configuration\" type=\"a{sv}\">\n"
+ " <arg name=\"configuration\" type=\"a{sv}\"/>\n"
" </signal>\n"
" <signal name=\"StatusChanged\">\n"
- " <arg name=\"status\" type=\"s\">\n"
+ " <arg name=\"status\" type=\"s\"/>\n"
" </signal>\n";
static const struct o_dbus const dhos[] = {
@@ -354,10 +354,10 @@
dbus_message_unref(msg);
}
-static const char *introspection_header_xml =
+static const char introspection_header_xml[] =
"<!DOCTYPE node PUBLIC \"-//freedesktop//"
"DTD D-BUS Object Introspection 1.0//EN\"\n"
- "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\";>\n"
+ "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
"<node name=\"" DHCPCD_PATH "\">\n"
" <interface name=\"org.freedesktop.DBus.Introspectable\">\n"
" <method name=\"Introspect\">\n"
@@ -366,7 +366,7 @@
" </interface>\n"
" <interface name=\"" DHCPCD_SERVICE "\">\n";
-static const char *introspection_footer_xml =
+static const char introspection_footer_xml[] =
" </interface>\n"
"</node>\n";
@@ -377,14 +377,15 @@
char *xml;
size_t len;
- len = strlen(introspection_header_xml) +
- strlen(dhcpcd_introspection_xml) +
- strlen(wpa_introspection_xml) +
- strlen(introspection_footer_xml) + 1;
+ len = sizeof(introspection_header_xml) - 1
+ + sizeof(dhcpcd_introspection_xml) - 1
+ + strlen(wpa_introspection_xml)
+ + sizeof(introspection_footer_xml) - 1
+ + 1; /* terminal \0 */
xml = malloc(len);
if (xml == NULL)
return DBUS_HANDLER_RESULT_HANDLED;
- snprintf(xml, sizeof(xml), "%s%s%s%s",
+ snprintf(xml, len, "%s%s%s%s",
introspection_header_xml,
dhcpcd_introspection_xml,
wpa_introspection_xml,
diff -Naur dhcpcd-dbus-0.4.0.old/wpa-dbus.c dhcpcd-dbus-0.4.0/wpa-dbus.c
--- dhcpcd-dbus-0.4.0.old/wpa-dbus.c 2009-02-26 22:05:44.000000000 +0100
+++ dhcpcd-dbus-0.4.0/wpa-dbus.c 2009-06-03 18:05:53.000000000 +0200
@@ -41,7 +41,7 @@
#define S_EINVAL DHCPCD_SERVICE ".InvalidArgument"
#define S_WPA DHCPCD_SERVICE ".WPASupplicantError"
-const char *wpa_introspection_xml =
+const char wpa_introspection_xml[] =
" <method name=\"Scan\">\n"
" <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n"
" </method>\n"
diff -Naur dhcpcd-dbus-0.4.0.old/wpa-dbus.h dhcpcd-dbus-0.4.0/wpa-dbus.h
--- dhcpcd-dbus-0.4.0.old/wpa-dbus.h 2009-02-03 17:46:32.000000000 +0100
+++ dhcpcd-dbus-0.4.0/wpa-dbus.h 2009-06-03 18:06:12.000000000 +0200
@@ -29,7 +29,7 @@
#include <dbus/dbus.h>
-extern const char *wpa_introspection_xml;
+extern const char wpa_introspection_xml[];
DBusHandlerResult
wpa_dbus_handler(DBusConnection *con, DBusMessage *msg);
Archive administrator: postmaster@marples.name