1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

sd-event: let sd_event_source_set_enabled accept NULL

Same story as before: disabling a non-existent event source shouldn't
need to be guarded by an if. I retained the wrapper so that that we don't
have to say SD_EVENT_OFF in the many places where this is called.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-06-14 14:40:30 +02:00
parent 71193c0b62
commit 7e922b0584
4 changed files with 18 additions and 19 deletions

View File

@ -53,16 +53,15 @@
<refsect1> <refsect1>
<title>Description</title> <title>Description</title>
<para><function>sd_event_source_set_enabled()</function> may be <para><function>sd_event_source_set_enabled()</function> may be used to enable or disable the event
used to enable or disable the event source object specified as source object specified as <parameter>source</parameter>. The <parameter>enabled</parameter> parameter
<parameter>source</parameter>. The <parameter>enabled</parameter> takes one of <constant>SD_EVENT_ON</constant> (to enable), <constant>SD_EVENT_OFF</constant> (to disable)
parameter takes one of <constant>SD_EVENT_ON</constant> (to or <constant>SD_EVENT_ONESHOT</constant>. If invoked with <constant>SD_EVENT_ONESHOT</constant> the event
enable), <constant>SD_EVENT_OFF</constant> (to disable) or source will be enabled but automatically reset to <constant>SD_EVENT_OFF</constant> after one dispatch.
<constant>SD_EVENT_ONESHOT</constant>. If invoked with For <constant>SD_EVENT_OFF</constant>, the event source <parameter>source</parameter> may be
<constant>SD_EVENT_ONESHOT</constant> the event source will be <constant>NULL</constant>, in which case the function does nothing. Otherwise,
enabled but automatically reset to <parameter>source</parameter> must be a valid pointer to an <structname>sd_event_source</structname>
<constant>SD_EVENT_OFF</constant> after the event source was object.</para>
dispatched once.</para>
<para>Event sources that are disabled will not result in event <para>Event sources that are disabled will not result in event
loop wakeups and will not be dispatched, until they are enabled loop wakeups and will not be dispatched, until they are enabled

View File

@ -109,13 +109,6 @@ int event_reset_time_relative(
return event_reset_time(e, s, clock, usec_add(usec_now, usec), accuracy, callback, userdata, priority, description, force_reset); return event_reset_time(e, s, clock, usec_add(usec_now, usec), accuracy, callback, userdata, priority, description, force_reset);
} }
int event_source_disable(sd_event_source *s) {
if (!s)
return 0;
return sd_event_source_set_enabled(s, SD_EVENT_OFF);
}
int event_add_time_change(sd_event *e, sd_event_source **ret, sd_event_io_handler_t callback, void *userdata) { int event_add_time_change(sd_event *e, sd_event_source **ret, sd_event_io_handler_t callback, void *userdata) {
_cleanup_(sd_event_source_unrefp) sd_event_source *s = NULL; _cleanup_(sd_event_source_unrefp) sd_event_source *s = NULL;
_cleanup_close_ int fd = -1; _cleanup_close_ int fd = -1;

View File

@ -27,6 +27,8 @@ int event_reset_time_relative(
int64_t priority, int64_t priority,
const char *description, const char *description,
bool force_reset); bool force_reset);
int event_source_disable(sd_event_source *s); static inline int event_source_disable(sd_event_source *s) {
return sd_event_source_set_enabled(s, SD_EVENT_OFF);
}
int event_add_time_change(sd_event *e, sd_event_source **ret, sd_event_io_handler_t callback, void *userdata); int event_add_time_change(sd_event *e, sd_event_source **ret, sd_event_io_handler_t callback, void *userdata);

View File

@ -2594,8 +2594,13 @@ static int event_source_online(
_public_ int sd_event_source_set_enabled(sd_event_source *s, int m) { _public_ int sd_event_source_set_enabled(sd_event_source *s, int m) {
int r; int r;
assert_return(s, -EINVAL);
assert_return(IN_SET(m, SD_EVENT_OFF, SD_EVENT_ON, SD_EVENT_ONESHOT), -EINVAL); assert_return(IN_SET(m, SD_EVENT_OFF, SD_EVENT_ON, SD_EVENT_ONESHOT), -EINVAL);
/* Quick mode: if the source doesn't exist, SD_EVENT_OFF is a noop. */
if (m == SD_EVENT_OFF && !s)
return 0;
assert_return(s, -EINVAL);
assert_return(!event_pid_changed(s->event), -ECHILD); assert_return(!event_pid_changed(s->event), -ECHILD);
/* If we are dead anyway, we are fine with turning off sources, but everything else needs to fail. */ /* If we are dead anyway, we are fine with turning off sources, but everything else needs to fail. */