1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

Merge pull request #16596 from poettering/event-time-rel

Conflict in src/libsystemd-network/test-ndisc-rs.c fixed manually.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2020-08-04 16:07:03 +02:00
commit d06bd2e785
25 changed files with 186 additions and 131 deletions

4
TODO
View File

@ -934,6 +934,10 @@ Features:
- allow multiple signal handlers per signal?
- document chaining of signal handler for SIGCHLD and child handlers
- define more intervals where we will shift wakeup intervals around in, 1h, 6h, 24h, ...
- maybe support iouring as backend, so that we allow hooking read and write
operations instead of IO ready events into event loops. See considerations
here:
http://blog.vmsplice.net/2020/07/rethinking-event-loop-integration-for.html
* investigate endianness issues of UUID vs. GUID

View File

@ -51,6 +51,17 @@
<paramdef>void *<parameter>userdata</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_event_add_time_relative</function></funcdef>
<paramdef>sd_event *<parameter>event</parameter></paramdef>
<paramdef>sd_event_source **<parameter>source</parameter></paramdef>
<paramdef>clockid_t <parameter>clock</parameter></paramdef>
<paramdef>uint64_t <parameter>usec</parameter></paramdef>
<paramdef>uint64_t <parameter>accuracy</parameter></paramdef>
<paramdef>sd_event_time_handler_t <parameter>handler</parameter></paramdef>
<paramdef>void *<parameter>userdata</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_event_source_get_time</function></funcdef>
<paramdef>sd_event_source *<parameter>source</parameter></paramdef>
@ -63,6 +74,12 @@
<paramdef>uint64_t <parameter>usec</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_event_source_set_time_relative</function></funcdef>
<paramdef>sd_event_source *<parameter>source</parameter></paramdef>
<paramdef>uint64_t <parameter>usec</parameter></paramdef>
</funcprototype>
<funcprototype>
<funcdef>int <function>sd_event_source_get_time_accuracy</function></funcdef>
<paramdef>sd_event_source *<parameter>source</parameter></paramdef>
@ -123,6 +140,11 @@
<function>sd_event_source_set_time()</function>.
</para>
<para><function>sd_event_add_time_relative()</function> is like <function>sd_event_add_time()</function>,
but takes a relative time specification. It's relative to the current time of the event loop iteration,
as returned by
<citerefentry><refentrytitle>sd_event_now</refentrytitle><manvolnum>3</manvolnum></citerefentry>.</para>
<para>To destroy an event source object use
<citerefentry><refentrytitle>sd_event_source_unref</refentrytitle><manvolnum>3</manvolnum></citerefentry>,
but note that the event source is only removed from the event loop
@ -173,17 +195,21 @@
events will be regular, while in the latter case the scheduling
latency will keep accumulating on the timer.</para>
<para><function>sd_event_source_get_time()</function> retrieves
the configured time value of an event source created
previously with <function>sd_event_add_time()</function>. It takes
the event source object and a pointer to a variable to store the
time in, relative to the selected clock's epoch, in µs.</para>
<para><function>sd_event_source_get_time()</function> retrieves the configured time value of an event
source created previously with <function>sd_event_add_time()</function> or
<function>sd_event_add_time_relative()</function>. It takes the event source object and a pointer to a
variable to store the time in, relative to the selected clock's epoch, in µs. The returned value is
relative to the epoch, even if the event source was created with a relative time via
<function>sd_event_add_time_relative()</function>.</para>
<para><function>sd_event_source_set_time()</function> changes the
time of an event source created previously with
<function>sd_event_add_time()</function>. It takes the event
source object and a time relative to the selected clock's epoch,
in µs.</para>
<para><function>sd_event_source_set_time()</function> changes the time of an event source created
previously with <function>sd_event_add_time()</function> or
<function>sd_event_add_time_relative()</function>. It takes the event source object and a time relative
to the selected clock's epoch, in µs.</para>
<para><function>sd_event_source_set_time_relative()</function> is similar to
<function>sd_event_source_set_time()</function>, but takes a time relative to the current time of the
event loop iteration, as returned by <function>sd_event_now()</function>.</para>
<para><function>sd_event_source_get_time_accuracy()</function>
retrieves the configured accuracy value of an event source
@ -255,6 +281,13 @@
<listitem><para>The passed event source is not a timer event source.</para></listitem>
</varlistentry>
<varlistentry>
<term><constant>-EOVERFLOW</constant></term>
<listitem><para>The passed relative time is outside of the allowed range for time values (i.e. the
specified value added to the current time is outside the 64 bit unsigned integer range).</para></listitem>
</varlistentry>
</variablelist>
</refsect2>
</refsect1>

