From 0da36375ebd1c2768626692889b22c6adc3c4bab Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Tue, 22 Feb 2022 15:34:04 +0100 Subject: [PATCH] tree-wide: use timestamp_is_set() more --- src/basic/fileio.c | 4 ++-- src/basic/time-util.c | 8 ++++---- src/basic/xattr-util.c | 2 +- src/core/service.c | 4 ++-- src/libsystemd-network/lldp-neighbor.c | 2 +- src/libsystemd/sd-daemon/sd-daemon.c | 2 +- src/libsystemd/sd-journal/journal-vacuum.c | 6 +++--- src/login/loginctl.c | 4 ++-- src/login/logind-user.c | 2 +- src/machine/machinectl.c | 4 ++-- src/systemctl/systemctl-show.c | 4 ++-- 11 files changed, 21 insertions(+), 21 deletions(-) diff --git a/src/basic/fileio.c b/src/basic/fileio.c index 8d92da327ee..cac54794916 100644 --- a/src/basic/fileio.c +++ b/src/basic/fileio.c @@ -1195,7 +1195,7 @@ int write_timestamp_file_atomic(const char *fn, usec_t n) { /* Creates a "timestamp" file, that contains nothing but a * usec_t timestamp, formatted in ASCII. */ - if (n <= 0 || n >= USEC_INFINITY) + if (!timestamp_is_set(n)) return -ERANGE; xsprintf(ln, USEC_FMT "\n", n); @@ -1216,7 +1216,7 @@ int read_timestamp_file(const char *fn, usec_t *ret) { if (r < 0) return r; - if (t <= 0 || t >= (uint64_t) USEC_INFINITY) + if (!timestamp_is_set(t)) return -ERANGE; *ret = (usec_t) t; diff --git a/src/basic/time-util.c b/src/basic/time-util.c index c0841af8f3d..590e2e9e08a 100644 --- a/src/basic/time-util.c +++ b/src/basic/time-util.c @@ -126,7 +126,7 @@ usec_t map_clock_usec(usec_t from, clockid_t from_clock, clockid_t to_clock) { dual_timestamp* dual_timestamp_from_realtime(dual_timestamp *ts, usec_t u) { assert(ts); - if (u == USEC_INFINITY || u == 0) { + if (!timestamp_is_set(u)) { ts->realtime = ts->monotonic = u; return ts; } @@ -141,7 +141,7 @@ triple_timestamp* triple_timestamp_from_realtime(triple_timestamp *ts, usec_t u) assert(ts); - if (u == USEC_INFINITY || u == 0) { + if (!timestamp_is_set(u)) { ts->realtime = ts->monotonic = ts->boottime = u; return ts; } @@ -349,7 +349,7 @@ char *format_timestamp_style( 1 + 1 + /* space and shortest possible zone */ 1)) return NULL; /* Not enough space even for the shortest form. */ - if (t <= 0 || t == USEC_INFINITY) + if (!timestamp_is_set(t)) return NULL; /* Timestamp is unset */ if (style == TIMESTAMP_UNIX) { @@ -427,7 +427,7 @@ char *format_timestamp_relative(char *buf, size_t l, usec_t t) { const char *s; usec_t n, d; - if (t <= 0 || t == USEC_INFINITY) + if (!timestamp_is_set(t)) return NULL; n = now(CLOCK_REALTIME); diff --git a/src/basic/xattr-util.c b/src/basic/xattr-util.c index ebd620604ed..ac4fd7b1c55 100644 --- a/src/basic/xattr-util.c +++ b/src/basic/xattr-util.c @@ -199,7 +199,7 @@ int fd_setcrtime(int fd, usec_t usec) { assert(fd >= 0); - if (IN_SET(usec, 0, USEC_INFINITY)) + if (!timestamp_is_set(usec)) usec = now(CLOCK_REALTIME); le = htole64((uint64_t) usec); diff --git a/src/core/service.c b/src/core/service.c index 6350c564c60..92af448ff48 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -208,7 +208,7 @@ static void service_start_watchdog(Service *s) { assert(s); watchdog_usec = service_get_watchdog_usec(s); - if (IN_SET(watchdog_usec, 0, USEC_INFINITY)) { + if (!timestamp_is_set(watchdog_usec)) { service_stop_watchdog(s); return; } @@ -279,7 +279,7 @@ static void service_extend_timeout(Service *s, usec_t extend_timeout_usec) { assert(s); - if (IN_SET(extend_timeout_usec, 0, USEC_INFINITY)) + if (!timestamp_is_set(extend_timeout_usec)) return; extended = usec_add(now(CLOCK_MONOTONIC), extend_timeout_usec); diff --git a/src/libsystemd-network/lldp-neighbor.c b/src/libsystemd-network/lldp-neighbor.c index 44847b2b925..93f60368659 100644 --- a/src/libsystemd-network/lldp-neighbor.c +++ b/src/libsystemd-network/lldp-neighbor.c @@ -334,7 +334,7 @@ void lldp_neighbor_start_ttl(sd_lldp_neighbor *n) { /* Use the packet's timestamp if there is one known */ base = triple_timestamp_by_clock(&n->timestamp, clock_boottime_or_monotonic()); - if (base <= 0 || base == USEC_INFINITY) + if (!timestamp_is_set(base)) base = now(clock_boottime_or_monotonic()); /* Otherwise, take the current time */ n->until = usec_add(base, n->ttl * USEC_PER_SEC); diff --git a/src/libsystemd/sd-daemon/sd-daemon.c b/src/libsystemd/sd-daemon/sd-daemon.c index 4987eab9164..c6380768bb7 100644 --- a/src/libsystemd/sd-daemon/sd-daemon.c +++ b/src/libsystemd/sd-daemon/sd-daemon.c @@ -641,7 +641,7 @@ _public_ int sd_watchdog_enabled(int unset_environment, uint64_t *usec) { r = safe_atou64(s, &u); if (r < 0) goto finish; - if (u <= 0 || u >= USEC_INFINITY) { + if (!timestamp_is_set(u)) { r = -EINVAL; goto finish; } diff --git a/src/libsystemd/sd-journal/journal-vacuum.c b/src/libsystemd/sd-journal/journal-vacuum.c index 8296448ed5d..eac35002023 100644 --- a/src/libsystemd/sd-journal/journal-vacuum.c +++ b/src/libsystemd/sd-journal/journal-vacuum.c @@ -64,15 +64,15 @@ static void patch_realtime( assert(realtime); x = timespec_load(&st->st_ctim); - if (x > 0 && x != USEC_INFINITY && x < *realtime) + if (timestamp_is_set(x) && x < *realtime) *realtime = x; x = timespec_load(&st->st_atim); - if (x > 0 && x != USEC_INFINITY && x < *realtime) + if (timestamp_is_set(x) && x < *realtime) *realtime = x; x = timespec_load(&st->st_mtim); - if (x > 0 && x != USEC_INFINITY && x < *realtime) + if (timestamp_is_set(x) && x < *realtime) *realtime = x; /* Let's read the original creation time, if possible. Ideally we'd just query the creation time the diff --git a/src/login/loginctl.c b/src/login/loginctl.c index 3e1916725d4..6af0ad2f3cc 100644 --- a/src/login/loginctl.c +++ b/src/login/loginctl.c @@ -469,7 +469,7 @@ static int print_session_status_info(sd_bus *bus, const char *path, bool *new_li else printf("%"PRIu32"\n", i.uid); - if (i.timestamp.realtime > 0 && i.timestamp.realtime < USEC_INFINITY) + if (timestamp_is_set(i.timestamp.realtime)) printf("\t Since: %s; %s\n", FORMAT_TIMESTAMP(i.timestamp.realtime), FORMAT_TIMESTAMP_RELATIVE(i.timestamp.realtime)); @@ -592,7 +592,7 @@ static int print_user_status_info(sd_bus *bus, const char *path, bool *new_line) else printf("%"PRIu32"\n", i.uid); - if (i.timestamp.realtime > 0 && i.timestamp.realtime < USEC_INFINITY) + if (timestamp_is_set(i.timestamp.realtime)) printf("\t Since: %s; %s\n", FORMAT_TIMESTAMP(i.timestamp.realtime), FORMAT_TIMESTAMP_RELATIVE(i.timestamp.realtime)); diff --git a/src/login/logind-user.c b/src/login/logind-user.c index 6d61b55c2b0..8d6bafe45d3 100644 --- a/src/login/logind-user.c +++ b/src/login/logind-user.c @@ -856,7 +856,7 @@ void user_update_last_session_timer(User *u) { assert(!u->timer_event_source); user_stop_delay = user_get_stop_delay(u); - if (IN_SET(user_stop_delay, 0, USEC_INFINITY)) + if (!timestamp_is_set(user_stop_delay)) return; if (sd_event_get_state(u->manager->event) == SD_EVENT_FINISHED) { diff --git a/src/machine/machinectl.c b/src/machine/machinectl.c index 2f552a9387a..64233b89c00 100644 --- a/src/machine/machinectl.c +++ b/src/machine/machinectl.c @@ -850,11 +850,11 @@ static void print_image_status_info(sd_bus *bus, ImageStatusInfo *i) { i->read_only ? "read-only" : "writable", i->read_only ? ansi_normal() : ""); - if (i->crtime > 0 && i->crtime < USEC_INFINITY) + if (timestamp_is_set(i->crtime)) printf("\t Created: %s; %s\n", FORMAT_TIMESTAMP(i->crtime), FORMAT_TIMESTAMP_RELATIVE(i->crtime)); - if (i->mtime > 0 && i->mtime < USEC_INFINITY) + if (timestamp_is_set(i->mtime)) printf("\tModified: %s; %s\n", FORMAT_TIMESTAMP(i->mtime), FORMAT_TIMESTAMP_RELATIVE(i->mtime)); diff --git a/src/systemctl/systemctl-show.c b/src/systemctl/systemctl-show.c index 86a731f637a..76418196c6a 100644 --- a/src/systemctl/systemctl-show.c +++ b/src/systemctl/systemctl-show.c @@ -421,7 +421,7 @@ static void print_status_info( STRPTR_IN_SET(i->active_state, "activating") ? i->inactive_exit_timestamp : i->active_exit_timestamp; - if (timestamp > 0 && timestamp < USEC_INFINITY) { + if (timestamp_is_set(timestamp)) { printf(" since %s; %s\n", FORMAT_TIMESTAMP_STYLE(timestamp, arg_timestamp_style), FORMAT_TIMESTAMP_RELATIVE(timestamp)); @@ -455,7 +455,7 @@ static void print_status_info( dual_timestamp_get(&nw); next_elapse = calc_next_elapse(&nw, &next); - if (next_elapse > 0 && next_elapse < USEC_INFINITY) + if (timestamp_is_set(next_elapse)) printf(" Trigger: %s; %s\n", FORMAT_TIMESTAMP_STYLE(next_elapse, arg_timestamp_style), FORMAT_TIMESTAMP_RELATIVE(next_elapse)); -- 2.47.3