sd-event: add sd_event_source_{get,set}_floating()

This commit is contained in:
Yu Watanabe 2018-11-04 01:55:28 +09:00
parent b3ae7237c6
commit 2382c9367b
3 changed files with 33 additions and 0 deletions

View File

@ -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;

View File

@ -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;
}

View File

@ -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);