From ba4e0427e955a648e24f6506d0cb92857c84b85d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 28 Mar 2022 16:41:10 +0200 Subject: [PATCH] time-util: assume CLOCK_BOOTTIME always exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Let's raise our supported baseline a bit: CLOCK_BOOTTIME started to work with timerfd in kernel 3.15 (i.e. back in 2014), let's require support for it now. This will raise our baseline only modestly from 3.13 → 3.15. --- README | 2 +- src/basic/time-util.c | 56 +++---------------- src/basic/time-util.h | 4 +- src/core/timer.h | 2 +- src/import/curl-util.c | 2 +- src/libsystemd-network/lldp-neighbor.c | 4 +- src/libsystemd-network/sd-dhcp-client.c | 22 ++++---- src/libsystemd-network/sd-dhcp-server.c | 4 +- src/libsystemd-network/sd-dhcp6-client.c | 14 ++--- src/libsystemd-network/sd-ipv4acd.c | 6 +- src/libsystemd-network/sd-lldp-rx.c | 4 +- src/libsystemd-network/sd-lldp-tx.c | 2 +- src/libsystemd-network/sd-ndisc.c | 10 ++-- src/libsystemd-network/sd-radv.c | 8 +-- src/libsystemd-network/test-dhcp-client.c | 2 +- src/libsystemd-network/test-dhcp6-client.c | 2 +- src/libsystemd-network/test-ndisc-ra.c | 2 +- src/libsystemd-network/test-ndisc-rs.c | 4 +- src/libsystemd/sd-event/sd-event.c | 6 -- src/libsystemd/sd-event/test-event.c | 12 ++-- src/machine/machined.c | 2 +- src/network/netdev/wireguard.c | 2 +- src/network/networkd-address.c | 6 +- src/network/networkd-dhcp-prefix-delegation.c | 8 +-- src/network/networkd-dhcp4.c | 2 +- src/network/networkd-dhcp6.c | 2 +- src/network/networkd-link.c | 2 +- src/network/networkd-ndisc.c | 14 ++--- src/network/networkd-route.c | 4 +- src/network/test-networkd-address.c | 2 +- src/network/wait-online/manager.c | 2 +- src/resolve/resolved-dns-cache.c | 6 +- src/resolve/resolved-dns-packet.c | 2 +- src/resolve/resolved-dns-query.c | 2 +- src/resolve/resolved-dns-scope.c | 4 +- src/resolve/resolved-dns-server.c | 4 +- src/resolve/resolved-dns-stream.c | 4 +- src/resolve/resolved-dns-transaction.c | 12 ++-- src/resolve/resolved-etc-hosts.c | 2 +- src/resolve/resolved-manager.c | 2 +- src/resolve/resolved-socket-graveyard.c | 4 +- src/shared/watchdog.c | 6 +- src/test/test-time-util.c | 16 +++--- src/timesync/timesyncd-manager.c | 14 ++--- src/udev/udev-ctrl.c | 2 +- src/udev/udevd.c | 4 +- 46 files changed, 122 insertions(+), 176 deletions(-) diff --git a/README b/README index bbde47fda7..420276eda8 100644 --- a/README +++ b/README @@ -30,7 +30,7 @@ LICENSE: LGPL-2.1-or-later for all code, exceptions noted in LICENSES/README.md REQUIREMENTS: - Linux kernel >= 3.13 + Linux kernel >= 3.15 Linux kernel >= 4.2 for unified cgroup hierarchy support Linux kernel >= 4.10 for cgroup-bpf egress and ingress hooks Linux kernel >= 4.15 for cgroup-bpf device hook diff --git a/src/basic/time-util.c b/src/basic/time-util.c index ebf1dddb56..ad4a189ff7 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -77,7 +77,7 @@ triple_timestamp* triple_timestamp_get(triple_timestamp *ts) { ts->realtime = now(CLOCK_REALTIME); ts->monotonic = now(CLOCK_MONOTONIC); - ts->boottime = clock_boottime_supported() ? now(CLOCK_BOOTTIME) : USEC_INFINITY; + ts->boottime = now(CLOCK_BOOTTIME); return ts; } @@ -150,9 +150,7 @@ triple_timestamp* triple_timestamp_from_realtime(triple_timestamp *ts, usec_t u) ts->realtime = u; ts->monotonic = map_clock_usec_internal(u, nowr, now(CLOCK_MONOTONIC)); - ts->boottime = clock_boottime_supported() ? - map_clock_usec_internal(u, nowr, now(CLOCK_BOOTTIME)) : - USEC_INFINITY; + ts->boottime = map_clock_usec_internal(u, nowr, now(CLOCK_BOOTTIME)); return ts; } @@ -170,8 +168,7 @@ dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u) { return ts; } -dual_timestamp* dual_timestamp_from_boottime_or_monotonic(dual_timestamp *ts, usec_t u) { - clockid_t cid; +dual_timestamp* dual_timestamp_from_boottime(dual_timestamp *ts, usec_t u) { usec_t nowm; if (u == USEC_INFINITY) { @@ -179,14 +176,8 @@ dual_timestamp* dual_timestamp_from_boottime_or_monotonic(dual_timestamp *ts, us return ts; } - cid = clock_boottime_or_monotonic(); - nowm = now(cid); - - if (cid == CLOCK_MONOTONIC) - ts->monotonic = u; - else - ts->monotonic = map_clock_usec_internal(u, nowm, now(CLOCK_MONOTONIC)); - + nowm = now(CLOCK_BOOTTIME); + ts->monotonic = map_clock_usec_internal(u, nowm, now(CLOCK_MONOTONIC)); ts->realtime = map_clock_usec_internal(u, nowm, now(CLOCK_REALTIME)); return ts; } @@ -1461,33 +1452,6 @@ int verify_timezone(const char *name, int log_level) { return 0; } -bool clock_boottime_supported(void) { - static int supported = -1; - - /* Note that this checks whether CLOCK_BOOTTIME is available in general as well as available for timerfds()! */ - - if (supported < 0) { - int fd; - - fd = timerfd_create(CLOCK_BOOTTIME, TFD_NONBLOCK|TFD_CLOEXEC); - if (fd < 0) - supported = false; - else { - safe_close(fd); - supported = true; - } - } - - return supported; -} - -clockid_t clock_boottime_or_monotonic(void) { - if (clock_boottime_supported()) - return CLOCK_BOOTTIME; - else - return CLOCK_MONOTONIC; -} - bool clock_supported(clockid_t clock) { struct timespec ts; @@ -1495,16 +1459,10 @@ bool clock_supported(clockid_t clock) { case CLOCK_MONOTONIC: case CLOCK_REALTIME: + case CLOCK_BOOTTIME: + /* These three are always available in our baseline, and work in timerfd, as of kernel 3.15 */ return true; - case CLOCK_BOOTTIME: - return clock_boottime_supported(); - - case CLOCK_BOOTTIME_ALARM: - if (!clock_boottime_supported()) - return false; - - _fallthrough_; default: /* For everything else, check properly */ return clock_gettime(clock, &ts) >= 0; diff --git a/src/basic/time-util.h b/src/basic/time-util.h index d3a88ed6e4..bf312442b0 100644 --- a/src/basic/time-util.h +++ b/src/basic/time-util.h @@ -82,7 +82,7 @@ usec_t map_clock_usec(usec_t from, clockid_t from_clock, clockid_t to_clock); dual_timestamp* dual_timestamp_get(dual_timestamp *ts); dual_timestamp* dual_timestamp_from_realtime(dual_timestamp *ts, usec_t u); dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u); -dual_timestamp* dual_timestamp_from_boottime_or_monotonic(dual_timestamp *ts, usec_t u); +dual_timestamp* dual_timestamp_from_boottime(dual_timestamp *ts, usec_t u); triple_timestamp* triple_timestamp_get(triple_timestamp *ts); triple_timestamp* triple_timestamp_from_realtime(triple_timestamp *ts, usec_t u); @@ -155,9 +155,7 @@ static inline bool timezone_is_valid(const char *name, int log_level) { return verify_timezone(name, log_level) >= 0; } -bool clock_boottime_supported(void); bool clock_supported(clockid_t clock); -clockid_t clock_boottime_or_monotonic(void); usec_t usec_shift_clock(usec_t, clockid_t from, clockid_t to); diff --git a/src/core/timer.h b/src/core/timer.h index a51fbf56f3..551e283341 100644 --- a/src/core/timer.h +++ b/src/core/timer.h @@ -64,7 +64,7 @@ struct Timer { char *stamp_path; }; -#define TIMER_MONOTONIC_CLOCK(t) ((t)->wake_system && clock_boottime_supported() ? CLOCK_BOOTTIME_ALARM : CLOCK_MONOTONIC) +#define TIMER_MONOTONIC_CLOCK(t) ((t)->wake_system ? CLOCK_BOOTTIME_ALARM : CLOCK_MONOTONIC) void timer_free_values(Timer *t); diff --git a/src/import/curl-util.c b/src/import/curl-util.c index d6a16b4f57..5b39251aa9 100644 --- a/src/import/curl-util.c +++ b/src/import/curl-util.c @@ -148,7 +148,7 @@ static int curl_glue_timer_callback(CURLM *curl, long timeout_ms, void *userdata if (sd_event_source_set_enabled(g->timer, SD_EVENT_ONESHOT) < 0) return -1; } else { - if (sd_event_add_time_relative(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, usec, 0, curl_glue_on_timer, g) < 0) return -1; (void) sd_event_source_set_description(g->timer, "curl-timer"); diff --git a/src/libsystemd-network/lldp-neighbor.c b/src/libsystemd-network/lldp-neighbor.c index 93f6036865..b056019989 100644 --- a/src/libsystemd-network/lldp-neighbor.c +++ b/src/libsystemd-network/lldp-neighbor.c @@ -333,9 +333,9 @@ void lldp_neighbor_start_ttl(sd_lldp_neighbor *n) { usec_t base; /* Use the packet's timestamp if there is one known */ - base = triple_timestamp_by_clock(&n->timestamp, clock_boottime_or_monotonic()); + base = triple_timestamp_by_clock(&n->timestamp, CLOCK_BOOTTIME); if (!timestamp_is_set(base)) - base = now(clock_boottime_or_monotonic()); /* Otherwise, take the current time */ + base = now(CLOCK_BOOTTIME); /* Otherwise, take the current time */ n->until = usec_add(base, n->ttl * USEC_PER_SEC); } else diff --git a/src/libsystemd-network/sd-dhcp-client.c b/src/libsystemd-network/sd-dhcp-client.c index cdf49fc586..e8534e8e86 100644 --- a/src/libsystemd-network/sd-dhcp-client.c +++ b/src/libsystemd-network/sd-dhcp-client.c @@ -821,7 +821,7 @@ static int client_message_init( /* Although 'secs' field is a SHOULD in RFC 2131, certain DHCP servers refuse to issue an DHCP lease if 'secs' is set to zero */ - r = sd_event_now(client->event, clock_boottime_or_monotonic(), &time_now); + r = sd_event_now(client->event, CLOCK_BOOTTIME, &time_now); if (r < 0) return r; assert(time_now >= client->start_time); @@ -1246,7 +1246,7 @@ static int client_timeout_resend( assert(client); assert(client->event); - r = sd_event_now(client->event, clock_boottime_or_monotonic(), &time_now); + r = sd_event_now(client->event, CLOCK_BOOTTIME, &time_now); if (r < 0) goto error; @@ -1294,7 +1294,7 @@ static int client_timeout_resend( } r = event_reset_time(client->event, &client->timeout_resend, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, next_timeout, 10 * USEC_PER_MSEC, client_timeout_resend, client, client->event_priority, "dhcp4-resend-timer", true); @@ -1394,12 +1394,12 @@ static int client_initialize_time_events(sd_dhcp_client *client) { assert(client->event); if (client->start_delay > 0) { - assert_se(sd_event_now(client->event, clock_boottime_or_monotonic(), &usec) >= 0); + assert_se(sd_event_now(client->event, CLOCK_BOOTTIME, &usec) >= 0); usec += client->start_delay; } r = event_reset_time(client->event, &client->timeout_resend, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, usec, 0, client_timeout_resend, client, client->event_priority, "dhcp4-resend-timer", true); @@ -1440,7 +1440,7 @@ static int client_start_delayed(sd_dhcp_client *client) { client->fd = r; if (IN_SET(client->state, DHCP_STATE_INIT, DHCP_STATE_INIT_REBOOT)) - client->start_time = now(clock_boottime_or_monotonic()); + client->start_time = now(CLOCK_BOOTTIME); return client_initialize_events(client, client_receive_message_raw); } @@ -1684,7 +1684,7 @@ static int client_set_lease_timeouts(sd_dhcp_client *client) { return 0; } - r = sd_event_now(client->event, clock_boottime_or_monotonic(), &time_now); + r = sd_event_now(client->event, CLOCK_BOOTTIME, &time_now); if (r < 0) return r; assert(client->request_sent <= time_now); @@ -1717,7 +1717,7 @@ static int client_set_lease_timeouts(sd_dhcp_client *client) { /* arm lifetime timeout */ r = event_reset_time(client->event, &client->timeout_expire, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, client->expire_time, 10 * USEC_PER_MSEC, client_timeout_expire, client, client->event_priority, "dhcp4-lifetime", true); @@ -1733,7 +1733,7 @@ static int client_set_lease_timeouts(sd_dhcp_client *client) { /* arm T2 timeout */ r = event_reset_time(client->event, &client->timeout_t2, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, client->t2_time, 10 * USEC_PER_MSEC, client_timeout_t2, client, client->event_priority, "dhcp4-t2-timeout", true); @@ -1749,7 +1749,7 @@ static int client_set_lease_timeouts(sd_dhcp_client *client) { /* arm T1 timeout */ r = event_reset_time(client->event, &client->timeout_t1, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, client->t1_time, 10 * USEC_PER_MSEC, client_timeout_t1, client, client->event_priority, "dhcp4-t1-timer", true); @@ -1784,7 +1784,7 @@ static int client_handle_message(sd_dhcp_client *client, DHCPMessage *message, i client->attempt = 0; r = event_reset_time(client->event, &client->timeout_resend, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, 0, 0, client_timeout_resend, client, client->event_priority, "dhcp4-resend-timer", true); diff --git a/src/libsystemd-network/sd-dhcp-server.c b/src/libsystemd-network/sd-dhcp-server.c index b9ff27b9e1..64f5286ead 100644 --- a/src/libsystemd-network/sd-dhcp-server.c +++ b/src/libsystemd-network/sd-dhcp-server.c @@ -987,7 +987,7 @@ static int server_ack_request(sd_dhcp_server *server, DHCPRequest *req, DHCPLeas assert(req); assert(address != 0); - r = sd_event_now(server->event, clock_boottime_or_monotonic(), &time_now); + r = sd_event_now(server->event, CLOCK_BOOTTIME, &time_now); if (r < 0) return r; @@ -1039,7 +1039,7 @@ static int dhcp_server_cleanup_expired_leases(sd_dhcp_server *server) { assert(server); - r = sd_event_now(server->event, clock_boottime_or_monotonic(), &time_now); + r = sd_event_now(server->event, CLOCK_BOOTTIME, &time_now); if (r < 0) return r; diff --git a/src/libsystemd-network/sd-dhcp6-client.c b/src/libsystemd-network/sd-dhcp6-client.c index a0faa1ec86..27864a0a49 100644 --- a/src/libsystemd-network/sd-dhcp6-client.c +++ b/src/libsystemd-network/sd-dhcp6-client.c @@ -649,7 +649,7 @@ int dhcp6_client_send_message(sd_dhcp6_client *client) { assert(client); assert(client->event); - r = sd_event_now(client->event, clock_boottime_or_monotonic(), &time_now); + r = sd_event_now(client->event, CLOCK_BOOTTIME, &time_now); if (r < 0) return r; @@ -830,7 +830,7 @@ static int client_timeout_resend(sd_event_source *s, uint64_t usec, void *userda FORMAT_TIMESPAN(client->retransmit_time, USEC_PER_SEC)); r = event_reset_time_relative(client->event, &client->timeout_resend, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, client->retransmit_time, 10 * USEC_PER_MSEC, client_timeout_resend, client, client->event_priority, "dhcp6-resend-timer", true); @@ -872,12 +872,12 @@ static int client_start_transaction(sd_dhcp6_client *client, DHCP6State state) { client->retransmit_count = 0; client->transaction_id = random_u32() & htobe32(0x00ffffff); - r = sd_event_now(client->event, clock_boottime_or_monotonic(), &client->transaction_start); + r = sd_event_now(client->event, CLOCK_BOOTTIME, &client->transaction_start); if (r < 0) goto error; r = event_reset_time(client->event, &client->timeout_resend, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, 0, 0, client_timeout_resend, client, client->event_priority, "dhcp6-resend-timeout", true); @@ -969,7 +969,7 @@ static int client_enter_bound_state(sd_dhcp6_client *client) { } else { log_dhcp6_client(client, "T1 expires in %s", FORMAT_TIMESPAN(lifetime_t1, USEC_PER_SEC)); r = event_reset_time_relative(client->event, &client->timeout_t1, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, lifetime_t1, 10 * USEC_PER_SEC, client_timeout_t1, client, client->event_priority, "dhcp6-t1-timeout", true); @@ -983,7 +983,7 @@ static int client_enter_bound_state(sd_dhcp6_client *client) { } else { log_dhcp6_client(client, "T2 expires in %s", FORMAT_TIMESPAN(lifetime_t2, USEC_PER_SEC)); r = event_reset_time_relative(client->event, &client->timeout_t2, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, lifetime_t2, 10 * USEC_PER_SEC, client_timeout_t2, client, client->event_priority, "dhcp6-t2-timeout", true); @@ -998,7 +998,7 @@ static int client_enter_bound_state(sd_dhcp6_client *client) { log_dhcp6_client(client, "Valid lifetime expires in %s", FORMAT_TIMESPAN(lifetime_valid, USEC_PER_SEC)); r = event_reset_time_relative(client->event, &client->timeout_expire, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, lifetime_valid, USEC_PER_SEC, client_timeout_expire, client, client->event_priority, "dhcp6-lease-expire", true); diff --git a/src/libsystemd-network/sd-ipv4acd.c b/src/libsystemd-network/sd-ipv4acd.c index 232b3b0333..8303e7fb34 100644 --- a/src/libsystemd-network/sd-ipv4acd.c +++ b/src/libsystemd-network/sd-ipv4acd.c @@ -200,10 +200,10 @@ static int ipv4acd_set_next_wakeup(sd_ipv4acd *acd, usec_t usec, usec_t random_u if (random_usec > 0) next_timeout += (usec_t) random_u64() % random_usec; - assert_se(sd_event_now(acd->event, clock_boottime_or_monotonic(), &time_now) >= 0); + assert_se(sd_event_now(acd->event, CLOCK_BOOTTIME, &time_now) >= 0); return event_reset_time(acd->event, &acd->timer_event_source, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, time_now + next_timeout, 0, ipv4acd_on_timeout, acd, acd->event_priority, "ipv4acd-timer", true); @@ -381,7 +381,7 @@ static int ipv4acd_on_packet( if (ipv4acd_arp_conflict(acd, &packet, true)) { usec_t ts; - assert_se(sd_event_now(acd->event, clock_boottime_or_monotonic(), &ts) >= 0); + assert_se(sd_event_now(acd->event, CLOCK_BOOTTIME, &ts) >= 0); /* Defend address */ if (ts > acd->defend_window) { diff --git a/src/libsystemd-network/sd-lldp-rx.c b/src/libsystemd-network/sd-lldp-rx.c index 34bdcb644b..d4762bf097 100644 --- a/src/libsystemd-network/sd-lldp-rx.c +++ b/src/libsystemd-network/sd-lldp-rx.c @@ -69,7 +69,7 @@ static int lldp_rx_make_space(sd_lldp_rx *lldp_rx, size_t extra) { goto remove_one; if (t == USEC_INFINITY) - t = now(clock_boottime_or_monotonic()); + t = now(CLOCK_BOOTTIME); if (n->until > t) break; @@ -448,7 +448,7 @@ static int lldp_rx_start_timer(sd_lldp_rx *lldp_rx, sd_lldp_neighbor *neighbor) return event_source_disable(lldp_rx->timer_event_source); return event_reset_time(lldp_rx->event, &lldp_rx->timer_event_source, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, n->until, 0, on_timer_event, lldp_rx, lldp_rx->event_priority, "lldp-rx-timer", true); diff --git a/src/libsystemd-network/sd-lldp-tx.c b/src/libsystemd-network/sd-lldp-tx.c index a5f60346eb..136059fa7f 100644 --- a/src/libsystemd-network/sd-lldp-tx.c +++ b/src/libsystemd-network/sd-lldp-tx.c @@ -609,7 +609,7 @@ int sd_lldp_tx_start(sd_lldp_tx *lldp_tx) { delay = lldp_tx_get_delay(lldp_tx); r = sd_event_add_time_relative(lldp_tx->event, &lldp_tx->timer_event_source, - clock_boottime_or_monotonic(), delay, 0, + CLOCK_BOOTTIME, delay, 0, on_timer_event, lldp_tx); if (r < 0) return r; diff --git a/src/libsystemd-network/sd-ndisc.c b/src/libsystemd-network/sd-ndisc.c index 7e16f51299..ecd552ca0c 100644 --- a/src/libsystemd-network/sd-ndisc.c +++ b/src/libsystemd-network/sd-ndisc.c @@ -269,7 +269,7 @@ static int ndisc_timeout(sd_event_source *s, uint64_t usec, void *userdata) { assert(nd); assert(nd->event); - assert_se(sd_event_now(nd->event, clock_boottime_or_monotonic(), &time_now) >= 0); + assert_se(sd_event_now(nd->event, CLOCK_BOOTTIME, &time_now) >= 0); if (!nd->retransmit_time) nd->retransmit_time = ndisc_timeout_compute_random(NDISC_ROUTER_SOLICITATION_INTERVAL); @@ -281,7 +281,7 @@ static int ndisc_timeout(sd_event_source *s, uint64_t usec, void *userdata) { } r = event_reset_time(nd->event, &nd->timeout_event_source, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, time_now + nd->retransmit_time, 10 * USEC_PER_MSEC, ndisc_timeout, nd, nd->event_priority, "ndisc-timeout-no-ra", true); @@ -344,7 +344,7 @@ int sd_ndisc_start(sd_ndisc *nd) { assert(!nd->recv_event_source); - r = sd_event_now(nd->event, clock_boottime_or_monotonic(), &time_now); + r = sd_event_now(nd->event, CLOCK_BOOTTIME, &time_now); if (r < 0) goto fail; @@ -363,7 +363,7 @@ int sd_ndisc_start(sd_ndisc *nd) { (void) sd_event_source_set_description(nd->recv_event_source, "ndisc-receive-message"); r = event_reset_time(nd->event, &nd->timeout_event_source, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, time_now + USEC_PER_SEC / 2, 1 * USEC_PER_SEC, /* See RFC 8415 sec. 18.2.1 */ ndisc_timeout, nd, nd->event_priority, "ndisc-timeout", true); @@ -371,7 +371,7 @@ int sd_ndisc_start(sd_ndisc *nd) { goto fail; r = event_reset_time(nd->event, &nd->timeout_no_ra, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, time_now + NDISC_TIMEOUT_NO_RA_USEC, 10 * USEC_PER_MSEC, ndisc_timeout_no_ra, nd, nd->event_priority, "ndisc-timeout-no-ra", true); diff --git a/src/libsystemd-network/sd-radv.c b/src/libsystemd-network/sd-radv.c index 370a10a013..7b5c12e489 100644 --- a/src/libsystemd-network/sd-radv.c +++ b/src/libsystemd-network/sd-radv.c @@ -181,7 +181,7 @@ static int radv_send(sd_radv *ra, const struct in6_addr *dst, usec_t lifetime_us assert(ra); assert(router_lifetime_is_valid(lifetime_usec)); - r = sd_event_now(ra->event, clock_boottime_or_monotonic(), &time_now); + r = sd_event_now(ra->event, CLOCK_BOOTTIME, &time_now); if (r < 0) return r; @@ -321,7 +321,7 @@ static int radv_timeout(sd_event_source *s, uint64_t usec, void *userdata) { assert(ra->event); assert(router_lifetime_is_valid(ra->lifetime_usec)); - r = sd_event_now(ra->event, clock_boottime_or_monotonic(), &time_now); + r = sd_event_now(ra->event, CLOCK_BOOTTIME, &time_now); if (r < 0) goto fail; @@ -357,7 +357,7 @@ static int radv_timeout(sd_event_source *s, uint64_t usec, void *userdata) { log_radv(ra, "Next Router Advertisement in %s", FORMAT_TIMESPAN(timeout, USEC_PER_SEC)); r = event_reset_time(ra->event, &ra->timeout_event_source, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, usec_add(time_now, timeout), MSEC_PER_SEC, radv_timeout, ra, ra->event_priority, "radv-timeout", true); @@ -409,7 +409,7 @@ int sd_radv_start(sd_radv *ra) { return 0; r = event_reset_time(ra->event, &ra->timeout_event_source, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, 0, 0, radv_timeout, ra, ra->event_priority, "radv-timeout", true); diff --git a/src/libsystemd-network/test-dhcp-client.c b/src/libsystemd-network/test-dhcp-client.c index dd95aaf588..7497c3ef3a 100644 --- a/src/libsystemd-network/test-dhcp-client.c +++ b/src/libsystemd-network/test-dhcp-client.c @@ -507,7 +507,7 @@ static void test_addr_acq(sd_event *e) { callback_recv = test_addr_acq_recv_discover; - assert_se(sd_event_add_time_relative(e, NULL, clock_boottime_or_monotonic(), + assert_se(sd_event_add_time_relative(e, NULL, CLOCK_BOOTTIME, 2 * USEC_PER_SEC, 0, NULL, INT_TO_PTR(-ETIMEDOUT)) >= 0); diff --git a/src/libsystemd-network/test-dhcp6-client.c b/src/libsystemd-network/test-dhcp6-client.c index dfd9042c29..8278a3875a 100644 --- a/src/libsystemd-network/test-dhcp6-client.c +++ b/src/libsystemd-network/test-dhcp6-client.c @@ -965,7 +965,7 @@ TEST(dhcp6_client) { _cleanup_(sd_event_unrefp) sd_event *e = NULL; assert_se(sd_event_new(&e) >= 0); - assert_se(sd_event_add_time_relative(e, NULL, clock_boottime_or_monotonic(), + assert_se(sd_event_add_time_relative(e, NULL, CLOCK_BOOTTIME, 2 * USEC_PER_SEC, 0, NULL, INT_TO_PTR(-ETIMEDOUT)) >= 0); diff --git a/src/libsystemd-network/test-ndisc-ra.c b/src/libsystemd-network/test-ndisc-ra.c index cbf065d4fb..d4f8cf89b9 100644 --- a/src/libsystemd-network/test-ndisc-ra.c +++ b/src/libsystemd-network/test-ndisc-ra.c @@ -327,7 +327,7 @@ TEST(ra) { assert_se(sd_event_add_io(e, &recv_router_advertisement, test_fd[0], EPOLLIN, radv_recv, ra) >= 0); - assert_se(sd_event_add_time_relative(e, NULL, clock_boottime_or_monotonic(), + assert_se(sd_event_add_time_relative(e, NULL, CLOCK_BOOTTIME, 2 * USEC_PER_SEC, 0, NULL, INT_TO_PTR(-ETIMEDOUT)) >= 0); diff --git a/src/libsystemd-network/test-ndisc-rs.c b/src/libsystemd-network/test-ndisc-rs.c index 2c27d12b09..13db49ea4d 100644 --- a/src/libsystemd-network/test-ndisc-rs.c +++ b/src/libsystemd-network/test-ndisc-rs.c @@ -274,7 +274,7 @@ TEST(rs) { 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_relative(e, NULL, clock_boottime_or_monotonic(), + assert_se(sd_event_add_time_relative(e, NULL, CLOCK_BOOTTIME, 30 * USEC_PER_SEC, 0, NULL, INT_TO_PTR(-ETIMEDOUT)) >= 0); @@ -362,7 +362,7 @@ TEST(timeout) { 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_relative(e, NULL, clock_boottime_or_monotonic(), + assert_se(sd_event_add_time_relative(e, NULL, CLOCK_BOOTTIME, 30 * USEC_PER_SEC, 0, NULL, INT_TO_PTR(-ETIMEDOUT)) >= 0); diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index 38b2ef510b..4dbdf19872 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -4313,12 +4313,6 @@ _public_ int sd_event_now(sd_event *e, clockid_t clock, uint64_t *usec) { if (!TRIPLE_TIMESTAMP_HAS_CLOCK(clock)) return -EOPNOTSUPP; - /* Generate a clean error in case CLOCK_BOOTTIME is not available. Note that don't use clock_supported() here, - * for a reason: there are systems where CLOCK_BOOTTIME is supported, but CLOCK_BOOTTIME_ALARM is not, but for - * the purpose of getting the time this doesn't matter. */ - if (IN_SET(clock, CLOCK_BOOTTIME, CLOCK_BOOTTIME_ALARM) && !clock_boottime_supported()) - return -EOPNOTSUPP; - if (!triple_timestamp_is_set(&e->timestamp)) { /* Implicitly fall back to now() if we never ran before and thus have no cached time. */ *usec = now(clock); diff --git a/src/libsystemd/sd-event/test-event.c b/src/libsystemd/sd-event/test-event.c index f902c4e3ff..ea29def3d5 100644 --- a/src/libsystemd/sd-event/test-event.c +++ b/src/libsystemd/sd-event/test-event.c @@ -315,10 +315,8 @@ TEST(sd_event_now) { assert_se(sd_event_now(e, CLOCK_MONOTONIC, &event_now) > 0); assert_se(sd_event_now(e, CLOCK_REALTIME, &event_now) > 0); assert_se(sd_event_now(e, CLOCK_REALTIME_ALARM, &event_now) > 0); - if (clock_boottime_supported()) { - assert_se(sd_event_now(e, CLOCK_BOOTTIME, &event_now) > 0); - assert_se(sd_event_now(e, CLOCK_BOOTTIME_ALARM, &event_now) > 0); - } + assert_se(sd_event_now(e, CLOCK_BOOTTIME, &event_now) > 0); + assert_se(sd_event_now(e, CLOCK_BOOTTIME_ALARM, &event_now) > 0); assert_se(sd_event_now(e, -1, &event_now) == -EOPNOTSUPP); assert_se(sd_event_now(e, 900 /* arbitrary big number */, &event_now) == -EOPNOTSUPP); @@ -327,10 +325,8 @@ TEST(sd_event_now) { assert_se(sd_event_now(e, CLOCK_MONOTONIC, &event_now) == 0); assert_se(sd_event_now(e, CLOCK_REALTIME, &event_now) == 0); assert_se(sd_event_now(e, CLOCK_REALTIME_ALARM, &event_now) == 0); - if (clock_boottime_supported()) { - assert_se(sd_event_now(e, CLOCK_BOOTTIME, &event_now) == 0); - assert_se(sd_event_now(e, CLOCK_BOOTTIME_ALARM, &event_now) == 0); - } + assert_se(sd_event_now(e, CLOCK_BOOTTIME, &event_now) == 0); + assert_se(sd_event_now(e, CLOCK_BOOTTIME_ALARM, &event_now) == 0); assert_se(sd_event_now(e, -1, &event_now) == -EOPNOTSUPP); assert_se(sd_event_now(e, 900 /* arbitrary big number */, &event_now) == -EOPNOTSUPP); } diff --git a/src/machine/machined.c b/src/machine/machined.c index a433afb1a6..9ecba8720f 100644 --- a/src/machine/machined.c +++ b/src/machine/machined.c @@ -127,7 +127,7 @@ static int manager_add_host_machine(Manager *m) { t->root_directory = TAKE_PTR(rd); t->unit = TAKE_PTR(unit); - dual_timestamp_from_boottime_or_monotonic(&t->timestamp, 0); + dual_timestamp_from_boottime(&t->timestamp, 0); m->host_machine = t; diff --git a/src/network/netdev/wireguard.c b/src/network/netdev/wireguard.c index 9e98b93a5c..32525e6200 100644 --- a/src/network/netdev/wireguard.c +++ b/src/network/netdev/wireguard.c @@ -375,7 +375,7 @@ static int wireguard_peer_resolve_handler( if (peer->n_retries > 0) { r = event_reset_time_relative(netdev->manager->event, &peer->resolve_retry_event_source, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, peer_next_resolve_usec(peer), 0, on_resolve_retry, peer, 0, "wireguard-resolve-retry", true); if (r < 0) diff --git a/src/network/networkd-address.c b/src/network/networkd-address.c index eba28cfc67..afcd53cbc7 100644 --- a/src/network/networkd-address.c +++ b/src/network/networkd-address.c @@ -218,7 +218,7 @@ static struct ifa_cacheinfo *address_set_cinfo(const Address *a, struct ifa_cach assert(a); assert(cinfo); - now_usec = now(clock_boottime_or_monotonic()); + now_usec = now(CLOCK_BOOTTIME); *cinfo = (struct ifa_cacheinfo) { .ifa_valid = MIN(usec_sub_unsigned(a->lifetime_valid_usec, now_usec) / USEC_PER_SEC, UINT32_MAX), @@ -234,7 +234,7 @@ static void address_set_lifetime(Address *a, const struct ifa_cacheinfo *cinfo) assert(a); assert(cinfo); - now_usec = now(clock_boottime_or_monotonic()); + now_usec = now(CLOCK_BOOTTIME); if (cinfo->ifa_valid == UINT32_MAX) a->lifetime_valid_usec = USEC_INFINITY; @@ -643,7 +643,7 @@ const char* format_lifetime(char *buf, size_t l, usec_t lifetime_usec) { sprintf(buf, "for "); /* format_timespan() never fails */ - assert_se(format_timespan(buf + 4, l - 4, usec_sub_unsigned(lifetime_usec, now(clock_boottime_or_monotonic())), USEC_PER_SEC)); + assert_se(format_timespan(buf + 4, l - 4, usec_sub_unsigned(lifetime_usec, now(CLOCK_BOOTTIME)), USEC_PER_SEC)); return buf; } diff --git a/src/network/networkd-dhcp-prefix-delegation.c b/src/network/networkd-dhcp-prefix-delegation.c index 775acb3f95..d8d9475635 100644 --- a/src/network/networkd-dhcp-prefix-delegation.c +++ b/src/network/networkd-dhcp-prefix-delegation.c @@ -886,7 +886,7 @@ static int dhcp4_pd_assign_subnet_prefix(Link *link, Link *uplink) { if (r < 0) return log_link_warning_errno(uplink, r, "Failed to get lifetime of DHCPv4 lease: %m"); - lifetime_usec = usec_add(lifetime_sec * USEC_PER_SEC, now(clock_boottime_or_monotonic())); + lifetime_usec = usec_add(lifetime_sec * USEC_PER_SEC, now(CLOCK_BOOTTIME)); r = sd_dhcp_lease_get_6rd(uplink->dhcp_lease, &ipv4masklen, &sixrd_prefixlen, &sixrd_prefix, &br_addresses, NULL); if (r < 0) @@ -958,7 +958,7 @@ int dhcp4_pd_prefix_acquired(Link *uplink) { if (r < 0) return log_link_warning_errno(uplink, r, "Failed to get lifetime of DHCPv4 lease: %m"); - lifetime_usec = usec_add(lifetime_sec * USEC_PER_SEC, now(clock_boottime_or_monotonic())); + lifetime_usec = usec_add(lifetime_sec * USEC_PER_SEC, now(CLOCK_BOOTTIME)); r = sd_dhcp_lease_get_server_identifier(uplink->dhcp_lease, &server_address.in); if (r < 0) @@ -1045,7 +1045,7 @@ static int dhcp6_pd_assign_subnet_prefixes(Link *link, Link *uplink) { if (r <= 0) return r; - r = sd_dhcp6_lease_get_timestamp(uplink->dhcp6_lease, clock_boottime_or_monotonic(), ×tamp_usec); + r = sd_dhcp6_lease_get_timestamp(uplink->dhcp6_lease, CLOCK_BOOTTIME, ×tamp_usec); if (r < 0) return r; @@ -1094,7 +1094,7 @@ int dhcp6_pd_prefix_acquired(Link *uplink) { if (r < 0) return log_link_warning_errno(uplink, r, "Failed to get server address of DHCPv6 lease: %m"); - r = sd_dhcp6_lease_get_timestamp(uplink->dhcp6_lease, clock_boottime_or_monotonic(), ×tamp_usec); + r = sd_dhcp6_lease_get_timestamp(uplink->dhcp6_lease, CLOCK_BOOTTIME, ×tamp_usec); if (r < 0) return log_link_warning_errno(uplink, r, "Failed to get timestamp of DHCPv6 lease: %m"); diff --git a/src/network/networkd-dhcp4.c b/src/network/networkd-dhcp4.c index 0f7be769ea..6bfcf67dd9 100644 --- a/src/network/networkd-dhcp4.c +++ b/src/network/networkd-dhcp4.c @@ -871,7 +871,7 @@ static int dhcp4_request_address(Link *link, bool announce) { if (r < 0) return log_link_warning_errno(link, r, "DHCP error: no lifetime: %m"); - lifetime_usec = usec_add(lifetime_sec * USEC_PER_SEC, now(clock_boottime_or_monotonic())); + lifetime_usec = usec_add(lifetime_sec * USEC_PER_SEC, now(CLOCK_BOOTTIME)); } else lifetime_usec = USEC_INFINITY; diff --git a/src/network/networkd-dhcp6.c b/src/network/networkd-dhcp6.c index c443098889..d4b61ad79e 100644 --- a/src/network/networkd-dhcp6.c +++ b/src/network/networkd-dhcp6.c @@ -258,7 +258,7 @@ static int dhcp6_address_acquired(Link *link) { if (r < 0) return log_link_warning_errno(link, r, "Failed to get server address of DHCPv6 lease: %m"); - r = sd_dhcp6_lease_get_timestamp(link->dhcp6_lease, clock_boottime_or_monotonic(), ×tamp_usec); + r = sd_dhcp6_lease_get_timestamp(link->dhcp6_lease, CLOCK_BOOTTIME, ×tamp_usec); if (r < 0) return log_link_warning_errno(link, r, "Failed to get timestamp of DHCPv6 lease: %m"); diff --git a/src/network/networkd-link.c b/src/network/networkd-link.c index 4312c6c7bb..d509855f48 100644 --- a/src/network/networkd-link.c +++ b/src/network/networkd-link.c @@ -1659,7 +1659,7 @@ static int link_carrier_lost(Link *link) { return event_reset_time_relative(link->manager->event, &link->carrier_lost_timer, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, link->network->ignore_carrier_loss_usec, 0, link_carrier_lost_handler, diff --git a/src/network/networkd-ndisc.c b/src/network/networkd-ndisc.c index 63e5ff6cc6..3078f82a44 100644 --- a/src/network/networkd-ndisc.c +++ b/src/network/networkd-ndisc.c @@ -316,7 +316,7 @@ static int ndisc_router_process_default(Link *link, sd_ndisc_router *rt) { if (lifetime_sec == 0) /* not a default router */ return 0; - r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), ×tamp_usec); + r = sd_ndisc_router_get_timestamp(rt, CLOCK_BOOTTIME, ×tamp_usec); if (r < 0) return log_link_error_errno(link, r, "Failed to get RA timestamp: %m"); @@ -410,7 +410,7 @@ static int ndisc_router_process_autonomous_prefix(Link *link, sd_ndisc_router *r if (!link->network->ipv6_accept_ra_use_autonomous_prefix) return 0; - r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), ×tamp_usec); + r = sd_ndisc_router_get_timestamp(rt, CLOCK_BOOTTIME, ×tamp_usec); if (r < 0) return log_link_error_errno(link, r, "Failed to get RA timestamp: %m"); @@ -510,7 +510,7 @@ static int ndisc_router_process_onlink_prefix(Link *link, sd_ndisc_router *rt) { if (lifetime_sec == 0) return 0; - r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), ×tamp_usec); + r = sd_ndisc_router_get_timestamp(rt, CLOCK_BOOTTIME, ×tamp_usec); if (r < 0) return log_link_error_errno(link, r, "Failed to get RA timestamp: %m"); @@ -652,7 +652,7 @@ static int ndisc_router_process_route(Link *link, sd_ndisc_router *rt) { if (r < 0) return log_link_error_errno(link, r, "Failed to get default router preference from RA: %m"); - r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), ×tamp_usec); + r = sd_ndisc_router_get_timestamp(rt, CLOCK_BOOTTIME, ×tamp_usec); if (r < 0) return log_link_error_errno(link, r, "Failed to get RA timestamp: %m"); @@ -709,7 +709,7 @@ static int ndisc_router_process_rdnss(Link *link, sd_ndisc_router *rt) { if (r < 0) return log_link_error_errno(link, r, "Failed to get router address from RA: %m"); - r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), ×tamp_usec); + r = sd_ndisc_router_get_timestamp(rt, CLOCK_BOOTTIME, ×tamp_usec); if (r < 0) return log_link_error_errno(link, r, "Failed to get RA timestamp: %m"); @@ -803,7 +803,7 @@ static int ndisc_router_process_dnssl(Link *link, sd_ndisc_router *rt) { if (r < 0) return log_link_error_errno(link, r, "Failed to get router address from RA: %m"); - r = sd_ndisc_router_get_timestamp(rt, clock_boottime_or_monotonic(), ×tamp_usec); + r = sd_ndisc_router_get_timestamp(rt, CLOCK_BOOTTIME, ×tamp_usec); if (r < 0) return log_link_error_errno(link, r, "Failed to get RA timestamp: %m"); @@ -1168,7 +1168,7 @@ void ndisc_vacuum(Link *link) { /* Removes all RDNSS and DNSSL entries whose validity time has passed */ - time_now = now(clock_boottime_or_monotonic()); + time_now = now(CLOCK_BOOTTIME); SET_FOREACH(r, link->ndisc_rdnss) if (r->lifetime_usec < time_now) diff --git a/src/network/networkd-route.c b/src/network/networkd-route.c index c9fb872ae5..934fed3b7f 100644 --- a/src/network/networkd-route.c +++ b/src/network/networkd-route.c @@ -1041,7 +1041,7 @@ static int route_setup_timer(Route *route, const struct rta_cacheinfo *cacheinfo /* Assume that non-zero rta_expires means kernel will handle the route expiration. */ return 0; - r = event_reset_time(manager->event, &route->expire, clock_boottime_or_monotonic(), + r = event_reset_time(manager->event, &route->expire, CLOCK_BOOTTIME, route->lifetime_usec, 0, route_expire_handler, route, 0, "route-expiration", true); if (r < 0) return r; @@ -1179,7 +1179,7 @@ static int route_configure(const Route *route, Link *link, Request *req) { if (route->lifetime_usec != USEC_INFINITY) { r = sd_netlink_message_append_u32(m, RTA_EXPIRES, - MIN(DIV_ROUND_UP(usec_sub_unsigned(route->lifetime_usec, now(clock_boottime_or_monotonic())), USEC_PER_SEC), UINT32_MAX)); + MIN(DIV_ROUND_UP(usec_sub_unsigned(route->lifetime_usec, now(CLOCK_BOOTTIME)), USEC_PER_SEC), UINT32_MAX)); if (r < 0) return r; } diff --git a/src/network/test-networkd-address.c b/src/network/test-networkd-address.c index e0d85b2b79..a40c571483 100644 --- a/src/network/test-networkd-address.c +++ b/src/network/test-networkd-address.c @@ -14,7 +14,7 @@ static void test_FORMAT_LIFETIME_one(usec_t lifetime, const char *expected) { TEST(FORMAT_LIFETIME) { usec_t now_usec; - now_usec = now(clock_boottime_or_monotonic()); + now_usec = now(CLOCK_BOOTTIME); test_FORMAT_LIFETIME_one(now_usec, "for 0"); test_FORMAT_LIFETIME_one(usec_add(now_usec, 2 * USEC_PER_SEC - 1), "for 1s"); diff --git a/src/network/wait-online/manager.c b/src/network/wait-online/manager.c index 093622270d..e5e23979ea 100644 --- a/src/network/wait-online/manager.c +++ b/src/network/wait-online/manager.c @@ -380,7 +380,7 @@ int manager_new(Manager **ret, (void) sd_event_add_signal(m->event, NULL, SIGINT, NULL, NULL); if (timeout > 0) { - r = sd_event_add_time_relative(m->event, NULL, clock_boottime_or_monotonic(), timeout, 0, NULL, INT_TO_PTR(-ETIMEDOUT)); + r = sd_event_add_time_relative(m->event, NULL, CLOCK_BOOTTIME, timeout, 0, NULL, INT_TO_PTR(-ETIMEDOUT)); if (r < 0 && r != -EOVERFLOW) return r; } diff --git a/src/resolve/resolved-dns-cache.c b/src/resolve/resolved-dns-cache.c index 3dce32ed38..45bcbfd9d7 100644 --- a/src/resolve/resolved-dns-cache.c +++ b/src/resolve/resolved-dns-cache.c @@ -214,7 +214,7 @@ void dns_cache_prune(DnsCache *c) { break; if (t <= 0) - t = now(clock_boottime_or_monotonic()); + t = now(CLOCK_BOOTTIME); if (i->until > t) break; @@ -735,7 +735,7 @@ int dns_cache_put( /* Make some space for our new entries */ dns_cache_make_space(c, cache_keys); - timestamp = now(clock_boottime_or_monotonic()); + timestamp = now(CLOCK_BOOTTIME); /* Second, add in positive entries for all contained RRs */ DNS_ANSWER_FOREACH_ITEM(item, answer) { @@ -1016,7 +1016,7 @@ int dns_cache_lookup( if (FLAGS_SET(query_flags, SD_RESOLVED_CLAMP_TTL)) { /* 'current' is always passed to answer_add_clamp_ttl(), but is only used conditionally. * We'll do the same assert there to make sure that it was initialized properly. */ - current = now(clock_boottime_or_monotonic()); + current = now(CLOCK_BOOTTIME); assert(current > 0); } diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c index 74396f14a8..48b91d6870 100644 --- a/src/resolve/resolved-dns-packet.c +++ b/src/resolve/resolved-dns-packet.c @@ -2502,7 +2502,7 @@ int dns_packet_patch_ttls(DnsPacket *p, usec_t timestamp) { usec_t k; int r; - k = now(clock_boottime_or_monotonic()); + k = now(CLOCK_BOOTTIME); assert(k >= timestamp); k -= timestamp; diff --git a/src/resolve/resolved-dns-query.c b/src/resolve/resolved-dns-query.c index b7cb21dd49..b62c5c349f 100644 --- a/src/resolve/resolved-dns-query.c +++ b/src/resolve/resolved-dns-query.c @@ -777,7 +777,7 @@ int dns_query_go(DnsQuery *q) { r = event_reset_time_relative( q->manager->event, &q->timeout_event_source, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, SD_RESOLVED_QUERY_TIMEOUT_USEC, 0, on_query_timeout, q, 0, "query-timeout", true); diff --git a/src/resolve/resolved-dns-scope.c b/src/resolve/resolved-dns-scope.c index 96978f8ac3..a872e9d255 100644 --- a/src/resolve/resolved-dns-scope.c +++ b/src/resolve/resolved-dns-scope.c @@ -1239,7 +1239,7 @@ int dns_scope_notify_conflict(DnsScope *scope, DnsResourceRecord *rr) { r = sd_event_add_time_relative( scope->manager->event, &scope->conflict_event_source, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, jitter, LLMNR_JITTER_INTERVAL_USEC, on_conflict_dispatch, scope); @@ -1509,7 +1509,7 @@ int dns_scope_announce(DnsScope *scope, bool goodbye) { r = sd_event_add_time_relative( scope->manager->event, &scope->announce_event_source, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, MDNS_ANNOUNCE_DELAY, MDNS_JITTER_RANGE_USEC, on_announcement_timeout, scope); diff --git a/src/resolve/resolved-dns-server.c b/src/resolve/resolved-dns-server.c index c2b608d383..2ef2568dac 100644 --- a/src/resolve/resolved-dns-server.c +++ b/src/resolve/resolved-dns-server.c @@ -230,7 +230,7 @@ static void dns_server_verified(DnsServer *s, DnsServerFeatureLevel level) { s->verified_feature_level = level; } - assert_se(sd_event_now(s->manager->event, clock_boottime_or_monotonic(), &s->verified_usec) >= 0); + assert_se(sd_event_now(s->manager->event, CLOCK_BOOTTIME, &s->verified_usec) >= 0); } static void dns_server_reset_counters(DnsServer *s) { @@ -405,7 +405,7 @@ static bool dns_server_grace_period_expired(DnsServer *s) { if (s->verified_usec == 0) return false; - assert_se(sd_event_now(s->manager->event, clock_boottime_or_monotonic(), &ts) >= 0); + assert_se(sd_event_now(s->manager->event, CLOCK_BOOTTIME, &ts) >= 0); if (s->verified_usec + s->features_grace_period_usec > ts) return false; diff --git a/src/resolve/resolved-dns-stream.c b/src/resolve/resolved-dns-stream.c index 61e92bea83..4018113d54 100644 --- a/src/resolve/resolved-dns-stream.c +++ b/src/resolve/resolved-dns-stream.c @@ -390,7 +390,7 @@ static int on_stream_io(sd_event_source *es, int fd, uint32_t revents, void *use s->read_packet->family = s->peer.sa.sa_family; s->read_packet->ttl = s->ttl; s->read_packet->ifindex = s->ifindex; - s->read_packet->timestamp = now(clock_boottime_or_monotonic()); + s->read_packet->timestamp = now(CLOCK_BOOTTIME); if (s->read_packet->family == AF_INET) { s->read_packet->sender.in = s->peer.in.sin_addr; @@ -543,7 +543,7 @@ int dns_stream_new( r = sd_event_add_time_relative( m->event, &s->timeout_event_source, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, connect_timeout_usec, 0, on_stream_timeout, s); if (r < 0) diff --git a/src/resolve/resolved-dns-transaction.c b/src/resolve/resolved-dns-transaction.c index 52897649d1..cec3cea7c5 100644 --- a/src/resolve/resolved-dns-transaction.c +++ b/src/resolve/resolved-dns-transaction.c @@ -1422,7 +1422,7 @@ static int on_dns_packet(sd_event_source *s, int fd, uint32_t revents, void *use * next recvmsg(). Treat this like a lost packet. */ log_debug_errno(r, "Connection failure for DNS UDP packet: %m"); - assert_se(sd_event_now(t->scope->manager->event, clock_boottime_or_monotonic(), &usec) >= 0); + assert_se(sd_event_now(t->scope->manager->event, CLOCK_BOOTTIME, &usec) >= 0); dns_server_packet_lost(t->server, IPPROTO_UDP, t->current_feature_level); dns_transaction_close_connection(t, /* use_graveyard = */ false); @@ -1797,7 +1797,7 @@ static int dns_transaction_make_packet_mdns(DnsTransaction *t) { * in our current scope, and see whether their timing constraints allow them to be sent. */ - assert_se(sd_event_now(t->scope->manager->event, clock_boottime_or_monotonic(), &ts) >= 0); + assert_se(sd_event_now(t->scope->manager->event, CLOCK_BOOTTIME, &ts) >= 0); LIST_FOREACH(transactions_by_scope, other, t->scope->transactions) { @@ -1835,7 +1835,7 @@ static int dns_transaction_make_packet_mdns(DnsTransaction *t) { r = sd_event_add_time( other->scope->manager->event, &other->timeout_event_source, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, ts, 0, on_transaction_timeout, other); if (r < 0) @@ -1937,7 +1937,7 @@ int dns_transaction_go(DnsTransaction *t) { * finished now. In the latter case, the transaction and query candidate objects must not be accessed. */ - assert_se(sd_event_now(t->scope->manager->event, clock_boottime_or_monotonic(), &ts) >= 0); + assert_se(sd_event_now(t->scope->manager->event, CLOCK_BOOTTIME, &ts) >= 0); r = dns_transaction_prepare(t, ts); if (r <= 0) @@ -1981,7 +1981,7 @@ int dns_transaction_go(DnsTransaction *t) { r = sd_event_add_time_relative( t->scope->manager->event, &t->timeout_event_source, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, jitter, accuracy, on_transaction_timeout, t); if (r < 0) @@ -2071,7 +2071,7 @@ int dns_transaction_go(DnsTransaction *t) { r = sd_event_add_time( t->scope->manager->event, &t->timeout_event_source, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, ts, 0, on_transaction_timeout, t); if (r < 0) diff --git a/src/resolve/resolved-etc-hosts.c b/src/resolve/resolved-etc-hosts.c index 72d6b42189..a1d797b111 100644 --- a/src/resolve/resolved-etc-hosts.c +++ b/src/resolve/resolved-etc-hosts.c @@ -294,7 +294,7 @@ static int manager_etc_hosts_read(Manager *m) { usec_t ts; int r; - assert_se(sd_event_now(m->event, clock_boottime_or_monotonic(), &ts) >= 0); + assert_se(sd_event_now(m->event, CLOCK_BOOTTIME, &ts) >= 0); /* See if we checked /etc/hosts recently already */ if (m->etc_hosts_last != USEC_INFINITY && m->etc_hosts_last + ETC_HOSTS_RECHECK_USEC > ts) diff --git a/src/resolve/resolved-manager.c b/src/resolve/resolved-manager.c index 916ad3ce03..12e7d87f22 100644 --- a/src/resolve/resolved-manager.c +++ b/src/resolve/resolved-manager.c @@ -803,7 +803,7 @@ int manager_recv(Manager *m, int fd, DnsProtocol protocol, DnsPacket **ret) { } else return -EAFNOSUPPORT; - p->timestamp = now(clock_boottime_or_monotonic()); + p->timestamp = now(CLOCK_BOOTTIME); CMSG_FOREACH(cmsg, &mh) { diff --git a/src/resolve/resolved-socket-graveyard.c b/src/resolve/resolved-socket-graveyard.c index e659ae9183..6d4105bc0a 100644 --- a/src/resolve/resolved-socket-graveyard.c +++ b/src/resolve/resolved-socket-graveyard.c @@ -53,7 +53,7 @@ void manager_socket_graveyard_process(Manager *m) { SocketGraveyard *g = m->socket_graveyard_oldest; if (n == USEC_INFINITY) - assert_se(sd_event_now(m->event, clock_boottime_or_monotonic(), &n) >= 0); + assert_se(sd_event_now(m->event, CLOCK_BOOTTIME, &n) >= 0); if (g->deadline > n) break; @@ -113,7 +113,7 @@ int manager_add_socket_to_graveyard(Manager *m, int fd) { m->n_socket_graveyard++; - assert_se(sd_event_now(m->event, clock_boottime_or_monotonic(), &g->deadline) >= 0); + assert_se(sd_event_now(m->event, CLOCK_BOOTTIME, &g->deadline) >= 0); g->deadline += SOCKET_GRAVEYARD_USEC; r = sd_event_add_io(m->event, &g->io_event_source, fd, EPOLLIN, on_io_event, g); diff --git a/src/shared/watchdog.c b/src/shared/watchdog.c index c4a4702a37..2476778c94 100644 --- a/src/shared/watchdog.c +++ b/src/shared/watchdog.c @@ -195,7 +195,7 @@ static int watchdog_ping_now(void) { if (ioctl(watchdog_fd, WDIOC_KEEPALIVE, 0) < 0) return log_warning_errno(errno, "Failed to ping hardware watchdog, ignoring: %m"); - watchdog_last_ping = now(clock_boottime_or_monotonic()); + watchdog_last_ping = now(CLOCK_BOOTTIME); return 0; } @@ -411,7 +411,7 @@ usec_t watchdog_runtime_wait(void) { /* Sleep half the watchdog timeout since the last successful ping at most */ if (timestamp_is_set(watchdog_last_ping)) { - usec_t ntime = now(clock_boottime_or_monotonic()); + usec_t ntime = now(CLOCK_BOOTTIME); assert(ntime >= watchdog_last_ping); return usec_sub_unsigned(watchdog_last_ping + (timeout / 2), ntime); @@ -430,7 +430,7 @@ int watchdog_ping(void) { /* open_watchdog() will automatically ping the device for us if necessary */ return open_watchdog(); - ntime = now(clock_boottime_or_monotonic()); + ntime = now(CLOCK_BOOTTIME); timeout = calc_timeout(); /* Never ping earlier than watchdog_timeout/4 and try to ping diff --git a/src/test/test-time-util.c b/src/test/test-time-util.c index 15f4a0c169..86a60604da 100644 --- a/src/test/test-time-util.c +++ b/src/test/test-time-util.c @@ -522,25 +522,25 @@ TEST(usec_shift_clock) { rt = now(CLOCK_REALTIME); mn = now(CLOCK_MONOTONIC); - bt = now(clock_boottime_or_monotonic()); + bt = now(CLOCK_BOOTTIME); assert_se(usec_shift_clock(USEC_INFINITY, CLOCK_REALTIME, CLOCK_MONOTONIC) == USEC_INFINITY); assert_similar(usec_shift_clock(rt + USEC_PER_HOUR, CLOCK_REALTIME, CLOCK_MONOTONIC), mn + USEC_PER_HOUR); - assert_similar(usec_shift_clock(rt + 2*USEC_PER_HOUR, CLOCK_REALTIME, clock_boottime_or_monotonic()), bt + 2*USEC_PER_HOUR); + assert_similar(usec_shift_clock(rt + 2*USEC_PER_HOUR, CLOCK_REALTIME, CLOCK_BOOTTIME), bt + 2*USEC_PER_HOUR); assert_se(usec_shift_clock(rt + 3*USEC_PER_HOUR, CLOCK_REALTIME, CLOCK_REALTIME_ALARM) == rt + 3*USEC_PER_HOUR); assert_similar(usec_shift_clock(mn + 4*USEC_PER_HOUR, CLOCK_MONOTONIC, CLOCK_REALTIME_ALARM), rt + 4*USEC_PER_HOUR); - assert_similar(usec_shift_clock(mn + 5*USEC_PER_HOUR, CLOCK_MONOTONIC, clock_boottime_or_monotonic()), bt + 5*USEC_PER_HOUR); + assert_similar(usec_shift_clock(mn + 5*USEC_PER_HOUR, CLOCK_MONOTONIC, CLOCK_BOOTTIME), bt + 5*USEC_PER_HOUR); assert_se(usec_shift_clock(mn + 6*USEC_PER_HOUR, CLOCK_MONOTONIC, CLOCK_MONOTONIC) == mn + 6*USEC_PER_HOUR); - assert_similar(usec_shift_clock(bt + 7*USEC_PER_HOUR, clock_boottime_or_monotonic(), CLOCK_MONOTONIC), mn + 7*USEC_PER_HOUR); - assert_similar(usec_shift_clock(bt + 8*USEC_PER_HOUR, clock_boottime_or_monotonic(), CLOCK_REALTIME_ALARM), rt + 8*USEC_PER_HOUR); - assert_se(usec_shift_clock(bt + 9*USEC_PER_HOUR, clock_boottime_or_monotonic(), clock_boottime_or_monotonic()) == bt + 9*USEC_PER_HOUR); + assert_similar(usec_shift_clock(bt + 7*USEC_PER_HOUR, CLOCK_BOOTTIME, CLOCK_MONOTONIC), mn + 7*USEC_PER_HOUR); + assert_similar(usec_shift_clock(bt + 8*USEC_PER_HOUR, CLOCK_BOOTTIME, CLOCK_REALTIME_ALARM), rt + 8*USEC_PER_HOUR); + assert_se(usec_shift_clock(bt + 9*USEC_PER_HOUR, CLOCK_BOOTTIME, CLOCK_BOOTTIME) == bt + 9*USEC_PER_HOUR); if (mn > USEC_PER_MINUTE) { assert_similar(usec_shift_clock(rt - 30 * USEC_PER_SEC, CLOCK_REALTIME_ALARM, CLOCK_MONOTONIC), mn - 30 * USEC_PER_SEC); - assert_similar(usec_shift_clock(rt - 50 * USEC_PER_SEC, CLOCK_REALTIME, clock_boottime_or_monotonic()), bt - 50 * USEC_PER_SEC); + assert_similar(usec_shift_clock(rt - 50 * USEC_PER_SEC, CLOCK_REALTIME, CLOCK_BOOTTIME), bt - 50 * USEC_PER_SEC); } } @@ -598,7 +598,7 @@ static int intro(void) { "boottime=" USEC_FMT "\n", now(CLOCK_REALTIME), now(CLOCK_MONOTONIC), - now(clock_boottime_or_monotonic())); + now(CLOCK_BOOTTIME)); /* Ensure time_t is signed */ assert_cc((time_t) -1 < (time_t) 1); diff --git a/src/timesync/timesyncd-manager.c b/src/timesync/timesyncd-manager.c index 7392edbe27..ae906a631d 100644 --- a/src/timesync/timesyncd-manager.c +++ b/src/timesync/timesyncd-manager.c @@ -130,7 +130,7 @@ static int manager_send_request(Manager *m) { * The actual value does not matter, We do not care about the correct * NTP UINT_MAX fraction; we just pass the plain nanosecond value. */ - assert_se(clock_gettime(clock_boottime_or_monotonic(), &m->trans_time_mon) >= 0); + assert_se(clock_gettime(CLOCK_BOOTTIME, &m->trans_time_mon) >= 0); assert_se(clock_gettime(CLOCK_REALTIME, &m->trans_time) >= 0); ntpmsg.trans_time.sec = htobe32(graceful_add_offset_1900_1970(m->trans_time.tv_sec)); ntpmsg.trans_time.frac = htobe32(m->trans_time.tv_nsec); @@ -161,8 +161,8 @@ static int manager_send_request(Manager *m) { r = sd_event_add_time( m->event, &m->event_timeout, - clock_boottime_or_monotonic(), - now(clock_boottime_or_monotonic()) + TIMEOUT_USEC, 0, + CLOCK_BOOTTIME, + now(CLOCK_BOOTTIME) + TIMEOUT_USEC, 0, manager_timeout, m); if (r < 0) return log_error_errno(r, "Failed to arm timeout timer: %m"); @@ -200,7 +200,7 @@ static int manager_arm_timer(Manager *m, usec_t next) { return sd_event_add_time_relative( m->event, &m->event_timer, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, next, 0, manager_timer, m); } @@ -799,7 +799,7 @@ int manager_connect(Manager *m) { if (!ratelimit_below(&m->ratelimit)) { log_debug("Delaying attempts to contact servers."); - r = sd_event_add_time_relative(m->event, &m->event_retry, clock_boottime_or_monotonic(), m->connection_retry_usec, + r = sd_event_add_time_relative(m->event, &m->event_retry, CLOCK_BOOTTIME, m->connection_retry_usec, 0, manager_retry_connect, m); if (r < 0) return log_error_errno(r, "Failed to create retry timer: %m"); @@ -854,7 +854,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_relative(m->event, &m->event_retry, 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, m->poll_interval_usec, 0, manager_retry_connect, m); if (r < 0) return log_error_errno(r, "Failed to create retry timer: %m"); @@ -1165,7 +1165,7 @@ int manager_setup_save_time_event(Manager *m) { /* NB: we'll accumulate scheduling latencies here, but this doesn't matter */ r = sd_event_add_time_relative( m->event, &m->event_save_time, - clock_boottime_or_monotonic(), + CLOCK_BOOTTIME, m->save_time_interval_usec, 10 * USEC_PER_SEC, manager_save_time_handler, m); diff --git a/src/udev/udev-ctrl.c b/src/udev/udev-ctrl.c index 45e45162ae..4913d0262b 100644 --- a/src/udev/udev-ctrl.c +++ b/src/udev/udev-ctrl.c @@ -356,7 +356,7 @@ int udev_ctrl_wait(UdevCtrl *uctrl, usec_t timeout) { if (timeout != USEC_INFINITY) { r = sd_event_add_time_relative( - uctrl->event, &source_timeout, clock_boottime_or_monotonic(), + uctrl->event, &source_timeout, CLOCK_BOOTTIME, timeout, 0, NULL, INT_TO_PTR(-ETIMEDOUT)); if (r < 0) diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 4d03f82fae..67d7733be2 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -807,7 +807,7 @@ static int event_is_blocked(Event *event) { if (event->retry_again_next_usec > 0) { usec_t now_usec; - r = sd_event_now(event->manager->event, clock_boottime_or_monotonic(), &now_usec); + r = sd_event_now(event->manager->event, CLOCK_BOOTTIME, &now_usec); if (r < 0) return r; @@ -1013,7 +1013,7 @@ static int event_requeue(Event *event) { event->timeout_event = sd_event_source_disable_unref(event->timeout_event); /* add a short delay to suppress busy loop */ - r = sd_event_now(event->manager->event, clock_boottime_or_monotonic(), &now_usec); + r = sd_event_now(event->manager->event, CLOCK_BOOTTIME, &now_usec); if (r < 0) return log_device_warning_errno(event->dev, r, "Failed to get current time, "