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>
<title>Description</title>
<para><function>sd_event_source_set_enabled()</function> may be
used to enable or disable the event source object specified as
<parameter>source</parameter>. The <parameter>enabled</parameter>
parameter takes one of <constant>SD_EVENT_ON</constant> (to
enable), <constant>SD_EVENT_OFF</constant> (to disable) or
<constant>SD_EVENT_ONESHOT</constant>. If invoked with
<constant>SD_EVENT_ONESHOT</constant> the event source will be
enabled but automatically reset to
<constant>SD_EVENT_OFF</constant> after the event source was
dispatched once.</para>
<para><function>sd_event_source_set_enabled()</function> may be used to enable or disable the event
source object specified as <parameter>source</parameter>. The <parameter>enabled</parameter> parameter
takes one of <constant>SD_EVENT_ON</constant> (to enable), <constant>SD_EVENT_OFF</constant> (to disable)
or <constant>SD_EVENT_ONESHOT</constant>. If invoked with <constant>SD_EVENT_ONESHOT</constant> the event
source will be enabled but automatically reset to <constant>SD_EVENT_OFF</constant> after one dispatch.
For <constant>SD_EVENT_OFF</constant>, the event source <parameter>source</parameter> may be
<constant>NULL</constant>, in which case the function does nothing. Otherwise,
<parameter>source</parameter> must be a valid pointer to an <structname>sd_event_source</structname>
object.</para>
<para>Event sources that are disabled will not result in event
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);
}
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) {
_cleanup_(sd_event_source_unrefp) sd_event_source *s = NULL;
_cleanup_close_ int fd = -1;

View File

@ -27,6 +27,8 @@ int event_reset_time_relative(
int64_t priority,
const char *description,
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);

View File

@ -2594,8 +2594,13 @@ static int event_source_online(
_public_ int sd_event_source_set_enabled(sd_event_source *s, int m) {
int r;
assert_return(s, -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);
/* If we are dead anyway, we are fine with turning off sources, but everything else needs to fail. */