summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/basic/io-util.c3
-rw-r--r--src/basic/process-util.c3
-rw-r--r--src/basic/time-util.h4
-rw-r--r--src/core/main.c4
-rw-r--r--src/libsystemd/sd-event/sd-event.c5
-rw-r--r--src/nspawn/nspawn-stub-pid1.c6
-rw-r--r--src/shared/clock-util.c5
-rw-r--r--src/timesync/timesyncd.c3
-rw-r--r--src/tty-ask-password-agent/tty-ask-password-agent.c7
-rw-r--r--src/userdb/userdbd-manager.c3
10 files changed, 17 insertions, 26 deletions
diff --git a/src/basic/io-util.c b/src/basic/io-util.c
index 783ca1309d..a591a75c37 100644
--- a/src/basic/io-util.c
+++ b/src/basic/io-util.c
@@ -159,7 +159,6 @@ int pipe_eof(int fd) {
}
int ppoll_usec(struct pollfd *fds, size_t nfds, usec_t timeout) {
- struct timespec ts;
int r;
assert(fds || nfds == 0);
@@ -167,7 +166,7 @@ int ppoll_usec(struct pollfd *fds, size_t nfds, usec_t timeout) {
if (nfds == 0)
return 0;
- r = ppoll(fds, nfds, timeout == USEC_INFINITY ? NULL : timespec_store(&ts, timeout), NULL);
+ r = ppoll(fds, nfds, timeout == USEC_INFINITY ? NULL : TIMESPEC_STORE(timeout), NULL);
if (r < 0)
return -errno;
if (r == 0)
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index 369edce816..680900c731 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -820,13 +820,12 @@ int wait_for_terminate_with_timeout(pid_t pid, usec_t timeout) {
for (;;) {
usec_t n;
siginfo_t status = {};
- struct timespec ts;
n = now(CLOCK_MONOTONIC);
if (n >= until)
break;
- r = RET_NERRNO(sigtimedwait(&mask, NULL, timespec_store(&ts, until - n)));
+ r = RET_NERRNO(sigtimedwait(&mask, NULL, TIMESPEC_STORE(until - n)));
/* Assuming we woke due to the child exiting. */
if (waitid(P_PID, pid, &status, WEXITED|WNOHANG) == 0) {
if (status.si_pid == pid) {
diff --git a/src/basic/time-util.h b/src/basic/time-util.h
index 01a72026e3..d3a88ed6e4 100644
--- a/src/basic/time-util.h
+++ b/src/basic/time-util.h
@@ -115,9 +115,13 @@ nsec_t timespec_load_nsec(const struct timespec *ts) _pure_;
struct timespec* timespec_store(struct timespec *ts, usec_t u);
struct timespec* timespec_store_nsec(struct timespec *ts, nsec_t n);
+#define TIMESPEC_STORE(u) timespec_store(&(struct timespec) {}, (u))
+
usec_t timeval_load(const struct timeval *tv) _pure_;
struct timeval* timeval_store(struct timeval *tv, usec_t u);
+#define TIMEVAL_STORE(u) timeval_store(&(struct timeval) {}, (u))
+
char* format_timestamp_style(char *buf, size_t l, usec_t t, TimestampStyle style) _warn_unused_result_;
char* format_timestamp_relative(char *buf, size_t l, usec_t t) _warn_unused_result_;
char* format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) _warn_unused_result_;
diff --git a/src/core/main.c b/src/core/main.c
index c13534e98a..be403dee79 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -1571,8 +1571,6 @@ static void initialize_clock(void) {
}
static void apply_clock_update(void) {
- struct timespec ts;
-
/* This is called later than initialize_clock(), i.e. after we parsed configuration files/kernel
* command line and such. */
@@ -1582,7 +1580,7 @@ static void apply_clock_update(void) {
if (getpid_cached() != 1)
return;
- if (clock_settime(CLOCK_REALTIME, timespec_store(&ts, arg_clock_usec)) < 0)
+ if (clock_settime(CLOCK_REALTIME, TIMESPEC_STORE(arg_clock_usec)) < 0)
log_error_errno(errno, "Failed to set system clock to time specified on kernel command line: %m");
else
log_info("Set system clock to %s, as specified on the kernel command line.",
diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c
index 82056998bd..fcb242fefa 100644
--- a/src/libsystemd/sd-event/sd-event.c
+++ b/src/libsystemd/sd-event/sd-event.c
@@ -3906,6 +3906,7 @@ static int epoll_wait_usec(
int msec;
#if 0
static bool epoll_pwait2_absent = false;
+ int r;
/* A wrapper that uses epoll_pwait2() if available, and falls back to epoll_wait() if not.
*
@@ -3914,12 +3915,10 @@ static int epoll_wait_usec(
* https://github.com/systemd/systemd/issues/19052. */
if (!epoll_pwait2_absent && timeout != USEC_INFINITY) {
- struct timespec ts;
-
r = epoll_pwait2(fd,
events,
maxevents,
- timespec_store(&ts, timeout),
+ TIMESPEC_STORE(timeout),
NULL);
if (r >= 0)
return r;
diff --git a/src/nspawn/nspawn-stub-pid1.c b/src/nspawn/nspawn-stub-pid1.c
index 6dbd6ba4c9..85c439815c 100644
--- a/src/nspawn/nspawn-stub-pid1.c
+++ b/src/nspawn/nspawn-stub-pid1.c
@@ -142,10 +142,8 @@ int stub_pid1(sd_id128_t uuid) {
if (quit_usec == USEC_INFINITY)
r = sigwaitinfo(&waitmask, &si);
- else {
- struct timespec ts;
- r = sigtimedwait(&waitmask, &si, timespec_store(&ts, quit_usec - current_usec));
- }
+ else
+ r = sigtimedwait(&waitmask, &si, TIMESPEC_STORE(quit_usec - current_usec));
if (r < 0) {
if (errno == EINTR) /* strace -p attach can result in EINTR, let's handle this nicely. */
continue;
diff --git a/src/shared/clock-util.c b/src/shared/clock-util.c
index febea8ea85..eb6f12a255 100644
--- a/src/shared/clock-util.c
+++ b/src/shared/clock-util.c
@@ -134,9 +134,8 @@ int clock_reset_timewarp(void) {
#define EPOCH_FILE "/usr/lib/clock-epoch"
int clock_apply_epoch(ClockChangeDirection *ret_attempted_change) {
- struct stat st;
- struct timespec ts;
usec_t epoch_usec, now_usec;
+ struct stat st;
/* NB: we update *ret_attempted_change in *all* cases, both
* on success and failure, to indicate what we intended to do! */
@@ -161,7 +160,7 @@ int clock_apply_epoch(ClockChangeDirection *ret_attempted_change) {
return 0;
}
- if (clock_settime(CLOCK_REALTIME, timespec_store(&ts, epoch_usec)) < 0)
+ if (clock_settime(CLOCK_REALTIME, TIMESPEC_STORE(epoch_usec)) < 0)
return -errno;
return 1;
diff --git a/src/timesync/timesyncd.c b/src/timesync/timesyncd.c
index 6f316746f5..471a63689e 100644
--- a/src/timesync/timesyncd.c
+++ b/src/timesync/timesyncd.c
@@ -72,13 +72,12 @@ static int load_clock_timestamp(uid_t uid, gid_t gid) {
settime:
ct = now(CLOCK_REALTIME);
if (ct < min) {
- struct timespec ts;
char date[FORMAT_TIMESTAMP_MAX];
log_info("System clock time unset or jumped backwards, restoring from recorded timestamp: %s",
format_timestamp(date, sizeof(date), min));
- if (clock_settime(CLOCK_REALTIME, timespec_store(&ts, min)) < 0)
+ if (clock_settime(CLOCK_REALTIME, TIMESPEC_STORE(min)) < 0)
log_error_errno(errno, "Failed to restore system clock, ignoring: %m");
}
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 e98b38510e..2535593775 100644
--- a/src/tty-ask-password-agent/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent/tty-ask-password-agent.c
@@ -581,8 +581,6 @@ static int ask_on_this_console(const char *tty, pid_t *ret_pid, char **arguments
}
static void terminate_agents(Set *pids) {
- struct timespec ts;
- siginfo_t status = {};
sigset_t set;
void *p;
int r, signum;
@@ -599,11 +597,10 @@ static void terminate_agents(Set *pids) {
*/
assert_se(sigemptyset(&set) >= 0);
assert_se(sigaddset(&set, SIGCHLD) >= 0);
- timespec_store(&ts, 50 * USEC_PER_MSEC);
while (!set_isempty(pids)) {
+ siginfo_t status = {};
- zero(status);
r = waitid(P_ALL, 0, &status, WEXITED|WNOHANG);
if (r < 0 && errno == EINTR)
continue;
@@ -613,7 +610,7 @@ static void terminate_agents(Set *pids) {
continue;
}
- signum = sigtimedwait(&set, NULL, &ts);
+ signum = sigtimedwait(&set, NULL, TIMESPEC_STORE(50 * USEC_PER_MSEC));
if (signum < 0) {
if (errno != EAGAIN)
log_error_errno(errno, "sigtimedwait() failed: %m");
diff --git a/src/userdb/userdbd-manager.c b/src/userdb/userdbd-manager.c
index 0564840dbe..aabf8070d2 100644
--- a/src/userdb/userdbd-manager.c
+++ b/src/userdb/userdbd-manager.c
@@ -251,7 +251,6 @@ static int start_workers(Manager *m, bool explicit_request) {
}
int manager_startup(Manager *m) {
- struct timeval ts;
int n, r;
assert(m);
@@ -300,7 +299,7 @@ int manager_startup(Manager *m) {
/* Let's make sure every accept() call on this socket times out after 25s. This allows workers to be
* GC'ed on idle */
- if (setsockopt(m->listen_fd, SOL_SOCKET, SO_RCVTIMEO, timeval_store(&ts, LISTEN_TIMEOUT_USEC), sizeof(ts)) < 0)
+ if (setsockopt(m->listen_fd, SOL_SOCKET, SO_RCVTIMEO, TIMEVAL_STORE(LISTEN_TIMEOUT_USEC), sizeof(struct timeval)) < 0)
return log_error_errno(errno, "Failed to se SO_RCVTIMEO: %m");
return start_workers(m, false);