summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKay Sievers <kay@vrfy.org>2014-07-29 12:23:31 +0200
committerKay Sievers <kay@vrfy.org>2014-07-29 13:20:20 +0200
commit3a43da2832dc5360a638d043f469a6dcbe025582 (patch)
treee3b60e840bb087c1af7f458676e3ab6bf04ea49e
parentcf347234ae78630dd4aad8907f027965e7fb9040 (diff)
time-util: add and use USEC/NSEC_INFINIY
-rw-r--r--src/core/cgroup.c6
-rw-r--r--src/core/dbus-execute.c2
-rw-r--r--src/core/execute.c8
-rw-r--r--src/core/load-fragment.c2
-rw-r--r--src/core/main.c4
-rw-r--r--src/core/manager.c2
-rw-r--r--src/core/timer.c4
-rw-r--r--src/firstboot/firstboot.c2
-rw-r--r--src/journal/journal-vacuum.c6
-rw-r--r--src/journal/journald.c2
-rw-r--r--src/libsystemd/sd-bus/bus-util.c2
-rw-r--r--src/libsystemd/sd-bus/sd-bus.c2
-rw-r--r--src/libsystemd/sd-bus/test-bus-kernel-benchmark.c2
-rw-r--r--src/libsystemd/sd-event/sd-event.c12
-rw-r--r--src/libsystemd/sd-rtnl/sd-rtnl.c2
-rw-r--r--src/shared/logs-show.c2
-rw-r--r--src/shared/spawn-polkit-agent.c2
-rw-r--r--src/shared/time-util.c28
-rw-r--r--src/shared/time-util.h27
-rw-r--r--src/shared/util.c26
-rw-r--r--src/shared/watchdog.c6
-rw-r--r--src/systemctl/systemctl.c4
-rw-r--r--src/tty-ask-password-agent/tty-ask-password-agent.c2
23 files changed, 79 insertions, 76 deletions
diff --git a/src/core/cgroup.c b/src/core/cgroup.c
index db8b4d7705..a52de2db69 100644
--- a/src/core/cgroup.c
+++ b/src/core/cgroup.c
@@ -41,7 +41,7 @@ void cgroup_context_init(CGroupContext *c) {
c->blockio_weight = (unsigned long) -1;
c->startup_blockio_weight = (unsigned long) -1;
- c->cpu_quota_per_sec_usec = (usec_t) -1;
+ c->cpu_quota_per_sec_usec = USEC_INFINITY;
}
void cgroup_context_free_device_allow(CGroupContext *c, CGroupDeviceAllow *a) {
@@ -311,7 +311,7 @@ void cgroup_context_apply(CGroupContext *c, CGroupControllerMask mask, const cha
if (r < 0)
log_warning("Failed to set cpu.cfs_period_us on %s: %s", path, strerror(-r));
- if (c->cpu_quota_per_sec_usec != (usec_t) -1) {
+ if (c->cpu_quota_per_sec_usec != USEC_INFINITY) {
sprintf(buf, USEC_FMT "\n", c->cpu_quota_per_sec_usec * CGROUP_CPU_QUOTA_PERIOD_USEC / USEC_PER_SEC);
r = cg_set_attribute("cpu", path, "cpu.cfs_quota_us", buf);
} else
@@ -447,7 +447,7 @@ CGroupControllerMask cgroup_context_get_mask(CGroupContext *c) {
if (c->cpu_accounting ||
c->cpu_shares != (unsigned long) -1 ||
c->startup_cpu_shares != (unsigned long) -1 ||
- c->cpu_quota_per_sec_usec != (usec_t) -1)
+ c->cpu_quota_per_sec_usec != USEC_INFINITY)
mask |= CGROUP_CPUACCT | CGROUP_CPU;
if (c->blockio_accounting ||
diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c
index ecbadd765b..9276da4cdc 100644
--- a/src/core/dbus-execute.c
+++ b/src/core/dbus-execute.c
@@ -300,7 +300,7 @@ static int property_get_timer_slack_nsec(
assert(reply);
assert(c);
- if (c->timer_slack_nsec != (nsec_t) -1)
+ if (c->timer_slack_nsec != NSEC_INFINITY)
u = (uint64_t) c->timer_slack_nsec;
else
u = (uint64_t) prctl(PR_GET_TIMERSLACK);
diff --git a/src/core/execute.c b/src/core/execute.c
index 6e76bd5b50..d8452a666c 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -333,7 +333,7 @@ static int setup_input(const ExecContext *context, int socket_fd, bool apply_tty
i == EXEC_INPUT_TTY_FAIL,
i == EXEC_INPUT_TTY_FORCE,
false,
- (usec_t) -1);
+ USEC_INFINITY);
if (fd < 0)
return fd;
@@ -1464,7 +1464,7 @@ int exec_spawn(ExecCommand *command,
goto fail_child;
}
- if (context->timer_slack_nsec != (nsec_t) -1)
+ if (context->timer_slack_nsec != NSEC_INFINITY)
if (prctl(PR_SET_TIMERSLACK, context->timer_slack_nsec) < 0) {
err = -errno;
r = EXIT_TIMERSLACK;
@@ -1833,7 +1833,7 @@ void exec_context_init(ExecContext *c) {
c->syslog_priority = LOG_DAEMON|LOG_INFO;
c->syslog_level_prefix = true;
c->ignore_sigpipe = true;
- c->timer_slack_nsec = (nsec_t) -1;
+ c->timer_slack_nsec = NSEC_INFINITY;
c->personality = 0xffffffffUL;
c->runtime_directory_mode = 0755;
}
@@ -2177,7 +2177,7 @@ void exec_context_dump(ExecContext *c, FILE* f, const char *prefix) {
fputs("\n", f);
}
- if (c->timer_slack_nsec != (nsec_t) -1)
+ if (c->timer_slack_nsec != NSEC_INFINITY)
fprintf(f, "%sTimerSlackNSec: "NSEC_FMT "\n", prefix, c->timer_slack_nsec);
fprintf(f,
diff --git a/src/core/load-fragment.c b/src/core/load-fragment.c
index 81f137946c..6d8431015d 100644
--- a/src/core/load-fragment.c
+++ b/src/core/load-fragment.c
@@ -2510,7 +2510,7 @@ int config_parse_cpu_quota(
assert(rvalue);
if (isempty(rvalue)) {
- c->cpu_quota_per_sec_usec = (usec_t) -1;
+ c->cpu_quota_per_sec_usec = USEC_INFINITY;
return 0;
}
diff --git a/src/core/main.c b/src/core/main.c
index f67c003941..2741989c48 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -109,7 +109,7 @@ static usec_t arg_shutdown_watchdog = 10 * USEC_PER_MINUTE;
static char **arg_default_environment = NULL;
static struct rlimit *arg_default_rlimit[_RLIMIT_MAX] = {};
static uint64_t arg_capability_bounding_set_drop = 0;
-static nsec_t arg_timer_slack_nsec = (nsec_t) -1;
+static nsec_t arg_timer_slack_nsec = NSEC_INFINITY;
static usec_t arg_default_timer_accuracy_usec = 1 * USEC_PER_MINUTE;
static Set* arg_syscall_archs = NULL;
static FILE* arg_serialization = NULL;
@@ -1604,7 +1604,7 @@ int main(int argc, char *argv[]) {
if (arg_running_as == SYSTEMD_SYSTEM && arg_runtime_watchdog > 0)
watchdog_set_timeout(&arg_runtime_watchdog);
- if (arg_timer_slack_nsec != (nsec_t) -1)
+ if (arg_timer_slack_nsec != NSEC_INFINITY)
if (prctl(PR_SET_TIMERSLACK, arg_timer_slack_nsec) < 0)
log_error("Failed to adjust timer slack: %m");
diff --git a/src/core/manager.c b/src/core/manager.c
index 0653d7e59a..af508ef30c 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -1875,7 +1875,7 @@ int manager_loop(Manager *m) {
if (wait_usec <= 0)
wait_usec = 1;
} else
- wait_usec = (usec_t) -1;
+ wait_usec = USEC_INFINITY;
r = sd_event_run(m->event, wait_usec);
if (r < 0) {
diff --git a/src/core/timer.c b/src/core/timer.c
index e69dfbd1e4..a5a33a6e6f 100644
--- a/src/core/timer.c
+++ b/src/core/timer.c
@@ -46,8 +46,8 @@ static void timer_init(Unit *u) {
assert(u);
assert(u->load_state == UNIT_STUB);
- t->next_elapse_monotonic_or_boottime = (usec_t) -1;
- t->next_elapse_realtime = (usec_t) -1;
+ t->next_elapse_monotonic_or_boottime = USEC_INFINITY;
+ t->next_elapse_realtime = USEC_INFINITY;
t->accuracy_usec = u->manager->default_timer_accuracy_usec;
}
diff --git a/src/firstboot/firstboot.c b/src/firstboot/firstboot.c
index 6abffc528f..2c08ad481b 100644
--- a/src/firstboot/firstboot.c
+++ b/src/firstboot/firstboot.c
@@ -68,7 +68,7 @@ static bool press_any_key(void) {
printf("-- Press any key to proceed --");
fflush(stdout);
- read_one_char(stdin, &k, (usec_t) -1, &need_nl);
+ read_one_char(stdin, &k, USEC_INFINITY, &need_nl);
if (need_nl)
putchar('\n');
diff --git a/src/journal/journal-vacuum.c b/src/journal/journal-vacuum.c
index 891b6bb848..7699482a77 100644
--- a/src/journal/journal-vacuum.c
+++ b/src/journal/journal-vacuum.c
@@ -89,15 +89,15 @@ static void patch_realtime(
assert(realtime);
x = timespec_load(&st->st_ctim);
- if (x > 0 && x != (usec_t) -1 && x < *realtime)
+ if (x > 0 && x != USEC_INFINITY && x < *realtime)
*realtime = x;
x = timespec_load(&st->st_atim);
- if (x > 0 && x != (usec_t) -1 && x < *realtime)
+ if (x > 0 && x != USEC_INFINITY && x < *realtime)
*realtime = x;
x = timespec_load(&st->st_mtim);
- if (x > 0 && x != (usec_t) -1 && x < *realtime)
+ if (x > 0 && x != USEC_INFINITY && x < *realtime)
*realtime = x;
/* Let's read the original creation time, if possible. Ideally
diff --git a/src/journal/journald.c b/src/journal/journald.c
index 886ac92a79..d6b235c12b 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -65,7 +65,7 @@ int main(int argc, char *argv[]) {
"STATUS=Processing requests...");
for (;;) {
- usec_t t = (usec_t) -1, n;
+ usec_t t = USEC_INFINITY, n;
r = sd_event_get_state(server.event);
if (r < 0)
diff --git a/src/libsystemd/sd-bus/bus-util.c b/src/libsystemd/sd-bus/bus-util.c
index 6441c5b162..d41e53753f 100644
--- a/src/libsystemd/sd-bus/bus-util.c
+++ b/src/libsystemd/sd-bus/bus-util.c
@@ -1265,7 +1265,7 @@ int bus_append_unit_property_assignment(sd_bus_message *m, const char *assignmen
if (r < 0)
return bus_log_create_error(r);
- r = sd_bus_message_append(m, "v", "t", (usec_t) -1);
+ r = sd_bus_message_append(m, "v", "t", USEC_INFINITY);
} else if (endswith(eq, "%")) {
double percent;
diff --git a/src/libsystemd/sd-bus/sd-bus.c b/src/libsystemd/sd-bus/sd-bus.c
index 28fc19e2cf..0fadd1699e 100644
--- a/src/libsystemd/sd-bus/sd-bus.c
+++ b/src/libsystemd/sd-bus/sd-bus.c
@@ -2646,7 +2646,7 @@ static int bus_poll(sd_bus *bus, bool need_more, uint64_t timeout_usec) {
struct pollfd p[2] = {};
int r, e, n;
struct timespec ts;
- usec_t m = (usec_t) -1;
+ usec_t m = USEC_INFINITY;
assert(bus);
diff --git a/src/libsystemd/sd-bus/test-bus-kernel-benchmark.c b/src/libsystemd/sd-bus/test-bus-kernel-benchmark.c
index 90257d4f3c..cd88e67c9e 100644
--- a/src/libsystemd/sd-bus/test-bus-kernel-benchmark.c
+++ b/src/libsystemd/sd-bus/test-bus-kernel-benchmark.c
@@ -47,7 +47,7 @@ static void server(sd_bus *b, size_t *result) {
assert_se(r >= 0);
if (r == 0)
- assert_se(sd_bus_wait(b, (usec_t) -1) >= 0);
+ assert_se(sd_bus_wait(b, USEC_INFINITY) >= 0);
if (!m)
continue;
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
index b285017376..bf6f01cfad 100644
--- a/src/libsystemd/sd-event/sd-event.c
+++ b/src/libsystemd/sd-event/sd-event.c
@@ -407,9 +407,9 @@ _public_ int sd_event_new(sd_event** ret) {
e->n_ref = 1;
e->signal_fd = e->watchdog_fd = e->epoll_fd = e->realtime.fd = e->boottime.fd = e->monotonic.fd = e->realtime_alarm.fd = e->boottime_alarm.fd = -1;
- e->realtime.next = e->boottime.next = e->monotonic.next = e->realtime_alarm.next = e->boottime_alarm.next = (usec_t) -1;
+ e->realtime.next = e->boottime.next = e->monotonic.next = e->realtime_alarm.next = e->boottime_alarm.next = USEC_INFINITY;
e->original_pid = getpid();
- e->perturb = (usec_t) -1;
+ e->perturb = USEC_INFINITY;
assert_se(sigemptyset(&e->sigset) == 0);
@@ -796,7 +796,7 @@ static void initialize_perturb(sd_event *e) {
bit. Here, we calculate a perturbation usec offset from the
boot ID. */
- if (_likely_(e->perturb != (usec_t) -1))
+ if (_likely_(e->perturb != USEC_INFINITY))
return;
if (sd_id128_get_boot(&bootid) >= 0)
@@ -1751,7 +1751,7 @@ static int event_arm_timer(
if (d->fd < 0)
return 0;
- if (d->next == (usec_t) -1)
+ if (d->next == USEC_INFINITY)
return 0;
/* disarm */
@@ -1759,7 +1759,7 @@ static int event_arm_timer(
if (r < 0)
return r;
- d->next = (usec_t) -1;
+ d->next = USEC_INFINITY;
return 0;
}
@@ -1827,7 +1827,7 @@ static int flush_timer(sd_event *e, int fd, uint32_t events, usec_t *next) {
return -EIO;
if (next)
- *next = (usec_t) -1;
+ *next = USEC_INFINITY;
return 0;
}
diff --git a/src/libsystemd/sd-rtnl/sd-rtnl.c b/src/libsystemd/sd-rtnl/sd-rtnl.c
index b91d08012a..c19bad1bc9 100644
--- a/src/libsystemd/sd-rtnl/sd-rtnl.c
+++ b/src/libsystemd/sd-rtnl/sd-rtnl.c
@@ -473,7 +473,7 @@ static usec_t calc_elapse(uint64_t usec) {
static int rtnl_poll(sd_rtnl *rtnl, bool need_more, uint64_t timeout_usec) {
struct pollfd p[1] = {};
struct timespec ts;
- usec_t m = (usec_t) -1;
+ usec_t m = USEC_INFINITY;
int r, e;
assert(rtnl);
diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c
index 8edf4087c6..5538dd3b9e 100644
--- a/src/shared/logs-show.c
+++ b/src/shared/logs-show.c
@@ -1032,7 +1032,7 @@ static int show_journal(FILE *f,
if (!(flags & OUTPUT_FOLLOW))
break;
- r = sd_journal_wait(j, (usec_t) -1);
+ r = sd_journal_wait(j, USEC_INFINITY);
if (r < 0)
goto finish;
diff --git a/src/shared/spawn-polkit-agent.c b/src/shared/spawn-polkit-agent.c
index fccf1e9173..29b01db19a 100644
--- a/src/shared/spawn-polkit-agent.c
+++ b/src/shared/spawn-polkit-agent.c
@@ -67,7 +67,7 @@ int polkit_agent_open(void) {
log_error("Failed to fork TTY ask password agent: %s", strerror(-r));
else
/* Wait until the agent closes the fd */
- fd_wait_for_event(pipe_fd[0], POLLHUP, (usec_t) -1);
+ fd_wait_for_event(pipe_fd[0], POLLHUP, USEC_INFINITY);
safe_close(pipe_fd[0]);
diff --git a/src/shared/time-util.c b/src/shared/time-util.c
index 76ab143f34..2dc01e6ed3 100644
--- a/src/shared/time-util.c
+++ b/src/shared/time-util.c
@@ -49,8 +49,8 @@ dual_timestamp* dual_timestamp_from_realtime(dual_timestamp *ts, usec_t u) {
int64_t delta;
assert(ts);
- if (u == (usec_t) -1) {
- ts->realtime = ts->monotonic = (usec_t) -1;
+ if (u == USEC_INFINITY) {
+ ts->realtime = ts->monotonic = USEC_INFINITY;
return ts;
}
@@ -76,8 +76,8 @@ dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u) {
int64_t delta;
assert(ts);
- if (u == (usec_t) -1) {
- ts->realtime = ts->monotonic = (usec_t) -1;
+ if (u == USEC_INFINITY) {
+ ts->realtime = ts->monotonic = USEC_INFINITY;
return ts;
}
@@ -98,10 +98,10 @@ usec_t timespec_load(const struct timespec *ts) {
if (ts->tv_sec == (time_t) -1 &&
ts->tv_nsec == (long) -1)
- return (usec_t) -1;
+ return USEC_INFINITY;
if ((usec_t) ts->tv_sec > (UINT64_MAX - (ts->tv_nsec / NSEC_PER_USEC)) / USEC_PER_SEC)
- return (usec_t) -1;
+ return USEC_INFINITY;
return
(usec_t) ts->tv_sec * USEC_PER_SEC +
@@ -111,7 +111,7 @@ usec_t timespec_load(const struct timespec *ts) {
struct timespec *timespec_store(struct timespec *ts, usec_t u) {
assert(ts);
- if (u == (usec_t) -1) {
+ if (u == USEC_INFINITY) {
ts->tv_sec = (time_t) -1;
ts->tv_nsec = (long) -1;
return ts;
@@ -128,10 +128,10 @@ usec_t timeval_load(const struct timeval *tv) {
if (tv->tv_sec == (time_t) -1 &&
tv->tv_usec == (suseconds_t) -1)
- return (usec_t) -1;
+ return USEC_INFINITY;
if ((usec_t) tv->tv_sec > (UINT64_MAX - tv->tv_usec) / USEC_PER_SEC)
- return (usec_t) -1;
+ return USEC_INFINITY;
return
(usec_t) tv->tv_sec * USEC_PER_SEC +
@@ -141,7 +141,7 @@ usec_t timeval_load(const struct timeval *tv) {
struct timeval *timeval_store(struct timeval *tv, usec_t u) {
assert(tv);
- if (u == (usec_t) -1) {
+ if (u == USEC_INFINITY) {
tv->tv_sec = (time_t) -1;
tv->tv_usec = (suseconds_t) -1;
} else {
@@ -159,7 +159,7 @@ char *format_timestamp(char *buf, size_t l, usec_t t) {
assert(buf);
assert(l > 0);
- if (t <= 0 || t == (usec_t) -1)
+ if (t <= 0 || t == USEC_INFINITY)
return NULL;
sec = (time_t) (t / USEC_PER_SEC);
@@ -177,7 +177,7 @@ char *format_timestamp_us(char *buf, size_t l, usec_t t) {
assert(buf);
assert(l > 0);
- if (t <= 0 || t == (usec_t) -1)
+ if (t <= 0 || t == USEC_INFINITY)
return NULL;
sec = (time_t) (t / USEC_PER_SEC);
@@ -198,7 +198,7 @@ char *format_timestamp_relative(char *buf, size_t l, usec_t t) {
n = now(CLOCK_REALTIME);
- if (t <= 0 || (t == (usec_t) -1))
+ if (t <= 0 || (t == USEC_INFINITY))
return NULL;
if (n > t) {
@@ -279,7 +279,7 @@ char *format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) {
assert(buf);
assert(l > 0);
- if (t == (usec_t) -1)
+ if (t == USEC_INFINITY)
return NULL;
if (t <= 0) {
diff --git a/src/shared/time-util.h b/src/shared/time-util.h
index 69a48c686b..8ba1cfee8e 100644
--- a/src/shared/time-util.h
+++ b/src/shared/time-util.h
@@ -37,25 +37,28 @@ typedef struct dual_timestamp {
usec_t monotonic;
} dual_timestamp;
-#define MSEC_PER_SEC ((usec_t) 1000ULL)
+#define USEC_INFINITY ((usec_t) -1)
+#define NSEC_INFINITY ((nsec_t) -1)
+
+#define MSEC_PER_SEC 1000ULL
#define USEC_PER_SEC ((usec_t) 1000000ULL)
#define USEC_PER_MSEC ((usec_t) 1000ULL)
-#define NSEC_PER_SEC ((usec_t) 1000000000ULL)
-#define NSEC_PER_MSEC ((usec_t) 1000000ULL)
-#define NSEC_PER_USEC ((usec_t) 1000ULL)
+#define NSEC_PER_SEC ((nsec_t) 1000000000ULL)
+#define NSEC_PER_MSEC ((nsec_t) 1000000ULL)
+#define NSEC_PER_USEC ((nsec_t) 1000ULL)
#define USEC_PER_MINUTE ((usec_t) (60ULL*USEC_PER_SEC))
-#define NSEC_PER_MINUTE ((usec_t) (60ULL*NSEC_PER_SEC))
+#define NSEC_PER_MINUTE ((nsec_t) (60ULL*NSEC_PER_SEC))
#define USEC_PER_HOUR ((usec_t) (60ULL*USEC_PER_MINUTE))
-#define NSEC_PER_HOUR ((usec_t) (60ULL*NSEC_PER_MINUTE))
+#define NSEC_PER_HOUR ((nsec_t) (60ULL*NSEC_PER_MINUTE))
#define USEC_PER_DAY ((usec_t) (24ULL*USEC_PER_HOUR))
-#define NSEC_PER_DAY ((usec_t) (24ULL*NSEC_PER_HOUR))
+#define NSEC_PER_DAY ((nsec_t) (24ULL*NSEC_PER_HOUR))
#define USEC_PER_WEEK ((usec_t) (7ULL*USEC_PER_DAY))
-#define NSEC_PER_WEEK ((usec_t) (7ULL*NSEC_PER_DAY))
+#define NSEC_PER_WEEK ((nsec_t) (7ULL*NSEC_PER_DAY))
#define USEC_PER_MONTH ((usec_t) (2629800ULL*USEC_PER_SEC))
-#define NSEC_PER_MONTH ((usec_t) (2629800ULL*NSEC_PER_SEC))
+#define NSEC_PER_MONTH ((nsec_t) (2629800ULL*NSEC_PER_SEC))
#define USEC_PER_YEAR ((usec_t) (31557600ULL*USEC_PER_SEC))
-#define NSEC_PER_YEAR ((usec_t) (31557600ULL*NSEC_PER_SEC))
+#define NSEC_PER_YEAR ((nsec_t) (31557600ULL*NSEC_PER_SEC))
#define FORMAT_TIMESTAMP_MAX ((4*4+1)+11+9+4+1) /* weekdays can be unicode */
#define FORMAT_TIMESTAMP_WIDTH 28 /* when outputting, assume this width */
@@ -71,8 +74,8 @@ dual_timestamp* dual_timestamp_from_realtime(dual_timestamp *ts, usec_t u);
dual_timestamp* dual_timestamp_from_monotonic(dual_timestamp *ts, usec_t u);
static inline bool dual_timestamp_is_set(dual_timestamp *ts) {
- return ((ts->realtime > 0 && ts->realtime != (usec_t) -1) ||
- (ts->monotonic > 0 && ts->monotonic != (usec_t) -1));
+ return ((ts->realtime > 0 && ts->realtime != USEC_INFINITY) ||
+ (ts->monotonic > 0 && ts->monotonic != USEC_INFINITY));
}
usec_t timespec_load(const struct timespec *ts) _pure_;
diff --git a/src/shared/util.c b/src/shared/util.c
index 49c17eff85..b1689e651f 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -1581,7 +1581,7 @@ int read_one_char(FILE *f, char *ret, usec_t t, bool *need_nl) {
if (tcsetattr(fileno(f), TCSADRAIN, &new_termios) >= 0) {
size_t k;
- if (t != (usec_t) -1) {
+ if (t != USEC_INFINITY) {
if (fd_wait_for_event(fileno(f), POLLIN, t) <= 0) {
tcsetattr(fileno(f), TCSADRAIN, &old_termios);
return -ETIMEDOUT;
@@ -1603,7 +1603,7 @@ int read_one_char(FILE *f, char *ret, usec_t t, bool *need_nl) {
}
}
- if (t != (usec_t) -1) {
+ if (t != USEC_INFINITY) {
if (fd_wait_for_event(fileno(f), POLLIN, t) <= 0)
return -ETIMEDOUT;
}
@@ -1648,7 +1648,7 @@ int ask_char(char *ret, const char *replies, const char *text, ...) {
fflush(stdout);
- r = read_one_char(stdin, &c, (usec_t) -1, &need_nl);
+ r = read_one_char(stdin, &c, USEC_INFINITY, &need_nl);
if (r < 0) {
if (r == -EBADMSG) {
@@ -1898,11 +1898,11 @@ int acquire_terminal(
* on the same tty as an untrusted user this should not be a
* problem. (Which he probably should not do anyway.) */
- if (timeout != (usec_t) -1)
+ if (timeout != USEC_INFINITY)
ts = now(CLOCK_MONOTONIC);
if (!fail && !force) {
- notify = inotify_init1(IN_CLOEXEC | (timeout != (usec_t) -1 ? IN_NONBLOCK : 0));
+ notify = inotify_init1(IN_CLOEXEC | (timeout != USEC_INFINITY ? IN_NONBLOCK : 0));
if (notify < 0) {
r = -errno;
goto fail;
@@ -1966,7 +1966,7 @@ int acquire_terminal(
ssize_t l;
struct inotify_event *e;
- if (timeout != (usec_t) -1) {
+ if (timeout != USEC_INFINITY) {
usec_t n;
n = now(CLOCK_MONOTONIC);
@@ -2148,7 +2148,7 @@ ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
* and expect that any error/EOF is reported
* via read() */
- fd_wait_for_event(fd, POLLIN, (usec_t) -1);
+ fd_wait_for_event(fd, POLLIN, USEC_INFINITY);
continue;
}
@@ -2183,7 +2183,7 @@ ssize_t loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
* and expect that any error/EOF is reported
* via write() */
- fd_wait_for_event(fd, POLLOUT, (usec_t) -1);
+ fd_wait_for_event(fd, POLLOUT, USEC_INFINITY);
continue;
}
@@ -3428,7 +3428,7 @@ int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gi
return -errno;
}
- if (stamp != (usec_t) -1) {
+ if (stamp != USEC_INFINITY) {
struct timespec ts[2];
timespec_store(&ts[0], stamp);
@@ -3443,7 +3443,7 @@ int touch_file(const char *path, bool parents, usec_t stamp, uid_t uid, gid_t gi
}
int touch(const char *path) {
- return touch_file(path, false, (usec_t) -1, (uid_t) -1, (gid_t) -1, 0);
+ return touch_file(path, false, USEC_INFINITY, (uid_t) -1, (gid_t) -1, 0);
}
char *unquote(const char *s, const char* quotes) {
@@ -3904,7 +3904,7 @@ void execute_directory(const char *directory, DIR *d, usec_t timeout, char *argv
* timout. We simply rely on SIGALRM as default action
* terminating the process, and turn on alarm(). */
- if (timeout != (usec_t) -1)
+ if (timeout != USEC_INFINITY)
alarm((timeout + USEC_PER_SEC - 1) / USEC_PER_SEC);
while (!hashmap_isempty(pids)) {
@@ -4074,7 +4074,7 @@ int fd_wait_for_event(int fd, int event, usec_t t) {
struct timespec ts;
int r;
- r = ppoll(&pollfd, 1, t == (usec_t) -1 ? NULL : timespec_store(&ts, t), NULL);
+ r = ppoll(&pollfd, 1, t == USEC_INFINITY ? NULL : timespec_store(&ts, t), NULL);
if (r < 0)
return -errno;
@@ -5273,7 +5273,7 @@ int make_console_stdio(void) {
/* Make /dev/console the controlling terminal and stdin/stdout/stderr */
- fd = acquire_terminal("/dev/console", false, true, true, (usec_t) -1);
+ fd = acquire_terminal("/dev/console", false, true, true, USEC_INFINITY);
if (fd < 0) {
log_error("Failed to acquire terminal: %s", strerror(-fd));
return fd;
diff --git a/src/shared/watchdog.c b/src/shared/watchdog.c
index ba9ad9be97..7d188d98e8 100644
--- a/src/shared/watchdog.c
+++ b/src/shared/watchdog.c
@@ -29,7 +29,7 @@
#include "log.h"
static int watchdog_fd = -1;
-static usec_t watchdog_timeout = (usec_t) -1;
+static usec_t watchdog_timeout = USEC_INFINITY;
static int update_timeout(void) {
int r;
@@ -37,7 +37,7 @@ static int update_timeout(void) {
if (watchdog_fd < 0)
return 0;
- if (watchdog_timeout == (usec_t) -1)
+ if (watchdog_timeout == USEC_INFINITY)
return 0;
else if (watchdog_timeout == 0) {
int flags;
@@ -104,7 +104,7 @@ int watchdog_set_timeout(usec_t *usec) {
/* If we didn't open the watchdog yet and didn't get any
* explicit timeout value set, don't do anything */
- if (watchdog_fd < 0 && watchdog_timeout == (usec_t) -1)
+ if (watchdog_fd < 0 && watchdog_timeout == USEC_INFINITY)
return 0;
if (watchdog_fd < 0)
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 599d590747..4699a670f7 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -1142,7 +1142,7 @@ static usec_t calc_next_elapse(dual_timestamp *nw, dual_timestamp *next) {
assert(nw);
assert(next);
- if (next->monotonic != (usec_t) -1 && next->monotonic > 0) {
+ if (next->monotonic != USEC_INFINITY && next->monotonic > 0) {
usec_t converted;
if (next->monotonic > nw->monotonic)
@@ -1150,7 +1150,7 @@ static usec_t calc_next_elapse(dual_timestamp *nw, dual_timestamp *next) {
else
converted = nw->realtime - (nw->monotonic - next->monotonic);
- if (next->realtime != (usec_t) -1 && next->realtime > 0)
+ if (next->realtime != USEC_INFINITY && next->realtime > 0)
next_elapse = MIN(converted, next->realtime);
else
next_elapse = converted;
diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c
index 2c540ba170..94ae5670f7 100644
--- a/src/tty-ask-password-agent/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent/tty-ask-password-agent.c
@@ -343,7 +343,7 @@ static int parse_password(const char *filename, char **wall) {
_cleanup_free_ char *password = NULL;
if (arg_console) {
- tty_fd = acquire_terminal("/dev/console", false, false, false, (usec_t) -1);
+ tty_fd = acquire_terminal("/dev/console", false, false, false, USEC_INFINITY);
if (tty_fd < 0)
return tty_fd;
}