]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
tree-wide: use timestamp_is_set() more 22600/head
authorLennart Poettering <lennart@poettering.net>
Tue, 22 Feb 2022 14:34:04 +0000 (15:34 +0100)
committerLennart Poettering <lennart@poettering.net>
Tue, 22 Feb 2022 21:49:40 +0000 (22:49 +0100)
src/basic/fileio.c
src/basic/time-util.c
src/basic/xattr-util.c
src/core/service.c
src/libsystemd-network/lldp-neighbor.c
src/libsystemd/sd-daemon/sd-daemon.c
src/libsystemd/sd-journal/journal-vacuum.c
src/login/loginctl.c
src/login/logind-user.c
src/machine/machinectl.c
src/systemctl/systemctl-show.c

index 8d92da327ee98c9b1aca735da087635143d2f143..cac547949165d7da2e7686cfd70db41906385be3 100644 (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;
index c0841af8f3dbcfd3566baa58953292ab2a704871..590e2e9e08a3d78e8265cb062d7078df9f7d484a 100644 (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);
index ebd620604ed26819ff3910d7c75adeb95c162f00..ac4fd7b1c55a277c9e7fd86e4c2ab7c14d9f183e 100644 (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);
index 6350c564c600a9b47bc278e7ae5d52dd72a29ffb..92af448ff48b37346d3af2b074ea64d6e2b55f7b 100644 (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);
index 44847b2b925cdb947b5295a665ee9350d0d4a6b5..93f603686591d1e4adf49817dbecc8b7cdf06170 100644 (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);
index 4987eab916435d7535b136fdc42083b055bde3b7..c6380768bb7943bbcdd51be861a7632e27b1cc8f 100644 (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;
         }
index 8296448ed5db6caf35278aa43514a68d37c27e3a..eac35002023a1f379798227b304d604110d5b7d9 100644 (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
index 3e1916725d42f2752f112c19ad2f69b155b7c12c..6af0ad2f3ccca54b82bcf4307e8f5b8127e7ad59 100644 (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));
index 6d61b55c2b07f0d2ee8e64f538acf514f8f9ea83..8d6bafe45d347d74c3c09ccb967c9d4fc8ea46c9 100644 (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) {
index 2f552a9387af650be6676cdd1f64fcc4f264b50c..64233b89c0099580633b1c6ad2e5953fa25a5146 100644 (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));
 
index 86a731f637acb493e3739de9c0328217df32c375..76418196c6ace918d0ea3afaa7126f0c88f817d2 100644 (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));