diff --git a/man/sd_event_source_set_enabled.xml b/man/sd_event_source_set_enabled.xml index 87c38707e11..73f01848d56 100644 --- a/man/sd_event_source_set_enabled.xml +++ b/man/sd_event_source_set_enabled.xml @@ -74,8 +74,10 @@ 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 in - enabled. + 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. Event source objects are enabled when they are first created with calls such as @@ -100,10 +102,10 @@ Return Value - On success, sd_event_source_set_enabled() and - sd_event_source_get_enabled() return a - non-negative integer. On failure, they return a negative - errno-style error code. + On success, sd_event_source_set_enabled() returns a non-negative + integer. sd_event_source_get_enabled() returns zero if the source is + disabled (SD_EVENT_OFF) and a positive integer otherwise. On failure, they + return a negative errno-style error code. diff --git a/src/journal/journal-file.c b/src/journal/journal-file.c index 14da087f24a..390996a8150 100644 --- a/src/journal/journal-file.c +++ b/src/journal/journal-file.c @@ -349,11 +349,8 @@ JournalFile* journal_file_close(JournalFile *f) { #endif if (f->post_change_timer) { - int enabled; - - if (sd_event_source_get_enabled(f->post_change_timer, &enabled) >= 0) - if (enabled == SD_EVENT_ONESHOT) - journal_file_post_change(f); + if (sd_event_source_get_enabled(f->post_change_timer, NULL) > 0) + journal_file_post_change(f); (void) sd_event_source_set_enabled(f->post_change_timer, SD_EVENT_OFF); sd_event_source_unref(f->post_change_timer); @@ -1869,37 +1866,33 @@ static int post_change_thunk(sd_event_source *timer, uint64_t usec, void *userda } static void schedule_post_change(JournalFile *f) { - sd_event_source *timer; - int enabled, r; uint64_t now; + int r; assert(f); assert(f->post_change_timer); - timer = f->post_change_timer; - - r = sd_event_source_get_enabled(timer, &enabled); + r = sd_event_source_get_enabled(f->post_change_timer, NULL); if (r < 0) { log_debug_errno(r, "Failed to get ftruncate timer state: %m"); goto fail; } - - if (enabled == SD_EVENT_ONESHOT) + if (r > 0) return; - r = sd_event_now(sd_event_source_get_event(timer), CLOCK_MONOTONIC, &now); + r = sd_event_now(sd_event_source_get_event(f->post_change_timer), CLOCK_MONOTONIC, &now); if (r < 0) { log_debug_errno(r, "Failed to get clock's now for scheduling ftruncate: %m"); goto fail; } - r = sd_event_source_set_time(timer, now+f->post_change_timer_period); + r = sd_event_source_set_time(f->post_change_timer, now + f->post_change_timer_period); if (r < 0) { log_debug_errno(r, "Failed to set time for scheduling ftruncate: %m"); goto fail; } - r = sd_event_source_set_enabled(timer, SD_EVENT_ONESHOT); + r = sd_event_source_set_enabled(f->post_change_timer, SD_EVENT_ONESHOT); if (r < 0) { log_debug_errno(r, "Failed to enable scheduled ftruncate: %m"); goto fail; diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 8762b7b89d9..66824c6c78d 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -2143,11 +2143,11 @@ fail: _public_ int sd_event_source_get_enabled(sd_event_source *s, int *m) { assert_return(s, -EINVAL); - assert_return(m, -EINVAL); assert_return(!event_pid_changed(s->event), -ECHILD); - *m = s->enabled; - return 0; + if (m) + *m = s->enabled; + return s->enabled != SD_EVENT_OFF; } _public_ int sd_event_source_set_enabled(sd_event_source *s, int m) {