1
0
mirror of https://github.com/systemd/systemd.git synced 2025-01-26 14:04:03 +03:00

Merge pull request #22600 from poettering/timestamp_is_set-more

make more use of timestamp_is_set()
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-02-23 08:59:49 +01:00 committed by GitHub
commit f2acaf39c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 94 additions and 21 deletions

View File

@ -0,0 +1,73 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
@@
expression x;
constant USEC_INFINITY = USEC_INFINITY;
/* We want to stick with the literal expression in the implementation of timestamp_is_set(), i.e. in time-util.c */
position p : script:python() { p[0].file != "src/basic/time-util.h" };
@@
(
- x > 0 && x < USEC_INFINITY
+ timestamp_is_set(x)
|
- x < USEC_INFINITY && x > 0
+ timestamp_is_set(x)
|
- x@p > 0 && x != USEC_INFINITY
+ timestamp_is_set(x)
|
- x != USEC_INFINITY && x > 0
+ timestamp_is_set(x)
|
- x != 0 && x < USEC_INFINITY
+ timestamp_is_set(x)
|
- x < USEC_INFINITY && x != 0
+ timestamp_is_set(x)
|
- x != 0 && x != USEC_INFINITY
+ timestamp_is_set(x)
|
- x != USEC_INFINITY && x != 0
+ timestamp_is_set(x)
|
- !IN_SET(x, 0, USEC_INFINITY)
+ timestamp_is_set(x)
|
- !IN_SET(x, USEC_INFINITY, 0)
+ timestamp_is_set(x)
)
@@
expression x;
constant USEC_INFINITY = USEC_INFINITY;
@@
(
- x <= 0 || x >= USEC_INFINITY
+ !timestamp_is_set(x)
|
- x >= USEC_INFINITY || x <= 0
+ !timestamp_is_set(x)
|
- x <= 0 || x == USEC_INFINITY
+ !timestamp_is_set(x)
|
- x == USEC_INFINITY || x <= 0
+ !timestamp_is_set(x)
|
- x == 0 || x >= USEC_INFINITY
+ !timestamp_is_set(x)
|
- x >= USEC_INFINITY || x == 0
+ !timestamp_is_set(x)
|
- x == 0 || x == USEC_INFINITY
+ !timestamp_is_set(x)
|
- x == USEC_INFINITY || x == 0
+ !timestamp_is_set(x)
|
- IN_SET(x, 0, USEC_INFINITY)
+ !timestamp_is_set(x)
|
- IN_SET(x, USEC_INFINITY, 0)
+ !timestamp_is_set(x)
)

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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;
}

View File

@ -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

View File

@ -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));

View File

@ -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) {

View File

@ -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));

View File

@ -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));