mirror of
https://github.com/systemd/systemd-stable.git
synced 2024-12-25 23:21:33 +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:
commit
567e5d5549
@ -74,8 +74,10 @@
|
||||
<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 in
|
||||
<parameter>enabled</parameter>.</para>
|
||||
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>Event source objects are enabled when they are first created
|
||||
with calls such as
|
||||
@ -100,10 +102,10 @@
|
||||
<refsect1>
|
||||
<title>Return Value</title>
|
||||
|
||||
<para>On success, <function>sd_event_source_set_enabled()</function> and
|
||||
<function>sd_event_source_get_enabled()</function> return a
|
||||
non-negative integer. On failure, they return a negative
|
||||
errno-style error code.</para>
|
||||
<para>On success, <function>sd_event_source_set_enabled()</function> returns a non-negative
|
||||
integer. <function>sd_event_source_get_enabled()</function> returns zero if the source is
|
||||
disabled (<constant>SD_EVENT_OFF</constant>) and a positive integer otherwise. On failure, they
|
||||
return a negative errno-style error code.</para>
|
||||
</refsect1>
|
||||
|
||||
<refsect1>
|
||||
|
@ -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;
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user