mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-10 01:17:44 +03:00
sd-event: allow sd_event_source_is_enabled() to return false for NULL
This is a natural use case, and instead of defining a wrapper to do this for us, let's just make this part of the API. Calling with NULL was not allowed, so this is not a breaking change to the interface. (After sd_event_source_is_enabled was originally added, we introduced sd_event_source_disable_unref() and other similar functions which accept NULL. So not accepting NULL here is likely to confuse people. Let's just make the API usable with minimal fuss.)
This commit is contained in:
parent
7d9337ed77
commit
71193c0b62
@ -68,13 +68,15 @@
|
||||
loop wakeups and will not be dispatched, until they are enabled
|
||||
again.</para>
|
||||
|
||||
<para><function>sd_event_source_get_enabled()</function> may be
|
||||
used to query whether the event source object
|
||||
<parameter>source</parameter> is currently enabled or not. It
|
||||
returns the enablement state (one of <constant>SD_EVENT_ON</constant>,
|
||||
<constant>SD_EVENT_OFF</constant>, <constant>SD_EVENT_ONESHOT</constant>)
|
||||
in <parameter>enabled</parameter>, if it is not <constant>NULL</constant>.
|
||||
It also returns true if the event source is not disabled.</para>
|
||||
<para><function>sd_event_source_get_enabled()</function> may be used to query whether the event source
|
||||
object <parameter>source</parameter> is currently enabled or not. If both the
|
||||
<parameter>source</parameter> and the output parameter <parameter>enabled</parameter> are
|
||||
<constant>NULL</constant>, this function returns false. Otherwise, <parameter>source</parameter> must be
|
||||
a valid pointer to an <structname>sd_event_source</structname> object. If the output parameter
|
||||
<parameter>enabled</parameter> is not <constant>NULL</constant>, it is set to the enablement state (one
|
||||
of <constant>SD_EVENT_ON</constant>, <constant>SD_EVENT_OFF</constant>,
|
||||
<constant>SD_EVENT_ONESHOT</constant>). The function also returns true if the event source is not
|
||||
disabled.</para>
|
||||
|
||||
<para>Event source objects are enabled when they are first created
|
||||
with calls such as
|
||||
|
@ -375,12 +375,9 @@ ManagedJournalFile* managed_journal_file_close(ManagedJournalFile *f) {
|
||||
}
|
||||
#endif
|
||||
|
||||
if (f->file->post_change_timer) {
|
||||
if (sd_event_source_get_enabled(f->file->post_change_timer, NULL) > 0)
|
||||
journal_file_post_change(f->file);
|
||||
|
||||
sd_event_source_disable_unref(f->file->post_change_timer);
|
||||
}
|
||||
if (sd_event_source_get_enabled(f->file->post_change_timer, NULL) > 0)
|
||||
journal_file_post_change(f->file);
|
||||
sd_event_source_disable_unref(f->file->post_change_timer);
|
||||
|
||||
managed_journal_file_set_offline(f, true);
|
||||
|
||||
|
@ -116,13 +116,6 @@ int event_source_disable(sd_event_source *s) {
|
||||
return sd_event_source_set_enabled(s, SD_EVENT_OFF);
|
||||
}
|
||||
|
||||
int event_source_is_enabled(sd_event_source *s) {
|
||||
if (!s)
|
||||
return false;
|
||||
|
||||
return sd_event_source_get_enabled(s, NULL);
|
||||
}
|
||||
|
||||
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;
|
||||
|
@ -28,6 +28,5 @@ int event_reset_time_relative(
|
||||
const char *description,
|
||||
bool force_reset);
|
||||
int event_source_disable(sd_event_source *s);
|
||||
int event_source_is_enabled(sd_event_source *s);
|
||||
|
||||
int event_add_time_change(sd_event *e, sd_event_source **ret, sd_event_io_handler_t callback, void *userdata);
|
||||
|
@ -2413,6 +2413,10 @@ fail:
|
||||
}
|
||||
|
||||
_public_ int sd_event_source_get_enabled(sd_event_source *s, int *ret) {
|
||||
/* Quick mode: the event source doesn't exist and we only want to query boolean enablement state. */
|
||||
if (!s && !ret)
|
||||
return false;
|
||||
|
||||
assert_return(s, -EINVAL);
|
||||
assert_return(!event_pid_changed(s->event), -ECHILD);
|
||||
|
||||
|
@ -405,7 +405,7 @@ static int peer_resolve_endpoint(WireguardPeer *peer) {
|
||||
/* Not necessary to resolve the endpoint. */
|
||||
return 0;
|
||||
|
||||
if (event_source_is_enabled(peer->resolve_retry_event_source) > 0)
|
||||
if (sd_event_source_get_enabled(peer->resolve_retry_event_source, NULL) > 0)
|
||||
/* Timer event source is enabled. The endpoint will be resolved later. */
|
||||
return 0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user