[systemd-commits] 5 commits - TODO src/libsystemd-bus src/systemd
Lennart Poettering
lennart at kemper.freedesktop.org
Fri Dec 13 06:30:45 PST 2013
TODO | 2
src/libsystemd-bus/bus-internal.h | 1
src/libsystemd-bus/bus-kernel.c | 1
src/libsystemd-bus/libsystemd-bus.sym | 2
src/libsystemd-bus/sd-bus.c | 143 ++++++++++++++++++++--------------
src/libsystemd-bus/sd-event.c | 55 +++++++++++++
src/systemd/sd-event.h | 3
7 files changed, 150 insertions(+), 57 deletions(-)
New commits:
commit 9f97c93671554dd3c46588b7c31031d26440ba34
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Dec 13 05:14:47 2013 +0100
update TODO
diff --git a/TODO b/TODO
index 0ea4109..7986497 100644
--- a/TODO
+++ b/TODO
@@ -127,11 +127,9 @@ Features:
- kdbus: matches against source or destination pids for an "strace -p"-like feel. Problem: The PID info needs to be available in userspace too...
- kdbus: we need a way to distuingish messages we got due to monitoring from normal messages, since we want to bind methods only to the latter
- kdbus: when we do "systemctl daemon-reexec" the call doesn't get properly cancelled
- - figure out what to do when fields in the kdbus header and in the payload header do not match
- longer term:
* priority queues
* priority inheritance
- - fix sd-event hookup when we connect to multiple servers one after the other
* sd-event
- allow multiple signal handlers per signal?
diff --git a/src/libsystemd-bus/bus-kernel.c b/src/libsystemd-bus/bus-kernel.c
index 4b69480..650e6b9 100644
--- a/src/libsystemd-bus/bus-kernel.c
+++ b/src/libsystemd-bus/bus-kernel.c
@@ -834,6 +834,7 @@ static int bus_kernel_make_message(sd_bus *bus, struct kdbus_msg *k) {
if (r < 0)
goto fail;
+ /* Override information from the user header with data from the kernel */
if (k->src_id == KDBUS_SRC_ID_KERNEL)
m->sender = "org.freedesktop.DBus";
else {
commit 6d6f4904aaa5047370949093cd63d0fc2a4a83b8
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Dec 13 05:13:31 2013 +0100
bus: when a connection terminated use ECONNRESET as error
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 9ab4367..932bf22 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -2236,9 +2236,11 @@ _public_ int sd_bus_process(sd_bus *bus, sd_bus_message **ret) {
switch (bus->state) {
case BUS_UNSET:
- case BUS_CLOSED:
return -ENOTCONN;
+ case BUS_CLOSED:
+ return -ECONNRESET;
+
case BUS_OPENING:
r = bus_socket_process_opening(bus);
if (r == -ECONNRESET || r == -EPIPE || r == -ESHUTDOWN) {
commit 1e05d493b729beaa947b449a60ed387ee77e5da7
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Dec 13 05:12:46 2013 +0100
bus: rework how we attach fds to event loops
When trying a couple of addresses one after the other, make sure to
reattach the fds to the event loop.
diff --git a/src/libsystemd-bus/bus-internal.h b/src/libsystemd-bus/bus-internal.h
index df9a0b5..a599e5a 100644
--- a/src/libsystemd-bus/bus-internal.h
+++ b/src/libsystemd-bus/bus-internal.h
@@ -251,6 +251,7 @@ struct sd_bus {
sd_event_source *time_event_source;
sd_event_source *quit_event_source;
sd_event *event;
+ int event_priority;
sd_bus_message *current;
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index a4709a1..9ab4367 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -50,10 +50,14 @@
#include "bus-protocol.h"
static int bus_poll(sd_bus *bus, bool need_more, uint64_t timeout_usec);
+static int attach_io_events(sd_bus *b);
+static void detach_io_events(sd_bus *b);
static void bus_close_fds(sd_bus *b) {
assert(b);
+ detach_io_events(b);
+
if (b->input_fd >= 0)
close_nointr_nofail(b->input_fd);
@@ -882,36 +886,27 @@ static int bus_start_address(sd_bus *b) {
assert(b);
for (;;) {
- sd_bus_close(b);
+ bool skipped = false;
- if (b->exec_path) {
+ bus_close_fds(b);
+ if (b->exec_path)
r = bus_socket_exec(b);
- if (r >= 0)
- return r;
-
- b->last_connect_error = -r;
- } else if (b->kernel) {
-
+ else if (b->kernel)
r = bus_kernel_connect(b);
- if (r >= 0)
- return r;
-
- b->last_connect_error = -r;
-
- } else if (b->machine) {
-
+ else if (b->machine)
r = bus_container_connect(b);
- if (r >= 0)
- return r;
-
- b->last_connect_error = -r;
-
- } else if (b->sockaddr.sa.sa_family != AF_UNSPEC) {
-
+ else if (b->sockaddr.sa.sa_family != AF_UNSPEC)
r = bus_socket_connect(b);
- if (r >= 0)
- return r;
+ else
+ skipped = true;
+
+ if (!skipped) {
+ if (r >= 0) {
+ r = attach_io_events(b);
+ if (r >= 0)
+ return r;
+ }
b->last_connect_error = -r;
}
@@ -2598,6 +2593,66 @@ static int quit_callback(sd_event_source *event, void *userdata) {
return 1;
}
+static int attach_io_events(sd_bus *bus) {
+ int r;
+
+ assert(bus);
+
+ if (bus->input_fd < 0)
+ return 0;
+
+ if (!bus->event)
+ return 0;
+
+ if (!bus->input_io_event_source) {
+ r = sd_event_add_io(bus->event, bus->input_fd, 0, io_callback, bus, &bus->input_io_event_source);
+ if (r < 0)
+ return r;
+
+ r = sd_event_source_set_prepare(bus->input_io_event_source, prepare_callback);
+ if (r < 0)
+ return r;
+
+ r = sd_event_source_set_priority(bus->input_io_event_source, bus->event_priority);
+ } else
+ r = sd_event_source_set_io_fd(bus->input_io_event_source, bus->input_fd);
+
+ if (r < 0)
+ return r;
+
+ if (bus->output_fd != bus->input_fd) {
+ assert(bus->output_fd >= 0);
+
+ if (!bus->output_io_event_source) {
+ r = sd_event_add_io(bus->event, bus->output_fd, 0, io_callback, bus, &bus->output_io_event_source);
+ if (r < 0)
+ return r;
+
+ r = sd_event_source_set_priority(bus->output_io_event_source, bus->event_priority);
+ } else
+ r = sd_event_source_set_io_fd(bus->output_io_event_source, bus->output_fd);
+
+ if (r < 0)
+ return r;
+ }
+
+ return 0;
+}
+
+static void detach_io_events(sd_bus *bus) {
+ assert(bus);
+
+ if (bus->input_io_event_source) {
+ sd_event_source_set_enabled(bus->input_io_event_source, SD_EVENT_OFF);
+ bus->input_io_event_source = sd_event_source_unref(bus->input_io_event_source);
+ }
+
+ if (bus->output_io_event_source) {
+ sd_event_source_set_enabled(bus->output_io_event_source, SD_EVENT_OFF);
+ bus->output_io_event_source = sd_event_source_unref(bus->output_io_event_source);
+ }
+}
+
_public_ int sd_bus_attach_event(sd_bus *bus, sd_event *event, int priority) {
int r;
@@ -2616,27 +2671,7 @@ _public_ int sd_bus_attach_event(sd_bus *bus, sd_event *event, int priority) {
return r;
}
- r = sd_event_add_io(bus->event, bus->input_fd, 0, io_callback, bus, &bus->input_io_event_source);
- if (r < 0)
- goto fail;
-
- r = sd_event_source_set_priority(bus->input_io_event_source, priority);
- if (r < 0)
- goto fail;
-
- if (bus->output_fd != bus->input_fd) {
- r = sd_event_add_io(bus->event, bus->output_fd, 0, io_callback, bus, &bus->output_io_event_source);
- if (r < 0)
- goto fail;
-
- r = sd_event_source_set_priority(bus->output_io_event_source, priority);
- if (r < 0)
- goto fail;
- }
-
- r = sd_event_source_set_prepare(bus->input_io_event_source, prepare_callback);
- if (r < 0)
- goto fail;
+ bus->event_priority = priority;
r = sd_event_add_monotonic(bus->event, 0, 0, time_callback, bus, &bus->time_event_source);
if (r < 0)
@@ -2650,6 +2685,10 @@ _public_ int sd_bus_attach_event(sd_bus *bus, sd_event *event, int priority) {
if (r < 0)
goto fail;
+ r = attach_io_events(bus);
+ if (r < 0)
+ goto fail;
+
return 0;
fail:
@@ -2663,15 +2702,7 @@ _public_ int sd_bus_detach_event(sd_bus *bus) {
if (!bus->event)
return 0;
- if (bus->input_io_event_source) {
- sd_event_source_set_enabled(bus->input_io_event_source, SD_EVENT_OFF);
- bus->input_io_event_source = sd_event_source_unref(bus->input_io_event_source);
- }
-
- if (bus->output_io_event_source) {
- sd_event_source_set_enabled(bus->output_io_event_source, SD_EVENT_OFF);
- bus->output_io_event_source = sd_event_source_unref(bus->output_io_event_source);
- }
+ detach_io_events(bus);
if (bus->time_event_source) {
sd_event_source_set_enabled(bus->time_event_source, SD_EVENT_OFF);
commit 30caf8f3afd29da8507c0edbcead7935604c9f3e
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Dec 13 05:13:59 2013 +0100
event: add ability to change fd of an active event source
diff --git a/src/libsystemd-bus/sd-event.c b/src/libsystemd-bus/sd-event.c
index 65ee12d..2b75c6a 100644
--- a/src/libsystemd-bus/sd-event.c
+++ b/src/libsystemd-bus/sd-event.c
@@ -1036,6 +1036,42 @@ _public_ int sd_event_source_get_io_fd(sd_event_source *s) {
return s->io.fd;
}
+_public_ int sd_event_source_set_io_fd(sd_event_source *s, int fd) {
+ int r;
+
+ assert_return(s, -EINVAL);
+ assert_return(fd >= 0, -EINVAL);
+ assert_return(s->type == SOURCE_IO, -EDOM);
+ assert_return(!event_pid_changed(s->event), -ECHILD);
+
+ if (s->io.fd == fd)
+ return 0;
+
+ if (s->enabled == SD_EVENT_OFF) {
+ s->io.fd = fd;
+ s->io.registered = false;
+ } else {
+ int saved_fd;
+
+ saved_fd = s->io.fd;
+ assert(s->io.registered);
+
+ s->io.fd = fd;
+ s->io.registered = false;
+
+ r = source_io_register(s, s->enabled, s->io.events);
+ if (r < 0) {
+ s->io.fd = saved_fd;
+ s->io.registered = true;
+ return r;
+ }
+
+ epoll_ctl(s->event->epoll_fd, EPOLL_CTL_DEL, saved_fd, NULL);
+ }
+
+ return 0;
+}
+
_public_ int sd_event_source_get_io_events(sd_event_source *s, uint32_t* events) {
assert_return(s, -EINVAL);
assert_return(events, -EINVAL);
diff --git a/src/systemd/sd-event.h b/src/systemd/sd-event.h
index cf949be..4c1fbf2 100644
--- a/src/systemd/sd-event.h
+++ b/src/systemd/sd-event.h
@@ -108,6 +108,7 @@ int sd_event_source_set_enabled(sd_event_source *s, int enabled);
void* sd_event_source_get_userdata(sd_event_source *s);
void* sd_event_source_set_userdata(sd_event_source *s, void *userdata);
int sd_event_source_get_io_fd(sd_event_source *s);
+int sd_event_source_set_io_fd(sd_event_source *s, int fd);
int sd_event_source_get_io_events(sd_event_source *s, uint32_t* events);
int sd_event_source_set_io_events(sd_event_source *s, uint32_t events);
int sd_event_source_get_io_revents(sd_event_source *s, uint32_t* revents);
commit 8f726607ece2b49980152a53845aefde858768a5
Author: Lennart Poettering <lennart at poettering.net>
Date: Fri Dec 13 04:14:25 2013 +0100
event: allow to query userdata and watchdog state
diff --git a/src/libsystemd-bus/libsystemd-bus.sym b/src/libsystemd-bus/libsystemd-bus.sym
index f3dbb76..7dbfcf9 100644
--- a/src/libsystemd-bus/libsystemd-bus.sym
+++ b/src/libsystemd-bus/libsystemd-bus.sym
@@ -239,6 +239,7 @@ global:
sd_event_get_now_realtime;
sd_event_get_now_monotonic;
sd_event_set_watchdog;
+ sd_event_get_watchdog;
sd_event_source_ref;
sd_event_source_unref;
@@ -250,6 +251,7 @@ global:
sd_event_source_get_enabled;
sd_event_source_set_enabled;
sd_event_source_get_userdata;
+ sd_event_source_set_userdata;
sd_event_source_get_io_fd;
sd_event_source_get_io_events;
sd_event_source_set_io_events;
diff --git a/src/libsystemd-bus/sd-event.c b/src/libsystemd-bus/sd-event.c
index 6af52ec..65ee12d 100644
--- a/src/libsystemd-bus/sd-event.c
+++ b/src/libsystemd-bus/sd-event.c
@@ -1371,6 +1371,17 @@ _public_ void* sd_event_source_get_userdata(sd_event_source *s) {
return s->userdata;
}
+_public_ void *sd_event_source_set_userdata(sd_event_source *s, void *userdata) {
+ void *ret;
+
+ assert_return(s, NULL);
+
+ ret = s->userdata;
+ s->userdata = userdata;
+
+ return ret;
+}
+
static usec_t sleep_between(sd_event *e, usec_t a, usec_t b) {
usec_t c;
assert(e);
@@ -2078,6 +2089,7 @@ _public_ int sd_event_set_watchdog(sd_event *e, int b) {
int r;
assert_return(e, -EINVAL);
+ assert_return(!event_pid_changed(e), -ECHILD);
if (e->watchdog == !!b)
return e->watchdog;
@@ -2133,3 +2145,10 @@ fail:
e->watchdog_fd = -1;
return r;
}
+
+_public_ int sd_event_get_watchdog(sd_event *e) {
+ assert_return(e, -EINVAL);
+ assert_return(!event_pid_changed(e), -ECHILD);
+
+ return e->watchdog;
+}
diff --git a/src/systemd/sd-event.h b/src/systemd/sd-event.h
index c7c4506..cf949be 100644
--- a/src/systemd/sd-event.h
+++ b/src/systemd/sd-event.h
@@ -94,6 +94,7 @@ int sd_event_get_exit_code(sd_event *e, int *code);
int sd_event_get_now_realtime(sd_event *e, uint64_t *usec);
int sd_event_get_now_monotonic(sd_event *e, uint64_t *usec);
int sd_event_set_watchdog(sd_event *e, int b);
+int sd_event_get_watchdog(sd_event *e);
sd_event_source* sd_event_source_ref(sd_event_source *s);
sd_event_source* sd_event_source_unref(sd_event_source *s);
@@ -105,6 +106,7 @@ int sd_event_source_set_priority(sd_event_source *s, int priority);
int sd_event_source_get_enabled(sd_event_source *s, int *enabled);
int sd_event_source_set_enabled(sd_event_source *s, int enabled);
void* sd_event_source_get_userdata(sd_event_source *s);
+void* sd_event_source_set_userdata(sd_event_source *s, void *userdata);
int sd_event_source_get_io_fd(sd_event_source *s);
int sd_event_source_get_io_events(sd_event_source *s, uint32_t* events);
int sd_event_source_set_io_events(sd_event_source *s, uint32_t events);
More information about the systemd-commits
mailing list