View File

@ -709,25 +709,25 @@ static int automount_dispatch_expire(sd_event_source *source, usec_t usec, void
}
static int automount_start_expire(Automount *a) {
int r;
usec_t timeout;
int r;
assert(a);
if (a->timeout_idle_usec == 0)
return 0;
timeout = now(CLOCK_MONOTONIC) + MAX(a->timeout_idle_usec/3, USEC_PER_SEC);
timeout = MAX(a->timeout_idle_usec/3, USEC_PER_SEC);
if (a->expire_event_source) {
r = sd_event_source_set_time(a->expire_event_source, timeout);
r = sd_event_source_set_time_relative(a->expire_event_source, timeout);
if (r < 0)
return r;
return sd_event_source_set_enabled(a->expire_event_source, SD_EVENT_ONESHOT);
}
r = sd_event_add_time(
r = sd_event_add_time_relative(
UNIT(a)->manager->event,
&a->expire_event_source,
CLOCK_MONOTONIC, timeout, 0,

View File

@ -2902,15 +2902,13 @@ static int manager_dispatch_idle_pipe_fd(sd_event_source *source, int fd, uint32
static int manager_dispatch_jobs_in_progress(sd_event_source *source, usec_t usec, void *userdata) {
Manager *m = userdata;
int r;
uint64_t next;
assert(m);
assert(source);
manager_print_jobs_in_progress(m);
next = now(CLOCK_MONOTONIC) + JOBS_IN_PROGRESS_PERIOD_USEC;
r = sd_event_source_set_time(source, next);
r = sd_event_source_set_time_relative(source, JOBS_IN_PROGRESS_PERIOD_USEC);
if (r < 0)
return r;

View File

@ -139,16 +139,16 @@ static int curl_glue_timer_callback(CURLM *curl, long timeout_ms, void *userdata
return 0;
}
usec = now(clock_boottime_or_monotonic()) + (usec_t) timeout_ms * USEC_PER_MSEC + USEC_PER_MSEC - 1;
usec = (usec_t) timeout_ms * USEC_PER_MSEC + USEC_PER_MSEC - 1;
if (g->timer) {
if (sd_event_source_set_time(g->timer, usec) < 0)
if (sd_event_source_set_time_relative(g->timer, usec) < 0)
return -1;
if (sd_event_source_set_enabled(g->timer, SD_EVENT_ONESHOT) < 0)
return -1;
} else {
if (sd_event_add_time(g->event, &g->timer, clock_boottime_or_monotonic(), usec, 0, curl_glue_on_timer, g) < 0)
if (sd_event_add_time_relative(g->event, &g->timer, clock_boottime_or_monotonic(), usec, 0, curl_glue_on_timer, g) < 0)
return -1;
(void) sd_event_source_set_description(g->timer, "curl-timer");

View File

@ -1978,7 +1978,6 @@ static int post_change_thunk(sd_event_source *timer, uint64_t usec, void *userda
}
static void schedule_post_change(JournalFile *f) {
uint64_t now;
int r;
assert(f);
@ -1992,13 +1991,7 @@ static void schedule_post_change(JournalFile *f) {
if (r > 0)
return;
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(f->post_change_timer, now + f->post_change_timer_period);
r = sd_event_source_set_time_relative(f->post_change_timer, f->post_change_timer_period);
if (r < 0) {
log_debug_errno(r, "Failed to set time for scheduling ftruncate: %m");
goto fail;

View File

@ -1677,27 +1677,20 @@ int server_schedule_sync(Server *s, int priority) {
return 0;
if (s->sync_interval_usec > 0) {
usec_t when;
r = sd_event_now(s->event, CLOCK_MONOTONIC, &when);
if (r < 0)
return r;
when += s->sync_interval_usec;
if (!s->sync_event_source) {
r = sd_event_add_time(
r = sd_event_add_time_relative(
s->event,
&s->sync_event_source,
CLOCK_MONOTONIC,
when, 0,
s->sync_interval_usec, 0,
server_dispatch_sync, s);
if (r < 0)
return r;
r = sd_event_source_set_priority(s->sync_event_source, SD_EVENT_PRIORITY_IMPORTANT);
} else {
r = sd_event_source_set_time(s->sync_event_source, when);
r = sd_event_source_set_time_relative(s->sync_event_source, s->sync_interval_usec);
if (r < 0)
return r;
@ -1888,7 +1881,7 @@ static int server_connect_notify(Server *s) {
if (sd_watchdog_enabled(false, &s->watchdog_usec) > 0) {
s->send_watchdog = true;
r = sd_event_add_time(s->event, &s->watchdog_event_source, CLOCK_MONOTONIC, now(CLOCK_MONOTONIC) + s->watchdog_usec/2, s->watchdog_usec/4, dispatch_watchdog, s);
r = sd_event_add_time_relative(s->event, &s->watchdog_event_source, CLOCK_MONOTONIC, s->watchdog_usec/2, s->watchdog_usec/4, dispatch_watchdog, s);
if (r < 0)
return log_error_errno(r, "Failed to add watchdog time event: %m");
}
@ -2116,7 +2109,6 @@ static int server_idle_handler(sd_event_source *source, uint64_t usec, void *use
int server_start_or_stop_idle_timer(Server *s) {
_cleanup_(sd_event_source_unrefp) sd_event_source *source = NULL;
usec_t when;
int r;
assert(s);
@ -2129,11 +2121,7 @@ int server_start_or_stop_idle_timer(Server *s) {
if (s->idle_event_source)
return 1;
r = sd_event_now(s->event, CLOCK_MONOTONIC, &when);
if (r < 0)
return log_error_errno(r, "Failed to determine current time: %m");
r = sd_event_add_time(s->event, &source, CLOCK_MONOTONIC, usec_add(when, IDLE_TIMEOUT_USEC), 0, server_idle_handler, s);
r = sd_event_add_time_relative(s->event, &source, CLOCK_MONOTONIC, IDLE_TIMEOUT_USEC, 0, server_idle_handler, s);
if (r < 0)
return log_error_errno(r, "Failed to allocate idle timer: %m");
@ -2148,7 +2136,6 @@ int server_start_or_stop_idle_timer(Server *s) {
}
int server_refresh_idle_timer(Server *s) {
usec_t when;
int r;
assert(s);
@ -2156,11 +2143,7 @@ int server_refresh_idle_timer(Server *s) {
if (!s->idle_event_source)
return 0;
r = sd_event_now(s->event, CLOCK_MONOTONIC, &when);
if (r < 0)
return log_error_errno(r, "Failed to determine current time: %m");
r = sd_event_source_set_time(s->idle_event_source, usec_add(when, IDLE_TIMEOUT_USEC));
r = sd_event_source_set_time_relative(s->idle_event_source, IDLE_TIMEOUT_USEC);
if (r < 0)
return log_error_errno(r, "Failed to refresh idle timer: %m");

View File

@ -514,7 +514,6 @@ static int test_addr_acq_recv_discover(size_t size, DHCPMessage *discover) {
}
static void test_addr_acq(sd_event *e) {
usec_t time_now = now(clock_boottime_or_monotonic());
sd_dhcp_client *client;
int res, r;
@ -535,10 +534,11 @@ static void test_addr_acq(sd_event *e) {
callback_recv = test_addr_acq_recv_discover;
assert_se(sd_event_add_time(e, &test_hangcheck,
clock_boottime_or_monotonic(),
time_now + 2 * USEC_PER_SEC, 0,
test_dhcp_hangcheck, NULL) >= 0);
assert_se(sd_event_add_time_relative(
e, &test_hangcheck,
clock_boottime_or_monotonic(),
2 * USEC_PER_SEC, 0,
test_dhcp_hangcheck, NULL) >= 0);
res = sd_dhcp_client_start(client);
assert_se(IN_SET(res, 0, -EINPROGRESS));

View File

@ -942,7 +942,6 @@ int dhcp6_network_bind_udp_socket(int ifindex, struct in6_addr *local_address) {
static int test_client_solicit(sd_event *e) {
sd_dhcp6_client *client;
usec_t time_now = now(clock_boottime_or_monotonic());
struct in6_addr address = { { { 0xfe, 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x01 } } };
int val;
@ -968,9 +967,9 @@ static int test_client_solicit(sd_event *e) {
assert_se(sd_dhcp6_client_set_callback(client,
test_client_information_cb, e) >= 0);
assert_se(sd_event_add_time(e, &hangcheck, clock_boottime_or_monotonic(),
time_now + 2 * USEC_PER_SEC, 0,
test_hangcheck, NULL) >= 0);
assert_se(sd_event_add_time_relative(e, &hangcheck, clock_boottime_or_monotonic(),
2 * USEC_PER_SEC, 0,
test_hangcheck, NULL) >= 0);
assert_se(sd_dhcp6_client_set_local_address(client, &address) >= 0);

View File

@ -293,7 +293,6 @@ static int radv_recv(sd_event_source *s, int fd, uint32_t revents, void *userdat
static void test_ra(void) {
sd_event *e;
sd_radv *ra;
usec_t time_now = now(clock_boottime_or_monotonic());
unsigned i;
printf("* %s\n", __FUNCTION__);
@ -339,9 +338,10 @@ static void test_ra(void) {
assert_se(sd_event_add_io(e, &recv_router_advertisement, test_fd[0],
EPOLLIN, radv_recv, ra) >= 0);
assert_se(sd_event_add_time(e, &test_hangcheck, clock_boottime_or_monotonic(),
time_now + 2 *USEC_PER_SEC, 0,
test_rs_hangcheck, NULL) >= 0);
assert_se(sd_event_add_time_relative(
e, &test_hangcheck, clock_boottime_or_monotonic(),
2 *USEC_PER_SEC, 0,
test_rs_hangcheck, NULL) >= 0);
assert_se(sd_radv_start(ra) >= 0);

View File

@ -272,7 +272,6 @@ static void test_callback(sd_ndisc *nd, sd_ndisc_event event, sd_ndisc_router *r
static void test_rs(void) {
sd_event *e;
sd_ndisc *nd;
usec_t time_now = now(clock_boottime_or_monotonic());
if (verbose)
printf("* %s\n", __FUNCTION__);
@ -290,9 +289,10 @@ static void test_rs(void) {
assert_se(sd_ndisc_set_mac(nd, &mac_addr) >= 0);
assert_se(sd_ndisc_set_callback(nd, test_callback, e) >= 0);
assert_se(sd_event_add_time(e, &test_hangcheck, clock_boottime_or_monotonic(),
time_now + 30 * USEC_PER_SEC, 0,
test_rs_hangcheck, NULL) >= 0);
assert_se(sd_event_add_time_relative(
e, &test_hangcheck, clock_boottime_or_monotonic(),
30 * USEC_PER_SEC, 0,
test_rs_hangcheck, NULL) >= 0);
assert_se(sd_ndisc_stop(nd) >= 0);
assert_se(sd_ndisc_start(nd) >= 0);
@ -373,7 +373,6 @@ static int test_timeout_value(uint8_t flags) {
static void test_timeout(void) {
sd_event *e;
sd_ndisc *nd;
usec_t time_now = now(clock_boottime_or_monotonic());
if (verbose)
printf("* %s\n", __FUNCTION__);
@ -392,9 +391,10 @@ static void test_timeout(void) {
assert_se(sd_ndisc_set_ifindex(nd, 42) >= 0);
assert_se(sd_ndisc_set_mac(nd, &mac_addr) >= 0);
assert_se(sd_event_add_time(e, &test_hangcheck, clock_boottime_or_monotonic(),
time_now + 30 * USEC_PER_SEC, 0,
test_rs_hangcheck, NULL) >= 0);
assert_se(sd_event_add_time_relative(
e, &test_hangcheck, clock_boottime_or_monotonic(),
30 * USEC_PER_SEC, 0,
test_rs_hangcheck, NULL) >= 0);
assert_se(sd_ndisc_start(nd) >= 0);

View File

@ -721,3 +721,9 @@ global:
sd_journal_enumerate_available_data;
sd_journal_enumerate_available_unique;
} LIBSYSTEMD_245;
LIBSYSTEMD_247 {
global:
sd_event_add_time_relative;
sd_event_source_set_time_relative;
} LIBSYSTEMD_246;

View File

@ -1146,6 +1146,31 @@ _public_ int sd_event_add_time(
return 0;
}
_public_ int sd_event_add_time_relative(
sd_event *e,
sd_event_source **ret,
clockid_t clock,
uint64_t usec,
uint64_t accuracy,
sd_event_time_handler_t callback,
void *userdata) {
usec_t t;
int r;
/* Same as sd_event_add_time() but operates relative to the event loop's current point in time, and
* checks for overflow. */
r = sd_event_now(e, clock, &t);
if (r < 0)
return r;
if (usec >= USEC_INFINITY - t)
return -EOVERFLOW;
return sd_event_add_time(e, ret, clock, t + usec, accuracy, callback, userdata);
}
static int signal_exit_callback(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) {
assert(s);
@ -2402,6 +2427,23 @@ _public_ int sd_event_source_set_time(sd_event_source *s, uint64_t usec) {
return 0;
}
_public_ int sd_event_source_set_time_relative(sd_event_source *s, uint64_t usec) {
usec_t t;
int r;
assert_return(s, -EINVAL);
assert_return(EVENT_SOURCE_IS_TIME(s->type), -EDOM);
r = sd_event_now(s->event, event_source_type_to_clock(s->type), &t);
if (r < 0)
return r;
if (usec >= USEC_INFINITY - t)
return -EOVERFLOW;
return sd_event_source_set_time(s, t + usec);
}
_public_ int sd_event_source_get_time_accuracy(sd_event_source *s, uint64_t *usec) {
assert_return(s, -EINVAL);
assert_return(usec, -EINVAL);

View File

@ -1720,26 +1720,26 @@ static int delay_shutdown_or_sleep(
const char *unit_name) {
int r;
usec_t timeout_val;
assert(m);
assert(w >= 0);
assert(w < _INHIBIT_WHAT_MAX);
assert(unit_name);
timeout_val = now(CLOCK_MONOTONIC) + m->inhibit_delay_max;
if (m->inhibit_timeout_source) {
r = sd_event_source_set_time(m->inhibit_timeout_source, timeout_val);
r = sd_event_source_set_time_relative(m->inhibit_timeout_source, m->inhibit_delay_max);
if (r < 0)
return log_error_errno(r, "sd_event_source_set_time() failed: %m");
return log_error_errno(r, "sd_event_source_set_time_relative() failed: %m");
r = sd_event_source_set_enabled(m->inhibit_timeout_source, SD_EVENT_ONESHOT);
if (r < 0)
return log_error_errno(r, "sd_event_source_set_enabled() failed: %m");
} else {
r = sd_event_add_time(m->event, &m->inhibit_timeout_source, CLOCK_MONOTONIC,
timeout_val, 0, manager_inhibit_timeout_handler, m);
r = sd_event_add_time_relative(
m->event,
&m->inhibit_timeout_source,
CLOCK_MONOTONIC, m->inhibit_delay_max, 0,
manager_inhibit_timeout_handler, m);
if (r < 0)
return r;
}

View File

@ -896,11 +896,12 @@ int session_release(Session *s) {
if (s->timer_event_source)
return 0;
return sd_event_add_time(s->manager->event,
&s->timer_event_source,
CLOCK_MONOTONIC,
usec_add(now(CLOCK_MONOTONIC), RELEASE_USEC), 0,
release_timeout_callback, s);
return sd_event_add_time_relative(
s->manager->event,
&s->timer_event_source,
CLOCK_MONOTONIC,
RELEASE_USEC, 0,
release_timeout_callback, s);
}
bool session_is_active(Session *s) {

View File

@ -332,7 +332,7 @@ static int link_send_lldp(Link *link) {
static int on_lldp_timer(sd_event_source *s, usec_t t, void *userdata) {
Link *link = userdata;
usec_t current, delay, next;
usec_t delay;
int r;
assert(s);
@ -347,12 +347,10 @@ static int on_lldp_timer(sd_event_source *s, usec_t t, void *userdata) {
if (link->lldp_tx_fast > 0)
link->lldp_tx_fast--;
assert_se(sd_event_now(sd_event_source_get_event(s), clock_boottime_or_monotonic(), &current) >= 0);
delay = link->lldp_tx_fast > 0 ? LLDP_FAST_TX_USEC : LLDP_TX_INTERVAL_USEC;
next = usec_add(usec_add(current, delay), (usec_t) random_u64() % LLDP_JITTER_USEC);
delay = usec_add(delay, (usec_t) random_u64() % LLDP_JITTER_USEC);
r = sd_event_source_set_time(s, next);
r = sd_event_source_set_time_relative(s, delay);
if (r < 0)
return log_link_error_errno(link, r, "Failed to restart LLDP timer: %m");

View File

@ -687,11 +687,11 @@ int dns_query_go(DnsQuery *q) {
dns_query_reset_answer(q);
r = sd_event_add_time(
r = sd_event_add_time_relative(
q->manager->event,
&q->timeout_event_source,
clock_boottime_or_monotonic(),
now(clock_boottime_or_monotonic()) + SD_RESOLVED_QUERY_TIMEOUT_USEC,
SD_RESOLVED_QUERY_TIMEOUT_USEC,
0, on_query_timeout, q);
if (r < 0)
goto fail;

View File

@ -1059,12 +1059,13 @@ int dns_scope_notify_conflict(DnsScope *scope, DnsResourceRecord *rr) {
random_bytes(&jitter, sizeof(jitter));
jitter %= LLMNR_JITTER_INTERVAL_USEC;
r = sd_event_add_time(scope->manager->event,
&scope->conflict_event_source,
clock_boottime_or_monotonic(),
now(clock_boottime_or_monotonic()) + jitter,
LLMNR_JITTER_INTERVAL_USEC,
on_conflict_dispatch, scope);
r = sd_event_add_time_relative(
scope->manager->event,
&scope->conflict_event_source,
clock_boottime_or_monotonic(),
jitter,
LLMNR_JITTER_INTERVAL_USEC,
on_conflict_dispatch, scope);
if (r < 0)
return log_debug_errno(r, "Failed to add conflict dispatch event: %m");
@ -1318,18 +1319,13 @@ int dns_scope_announce(DnsScope *scope, bool goodbye) {
/* In section 8.3 of RFC6762: "The Multicast DNS responder MUST send at least two unsolicited
* responses, one second apart." */
if (!scope->announced) {
usec_t ts;
scope->announced = true;
assert_se(sd_event_now(scope->manager->event, clock_boottime_or_monotonic(), &ts) >= 0);
ts += MDNS_ANNOUNCE_DELAY;
r = sd_event_add_time(
r = sd_event_add_time_relative(
scope->manager->event,
&scope->announce_event_source,
clock_boottime_or_monotonic(),
ts,
MDNS_ANNOUNCE_DELAY,
MDNS_JITTER_RANGE_USEC,
on_announcement_timeout, scope);
if (r < 0)

View File

@ -445,7 +445,7 @@ static int on_stream_io(sd_event_source *es, int fd, uint32_t revents, void *use
/* If we did something, let's restart the timeout event source */
if (progressed && s->timeout_event_source) {
r = sd_event_source_set_time(s->timeout_event_source, now(clock_boottime_or_monotonic()) + DNS_STREAM_TIMEOUT_USEC);
r = sd_event_source_set_time_relative(s->timeout_event_source, DNS_STREAM_TIMEOUT_USEC);
if (r < 0)
log_warning_errno(errno, "Couldn't restart TCP connection timeout, ignoring: %m");
}
@ -528,11 +528,11 @@ int dns_stream_new(
(void) sd_event_source_set_description(s->io_event_source, "dns-stream-io");
r = sd_event_add_time(
r = sd_event_add_time_relative(
m->event,
&s->timeout_event_source,
clock_boottime_or_monotonic(),
now(clock_boottime_or_monotonic()) + DNS_STREAM_TIMEOUT_USEC, 0,
DNS_STREAM_TIMEOUT_USEC, 0,
on_stream_timeout, s);
if (r < 0)
return r;

View File

@ -182,9 +182,10 @@ int device_wait_for_initialization(sd_device *device, const char *subsystem, use
return log_error_errno(r, "Failed to start device monitor: %m");
if (timeout != USEC_INFINITY) {
r = sd_event_add_time(event, &timeout_source,
CLOCK_MONOTONIC, now(CLOCK_MONOTONIC) + timeout, 0,
device_timeout_handler, NULL);
r = sd_event_add_time_relative(
event, &timeout_source,
CLOCK_MONOTONIC, timeout, 0,
device_timeout_handler, NULL);
if (r < 0)
return log_error_errno(r, "Failed to add timeout event source: %m");
}

View File

@ -95,16 +95,14 @@ static int idle_time_cb(sd_event_source *s, uint64_t usec, void *userdata) {
}
static int connection_release(Connection *c) {
int r;
Context *context = c->context;
usec_t idle_instant;
int r;
connection_free(c);
if (arg_exit_idle_time < USEC_INFINITY && set_isempty(context->connections)) {
idle_instant = usec_add(now(CLOCK_MONOTONIC), arg_exit_idle_time);
if (context->idle_time) {
r = sd_event_source_set_time(context->idle_time, idle_instant);
r = sd_event_source_set_time_relative(context->idle_time, arg_exit_idle_time);
if (r < 0)
return log_error_errno(r, "Error while setting idle time: %m");
@ -112,8 +110,9 @@ static int connection_release(Connection *c) {
if (r < 0)
return log_error_errno(r, "Error while enabling idle time: %m");
} else {
r = sd_event_add_time(context->event, &context->idle_time, CLOCK_MONOTONIC,
idle_instant, 0, idle_time_cb, context);
r = sd_event_add_time_relative(
context->event, &context->idle_time, CLOCK_MONOTONIC,
arg_exit_idle_time, 0, idle_time_cb, context);
if (r < 0)
return log_error_errno(r, "Failed to create idle timer: %m");
}

View File

@ -88,6 +88,7 @@ sd_event* sd_event_unref(sd_event *e);
int sd_event_add_io(sd_event *e, sd_event_source **s, int fd, uint32_t events, sd_event_io_handler_t callback, void *userdata);
int sd_event_add_time(sd_event *e, sd_event_source **s, clockid_t clock, uint64_t usec, uint64_t accuracy, sd_event_time_handler_t callback, void *userdata);
int sd_event_add_time_relative(sd_event *e, sd_event_source **s, clockid_t clock, uint64_t usec, uint64_t accuracy, sd_event_time_handler_t callback, void *userdata);
int sd_event_add_signal(sd_event *e, sd_event_source **s, int sig, sd_event_signal_handler_t callback, void *userdata);
int sd_event_add_child(sd_event *e, sd_event_source **s, pid_t pid, int options, sd_event_child_handler_t callback, void *userdata);
int sd_event_add_child_pidfd(sd_event *e, sd_event_source **s, int pidfd, int options, sd_event_child_handler_t callback, void *userdata);
@ -138,6 +139,7 @@ int sd_event_source_set_io_events(sd_event_source *s, uint32_t events);
int sd_event_source_get_io_revents(sd_event_source *s, uint32_t* revents);
int sd_event_source_get_time(sd_event_source *s, uint64_t *usec);
int sd_event_source_set_time(sd_event_source *s, uint64_t usec);
int sd_event_source_set_time_relative(sd_event_source *s, uint64_t usec);
int sd_event_source_get_time_accuracy(sd_event_source *s, uint64_t *usec);
int sd_event_source_set_time_accuracy(sd_event_source *s, uint64_t usec);
int sd_event_source_get_time_clock(sd_event_source *s, clockid_t *clock);

View File

@ -180,18 +180,18 @@ static int manager_arm_timer(Manager *m, usec_t next) {
}
if (m->event_timer) {
r = sd_event_source_set_time(m->event_timer, now(clock_boottime_or_monotonic()) + next);
r = sd_event_source_set_time_relative(m->event_timer, next);
if (r < 0)
return r;
return sd_event_source_set_enabled(m->event_timer, SD_EVENT_ONESHOT);
}
return sd_event_add_time(
return sd_event_add_time_relative(
m->event,
&m->event_timer,
clock_boottime_or_monotonic(),
now(clock_boottime_or_monotonic()) + next, 0,
next, 0,
manager_timer, m);
}
@ -786,7 +786,7 @@ int manager_connect(Manager *m) {
if (!ratelimit_below(&m->ratelimit)) {
log_debug("Delaying attempts to contact servers.");
r = sd_event_add_time(m->event, &m->event_retry, clock_boottime_or_monotonic(), now(clock_boottime_or_monotonic()) + RETRY_USEC, 0, manager_retry_connect, m);
r = sd_event_add_time_relative(m->event, &m->event_retry, clock_boottime_or_monotonic(), RETRY_USEC, 0, manager_retry_connect, m);
if (r < 0)
return log_error_errno(r, "Failed to create retry timer: %m");
@ -840,7 +840,7 @@ int manager_connect(Manager *m) {
if (restart && !m->exhausted_servers && m->poll_interval_usec) {
log_debug("Waiting after exhausting servers.");
r = sd_event_add_time(m->event, &m->event_retry, clock_boottime_or_monotonic(), now(clock_boottime_or_monotonic()) + m->poll_interval_usec, 0, manager_retry_connect, m);
r = sd_event_add_time_relative(m->event, &m->event_retry, clock_boottime_or_monotonic(), m->poll_interval_usec, 0, manager_retry_connect, m);
if (r < 0)
return log_error_errno(r, "Failed to create retry timer: %m");

View File

@ -392,9 +392,10 @@ int udev_ctrl_wait(struct udev_ctrl *uctrl, usec_t timeout) {
(void) sd_event_source_set_description(source_io, "udev-ctrl-wait-io");
if (timeout != USEC_INFINITY) {
r = sd_event_add_time(uctrl->event, &source_timeout, clock_boottime_or_monotonic(),
usec_add(now(clock_boottime_or_monotonic()), timeout),
0, NULL, INT_TO_PTR(-ETIMEDOUT));
r = sd_event_add_time_relative(
uctrl->event, &source_timeout, clock_boottime_or_monotonic(),
timeout,
0, NULL, INT_TO_PTR(-ETIMEDOUT));
if (r < 0)
return r;

View File

@ -251,7 +251,6 @@ static int on_event_timeout_warning(sd_event_source *s, uint64_t usec, void *use
static void worker_attach_event(struct worker *worker, struct event *event) {
sd_event *e;
uint64_t usec;
assert(worker);
assert(worker->manager);
@ -266,13 +265,13 @@ static void worker_attach_event(struct worker *worker, struct event *event) {
e = worker->manager->event;
assert_se(sd_event_now(e, CLOCK_MONOTONIC, &usec) >= 0);
(void) sd_event_add_time_relative(e, &event->timeout_warning_event, CLOCK_MONOTONIC,
udev_warn_timeout(arg_event_timeout_usec), USEC_PER_SEC,
on_event_timeout_warning, event);
(void) sd_event_add_time(e, &event->timeout_warning_event, CLOCK_MONOTONIC,
usec + udev_warn_timeout(arg_event_timeout_usec), USEC_PER_SEC, on_event_timeout_warning, event);
(void) sd_event_add_time(e, &event->timeout_event, CLOCK_MONOTONIC,
usec + arg_event_timeout_usec, USEC_PER_SEC, on_event_timeout, event);
(void) sd_event_add_time_relative(e, &event->timeout_event, CLOCK_MONOTONIC,
arg_event_timeout_usec, USEC_PER_SEC,
on_event_timeout, event);
}
static void manager_clear_for_worker(Manager *manager) {