From 8f726607ece2b49980152a53845aefde858768a5 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 13 Dec 2013 04:14:25 +0100 Subject: [PATCH] event: allow to query userdata and watchdog state --- src/libsystemd-bus/libsystemd-bus.sym | 2 ++ src/libsystemd-bus/sd-event.c | 19 +++++++++++++++++++ src/systemd/sd-event.h | 2 ++ 3 files changed, 23 insertions(+) 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); -- 2.7.4