diff --git a/man/sd_event_source_set_enabled.xml b/man/sd_event_source_set_enabled.xml index c8ae169c17..d6cdf85eda 100644 --- a/man/sd_event_source_set_enabled.xml +++ b/man/sd_event_source_set_enabled.xml @@ -68,13 +68,15 @@ loop wakeups and will not be dispatched, until they are enabled again. - sd_event_source_get_enabled() may be - used to query whether the event source object - source is currently enabled or not. It - returns the enablement state (one of SD_EVENT_ON, - SD_EVENT_OFF, SD_EVENT_ONESHOT) - in enabled, if it is not NULL. - It also returns true if the event source is not disabled. + sd_event_source_get_enabled() may be used to query whether the event source + object source is currently enabled or not. If both the + source and the output parameter enabled are + NULL, this function returns false. Otherwise, source must be + a valid pointer to an sd_event_source object. If the output parameter + enabled is not NULL, it is set to the enablement state (one + of SD_EVENT_ON, SD_EVENT_OFF, + SD_EVENT_ONESHOT). The function also returns true if the event source is not + disabled. Event source objects are enabled when they are first created with calls such as diff --git a/src/journal/managed-journal-file.c b/src/journal/managed-journal-file.c index 5c34d14ddc..2672679458 100644 --- a/src/journal/managed-journal-file.c +++ b/src/journal/managed-journal-file.c @@ -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); diff --git a/src/libsystemd/sd-event/event-util.c b/src/libsystemd/sd-event/event-util.c index 8c24e7db63..3a7afe9ae3 100644 --- a/src/libsystemd/sd-event/event-util.c +++ b/src/libsystemd/sd-event/event-util.c @@ -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; diff --git a/src/libsystemd/sd-event/event-util.h b/src/libsystemd/sd-event/event-util.h index abd043bdcc..7bab42ed8f 100644 --- a/src/libsystemd/sd-event/event-util.h +++ b/src/libsystemd/sd-event/event-util.h @@ -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); diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 50f2bb2804..94431d0725 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -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); diff --git a/src/network/netdev/wireguard.c b/src/network/netdev/wireguard.c index 2667a9fb2a..99ec09c641 100644 --- a/src/network/netdev/wireguard.c +++ b/src/network/netdev/wireguard.c @@ -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;