[systemd-commits] 3 commits - src/libsystemd-bus
Lennart Poettering
lennart at kemper.freedesktop.org
Mon Mar 25 18:49:59 PDT 2013
src/libsystemd-bus/bus-internal.h | 2
src/libsystemd-bus/bus-socket.c | 8 +-
src/libsystemd-bus/sd-bus-protocol.h | 42 ++++++++++++
src/libsystemd-bus/sd-bus.c | 116 ++++++++++++++++++++++++++++++++---
src/libsystemd-bus/sd-bus.h | 6 +
5 files changed, 159 insertions(+), 15 deletions(-)
New commits:
commit d65ddaa40e60f91d4b29fdb37224b95675af896f
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Mar 26 01:58:14 2013 +0100
bus: when we are talking to a bus, SCM_CREDS/SCM_SECLABEL are not very useful
diff --git a/src/libsystemd-bus/bus-socket.c b/src/libsystemd-bus/bus-socket.c
index f40aa59..4f1fd94 100644
--- a/src/libsystemd-bus/bus-socket.c
+++ b/src/libsystemd-bus/bus-socket.c
@@ -206,8 +206,8 @@ static int bus_socket_setup(sd_bus *b) {
assert(b);
- /* Enable SO_PASSCRED + SO_PASSEC. We try this on any socket,
- * just in case. This is actually irrelavant for */
+ /* Enable SO_PASSCRED + SO_PASSEC. We try this on any
+ * socket, just in case. */
one = 1;
setsockopt(b->fd, SOL_SOCKET, SO_PASSCRED, &one, sizeof(one));
setsockopt(b->fd, SOL_SOCKET, SO_PASSSEC, &one, sizeof(one));
@@ -467,8 +467,8 @@ static int bus_socket_make_message(sd_bus *bus, size_t size, sd_bus_message **m)
r = bus_message_from_malloc(bus->rbuffer, size,
bus->fds, bus->n_fds,
- bus->ucred_valid ? &bus->ucred : NULL,
- bus->label[0] ? bus->label : NULL,
+ !bus->bus_client && bus->ucred_valid ? &bus->ucred : NULL,
+ !bus->bus_client && bus->label[0] ? bus->label : NULL,
&t);
if (r < 0) {
free(b);
commit 0a72c2bdef69bae5f4677ee563019e3ccbd3dfe2
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Mar 26 01:54:37 2013 +0100
bus: automatically generate minimal introspection data to find installed objects
diff --git a/src/libsystemd-bus/sd-bus-protocol.h b/src/libsystemd-bus/sd-bus-protocol.h
index f9a5217..ac4d0b1 100644
--- a/src/libsystemd-bus/sd-bus-protocol.h
+++ b/src/libsystemd-bus/sd-bus-protocol.h
@@ -100,4 +100,46 @@ enum {
_SD_BUS_MESSAGE_HEADER_MAX
};
+#define SD_BUS_INTROSPECT_DOCTYPE \
+ "<!DOCTYPE node PUBLIC \"-//freedesktop//DTD D-BUS Object Introspection 1.0//EN\"\n" \
+ "\"http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd\">\n"
+
+#define SD_BUS_INTROSPECT_INTERFACE_PROPERTIES \
+ " <interface name=\"org.freedesktop.DBus.Properties\">\n" \
+ " <method name=\"Get\">\n" \
+ " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
+ " <arg name=\"property\" direction=\"in\" type=\"s\"/>\n" \
+ " <arg name=\"value\" direction=\"out\" type=\"v\"/>\n" \
+ " </method>\n" \
+ " <method name=\"GetAll\">\n" \
+ " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
+ " <arg name=\"properties\" direction=\"out\" type=\"a{sv}\"/>\n" \
+ " </method>\n" \
+ " <method name=\"Set\">\n" \
+ " <arg name=\"interface\" direction=\"in\" type=\"s\"/>\n" \
+ " <arg name=\"property\" direction=\"in\" type=\"s\"/>\n" \
+ " <arg name=\"value\" direction=\"in\" type=\"v\"/>\n" \
+ " </method>\n" \
+ " <signal name=\"PropertiesChanged\">\n" \
+ " <arg type=\"s\" name=\"interface\"/>\n" \
+ " <arg type=\"a{sv}\" name=\"changed_properties\"/>\n" \
+ " <arg type=\"as\" name=\"invalidated_properties\"/>\n" \
+ " </signal>\n" \
+ " </interface>\n"
+
+#define SD_BUS_INTROSPECT_INTERFACE_INTROSPECTABLE \
+ " <interface name=\"org.freedesktop.DBus.Introspectable\">\n" \
+ " <method name=\"Introspect\">\n" \
+ " <arg name=\"data\" type=\"s\" direction=\"out\"/>\n" \
+ " </method>\n" \
+ " </interface>\n"
+
+#define SD_BUS_INTROSPECT_INTERFACE_PEER \
+ "<interface name=\"org.freedesktop.DBus.Peer\">\n" \
+ " <method name=\"Ping\"/>\n" \
+ " <method name=\"GetMachineId\">\n" \
+ " <arg type=\"s\" name=\"machine_uuid\" direction=\"out\"/>\n" \
+ " </method>\n" \
+ "</interface>\n"
+
#endif
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 6a76db9..c82b738 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -30,6 +30,7 @@
#include "util.h"
#include "macro.h"
#include "strv.h"
+#include "set.h"
#include "sd-bus.h"
#include "bus-internal.h"
@@ -1553,7 +1554,10 @@ static int process_object(sd_bus *bus, sd_bus_message *m) {
}
}
- if (!found)
+ /* We found some handlers but none wanted to take this, then
+ * return this -- with one exception, we can handle
+ * introspection minimally ourselves */
+ if (!found || sd_bus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect"))
return 0;
sd_bus_error_set(&error,
@@ -1571,6 +1575,98 @@ static int process_object(sd_bus *bus, sd_bus_message *m) {
return 1;
}
+static int process_introspect(sd_bus *bus, sd_bus_message *m) {
+ _cleanup_bus_message_unref_ sd_bus_message *reply = NULL;
+ _cleanup_free_ char *introspection = NULL;
+ _cleanup_set_free_free_ Set *s = NULL;
+ _cleanup_fclose_ FILE *f = NULL;
+ struct object_callback *c;
+ Iterator i;
+ size_t size = 0;
+ char *node;
+ int r;
+
+ assert(bus);
+ assert(m);
+
+ if (!sd_bus_message_is_method_call(m, "org.freedesktop.DBus.Introspectable", "Introspect"))
+ return 0;
+
+ if (!m->path)
+ return 0;
+
+ s = set_new(string_hash_func, string_compare_func);
+ if (!s)
+ return -ENOMEM;
+
+ HASHMAP_FOREACH(c, bus->object_callbacks, i) {
+ const char *e;
+ char *a, *p;
+
+ if (streq(c->path, "/"))
+ continue;
+
+ if (streq(m->path, "/"))
+ e = c->path;
+ else {
+ e = startswith(c->path, m->path);
+ if (!e || *e != '/')
+ continue;
+ }
+
+ a = strdup(e+1);
+ if (!a)
+ return -ENOMEM;
+
+ p = strchr(a, '/');
+ if (p)
+ *p = 0;
+
+ r = set_put(s, a);
+ if (r < 0) {
+ free(a);
+
+ if (r != -EEXIST)
+ return r;
+ }
+ }
+
+ f = open_memstream(&introspection, &size);
+ if (!f)
+ return -ENOMEM;
+
+ fputs(SD_BUS_INTROSPECT_DOCTYPE, f);
+ fputs("<node>\n", f);
+ fputs(SD_BUS_INTROSPECT_INTERFACE_PEER, f);
+ fputs(SD_BUS_INTROSPECT_INTERFACE_INTROSPECTABLE, f);
+
+ while ((node = set_steal_first(s))) {
+ fprintf(f, " <node name=\"%s\"/>\n", node);
+ free(node);
+ }
+
+ fputs("</node>\n", f);
+
+ fflush(f);
+
+ if (ferror(f))
+ return -ENOMEM;
+
+ r = sd_bus_message_new_method_return(bus, m, &reply);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_message_append(reply, "s", introspection);
+ if (r < 0)
+ return r;
+
+ r = sd_bus_send(bus, reply, NULL);
+ if (r < 0)
+ return r;
+
+ return 1;
+}
+
static int process_message(sd_bus *bus, sd_bus_message *m) {
int r;
@@ -1589,7 +1685,11 @@ static int process_message(sd_bus *bus, sd_bus_message *m) {
if (r != 0)
return r;
- return process_object(bus, m);
+ r = process_object(bus, m);
+ if (r != 0)
+ return r;
+
+ return process_introspect(bus, m);
}
static int process_running(sd_bus *bus, sd_bus_message **ret) {
diff --git a/src/libsystemd-bus/sd-bus.h b/src/libsystemd-bus/sd-bus.h
index d680270..08c5e54 100644
--- a/src/libsystemd-bus/sd-bus.h
+++ b/src/libsystemd-bus/sd-bus.h
@@ -29,9 +29,10 @@
#include "sd-bus-protocol.h"
/* TODO:
- * - implicitly add stub introspection calls
* - server side
- * - allow installing match callbacks,
+ * - allow installing match callbacks
+ * - anonymous auth
+ * - default policy
*
* Later:
* - add page donation logic
commit 94bbf1ba6d2c8f3c64879c7f1af114ca25edeb8f
Author: Lennart Poettering <lennart at poettering.net>
Date: Tue Mar 26 00:36:43 2013 +0100
bus: rename send_hello flag to bus_cient
This way we can hide more than just the hello logic behind this flag,
for example, later on automatic match management.
diff --git a/src/libsystemd-bus/bus-internal.h b/src/libsystemd-bus/bus-internal.h
index 78d955d..c25a208 100644
--- a/src/libsystemd-bus/bus-internal.h
+++ b/src/libsystemd-bus/bus-internal.h
@@ -72,7 +72,7 @@ struct sd_bus {
bool negotiate_fds:1;
bool can_fds:1;
- bool send_hello:1;
+ bool bus_client:1;
bool ucred_valid:1;
void *rbuffer;
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 6eab4a5..6a76db9 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -176,13 +176,13 @@ int sd_bus_set_exec(sd_bus *bus, const char *path, char *const argv[]) {
return 0;
}
-int sd_bus_set_hello(sd_bus *bus, int b) {
+int sd_bus_set_bus_client(sd_bus *bus, int b) {
if (!bus)
return -EINVAL;
if (bus->state != BUS_UNSET)
return -EPERM;
- bus->send_hello = !!b;
+ bus->bus_client = !!b;
return 0;
}
@@ -230,7 +230,7 @@ static int bus_send_hello(sd_bus *bus) {
assert(bus);
- if (!bus->send_hello)
+ if (!bus->bus_client)
return 0;
r = sd_bus_message_new_method_call(
@@ -253,7 +253,7 @@ static int bus_send_hello(sd_bus *bus) {
int bus_start_running(sd_bus *bus) {
assert(bus);
- if (bus->send_hello) {
+ if (bus->bus_client) {
bus->state = BUS_HELLO;
return 1;
}
@@ -753,7 +753,7 @@ int sd_bus_open_system(sd_bus **ret) {
b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + sizeof("/run/dbus/system_bus_socket") - 1;
}
- b->send_hello = true;
+ b->bus_client = true;
r = sd_bus_start(b);
if (r < 0)
@@ -803,7 +803,7 @@ int sd_bus_open_user(sd_bus **ret) {
b->sockaddr_size = offsetof(struct sockaddr_un, sun_path) + l + 4;
}
- b->send_hello = true;
+ b->bus_client = true;
r = sd_bus_start(b);
if (r < 0)
diff --git a/src/libsystemd-bus/sd-bus.h b/src/libsystemd-bus/sd-bus.h
index a15cc26..d680270 100644
--- a/src/libsystemd-bus/sd-bus.h
+++ b/src/libsystemd-bus/sd-bus.h
@@ -31,6 +31,7 @@
/* TODO:
* - implicitly add stub introspection calls
* - server side
+ * - allow installing match callbacks,
*
* Later:
* - add page donation logic
@@ -58,7 +59,7 @@ int sd_bus_new(sd_bus **ret);
int sd_bus_set_address(sd_bus *bus, const char *address);
int sd_bus_set_fd(sd_bus *bus, int fd);
int sd_bus_set_exec(sd_bus *bus, const char *path, char *const argv[]);
-int sd_bus_set_hello(sd_bus *bus, int b);
+int sd_bus_set_bus_client(sd_bus *bus, int b);
int sd_bus_set_negotiate_fds(sd_bus *bus, int b);
int sd_bus_start(sd_bus *ret);
More information about the systemd-commits
mailing list