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
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;
}
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;
}
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) {
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;
}
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;
case CLOCK_MONOTONIC:
case CLOCK_REALTIME:
- return true;
-
case CLOCK_BOOTTIME:
- return clock_boottime_supported();
-
- case CLOCK_BOOTTIME_ALARM:
- if (!clock_boottime_supported())
- return false;
+ /* These three are always available in our baseline, and work in timerfd, as of kernel 3.15 */
+ return true;
- _fallthrough_;
default:
/* For everything else, check properly */
return clock_gettime(clock, &ts) >= 0;
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);
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);
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);
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");
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
/* 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);
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;
}
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);
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);
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);
}
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);
/* 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);
/* 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);
/* 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);
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);
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;
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;
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;
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);
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);
} 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);
} 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);
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);
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);
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) {
goto remove_one;
if (t == USEC_INFINITY)
- t = now(clock_boottime_or_monotonic());
+ t = now(CLOCK_BOOTTIME);
if (n->until > t)
break;
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);
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;
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);
}
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);
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;
(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);
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);
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;
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;
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);
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);
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);
_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);
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);
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);
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);
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);
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);
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);
}
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;
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)
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),
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;
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;
}
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)
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)
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;
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");
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;
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");
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,
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");
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");
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");
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");
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");
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");
/* 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)
/* 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;
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;
}
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");
(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;
}
break;
if (t <= 0)
- t = now(clock_boottime_or_monotonic());
+ t = now(CLOCK_BOOTTIME);
if (i->until > t)
break;
/* 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) {
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);
}
usec_t k;
int r;
- k = now(clock_boottime_or_monotonic());
+ k = now(CLOCK_BOOTTIME);
assert(k >= timestamp);
k -= timestamp;
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);
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);
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);
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) {
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;
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;
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)
* 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);
* 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) {
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)
* 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)
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)
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)
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)
} else
return -EAFNOSUPPORT;
- p->timestamp = now(clock_boottime_or_monotonic());
+ p->timestamp = now(CLOCK_BOOTTIME);
CMSG_FOREACH(cmsg, &mh) {
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;
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);
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;
}
/* 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);
/* 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
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);
}
}
"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);
* 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);
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");
return sd_event_add_time_relative(
m->event,
&m->event_timer,
- clock_boottime_or_monotonic(),
+ CLOCK_BOOTTIME,
next, 0,
manager_timer, 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");
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");
/* 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);
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)
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;
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, "