diff options
author | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-11-03 17:55:28 +0100 |
---|---|---|
committer | Yu Watanabe <watanabe.yu+github@gmail.com> | 2018-11-05 05:19:02 +0100 |
commit | 2382c9367b06a5fadad7ab83754bf3332ca3889b (patch) | |
tree | 51dc0e853f97bf34969cdf76b79d7db112b9c649 /src | |
parent | sd-resolve: introduce sd_resolve_query_{get,set}_floating() (diff) | |
download | systemd-2382c9367b06a5fadad7ab83754bf3332ca3889b.tar.xz systemd-2382c9367b06a5fadad7ab83754bf3332ca3889b.zip |
sd-event: add sd_event_source_{get,set}_floating()
Diffstat (limited to 'src')
-rw-r--r-- | src/libsystemd/libsystemd.sym | 3 | ||||
-rw-r--r-- | src/libsystemd/sd-event/sd-event.c | 28 | ||||
-rw-r--r-- | src/systemd/sd-event.h | 2 |
3 files changed, 33 insertions, 0 deletions
diff --git a/src/libsystemd/libsystemd.sym b/src/libsystemd/libsystemd.sym index 8d46081ec4..1f2238ca37 100644 --- a/src/libsystemd/libsystemd.sym +++ b/src/libsystemd/libsystemd.sym @@ -663,4 +663,7 @@ global: sd_device_monitor_filter_add_match_tag; sd_device_monitor_filter_update; sd_device_monitor_filter_remove; + + sd_event_source_get_floating; + sd_event_source_set_floating; } LIBSYSTEMD_239; diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index f44e6b4cca..27caa8681c 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -3702,3 +3702,31 @@ _public_ int sd_event_source_get_destroy_callback(sd_event_source *s, sd_event_d return !!s->destroy_callback; } + +_public_ int sd_event_source_get_floating(sd_event_source *s) { + assert_return(s, -EINVAL); + + return s->floating; +} + +_public_ int sd_event_source_set_floating(sd_event_source *s, int b) { + assert_return(s, -EINVAL); + + if (s->floating == !!b) + return 0; + + if (!s->event) /* Already disconnected */ + return -ESTALE; + + s->floating = b; + + if (b) { + sd_event_source_ref(s); + sd_event_unref(s->event); + } else { + sd_event_ref(s->event); + sd_event_source_unref(s); + } + + return 1; +} diff --git a/src/systemd/sd-event.h b/src/systemd/sd-event.h index c38eb84beb..b15cade20a 100644 --- a/src/systemd/sd-event.h +++ b/src/systemd/sd-event.h @@ -143,6 +143,8 @@ int sd_event_source_get_child_pid(sd_event_source *s, pid_t *pid); int sd_event_source_get_inotify_mask(sd_event_source *s, uint32_t *ret); int sd_event_source_set_destroy_callback(sd_event_source *s, sd_event_destroy_t callback); int sd_event_source_get_destroy_callback(sd_event_source *s, sd_event_destroy_t *ret); +int sd_event_source_get_floating(sd_event_source *s); +int sd_event_source_set_floating(sd_event_source *s, int b); /* Define helpers so that __attribute__((cleanup(sd_event_unrefp))) and similar may be used. */ _SD_DEFINE_POINTER_CLEANUP_FUNC(sd_event, sd_event_unref); |