1
0
mirror of https://github.com/systemd/systemd.git synced 2024-11-02 10:51:20 +03:00

Merge pull request #10791 from keszybz/sd-event-get-enabled

Some minor tweaks for sd_event_source_get_enabled
This commit is contained in:
Lennart Poettering 2018-11-16 12:46:30 +01:00 committed by GitHub
commit 567e5d5549
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 24 deletions

View File

@ -74,8 +74,10 @@
<para><function>sd_event_source_get_enabled()</function> may be <para><function>sd_event_source_get_enabled()</function> may be
used to query whether the event source object used to query whether the event source object
<parameter>source</parameter> is currently enabled or not. It <parameter>source</parameter> is currently enabled or not. It
returns the enablement state in returns the enablement state (one of <constant>SD_EVENT_ON</constant>,
<parameter>enabled</parameter>.</para> <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>Event source objects are enabled when they are first created <para>Event source objects are enabled when they are first created
with calls such as with calls such as
@ -100,10 +102,10 @@
<refsect1> <refsect1>
<title>Return Value</title> <title>Return Value</title>
<para>On success, <function>sd_event_source_set_enabled()</function> and <para>On success, <function>sd_event_source_set_enabled()</function> returns a non-negative
<function>sd_event_source_get_enabled()</function> return a integer. <function>sd_event_source_get_enabled()</function> returns zero if the source is
non-negative integer. On failure, they return a negative disabled (<constant>SD_EVENT_OFF</constant>) and a positive integer otherwise. On failure, they
errno-style error code.</para> return a negative errno-style error code.</para>
</refsect1> </refsect1>
<refsect1> <refsect1>

View File

@ -349,11 +349,8 @@ JournalFile* journal_file_close(JournalFile *f) {
#endif #endif
if (f->post_change_timer) { if (f->post_change_timer) {
int enabled; if (sd_event_source_get_enabled(f->post_change_timer, NULL) > 0)
journal_file_post_change(f);
if (sd_event_source_get_enabled(f->post_change_timer, &enabled) >= 0)
if (enabled == SD_EVENT_ONESHOT)
journal_file_post_change(f);
(void) sd_event_source_set_enabled(f->post_change_timer, SD_EVENT_OFF); (void) sd_event_source_set_enabled(f->post_change_timer, SD_EVENT_OFF);
sd_event_source_unref(f->post_change_timer); 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) { static void schedule_post_change(JournalFile *f) {
sd_event_source *timer;
int enabled, r;
uint64_t now; uint64_t now;
int r;
assert(f); assert(f);
assert(f->post_change_timer); assert(f->post_change_timer);
timer = f->post_change_timer; r = sd_event_source_get_enabled(f->post_change_timer, NULL);
r = sd_event_source_get_enabled(timer, &enabled);
if (r < 0) { if (r < 0) {
log_debug_errno(r, "Failed to get ftruncate timer state: %m"); log_debug_errno(r, "Failed to get ftruncate timer state: %m");
goto fail; goto fail;
} }
if (r > 0)
if (enabled == SD_EVENT_ONESHOT)
return; 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) { if (r < 0) {
log_debug_errno(r, "Failed to get clock's now for scheduling ftruncate: %m"); log_debug_errno(r, "Failed to get clock's now for scheduling ftruncate: %m");
goto fail; 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) { if (r < 0) {
log_debug_errno(r, "Failed to set time for scheduling ftruncate: %m"); log_debug_errno(r, "Failed to set time for scheduling ftruncate: %m");
goto fail; 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) { if (r < 0) {
log_debug_errno(r, "Failed to enable scheduled ftruncate: %m"); log_debug_errno(r, "Failed to enable scheduled ftruncate: %m");
goto fail; goto fail;

View File

@ -2143,11 +2143,11 @@ fail:
_public_ int sd_event_source_get_enabled(sd_event_source *s, int *m) { _public_ int sd_event_source_get_enabled(sd_event_source *s, int *m) {
assert_return(s, -EINVAL); assert_return(s, -EINVAL);
assert_return(m, -EINVAL);
assert_return(!event_pid_changed(s->event), -ECHILD); assert_return(!event_pid_changed(s->event), -ECHILD);
*m = s->enabled; if (m)
return 0; *m = s->enabled;
return s->enabled != SD_EVENT_OFF;
} }
_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) {