This way we can convert usec_t to timespec on-the-fly, without a buffer.
No actual behaviour change just some shortening of code.
}
int ppoll_usec(struct pollfd *fds, size_t nfds, usec_t timeout) {
- struct timespec ts;
int r;
assert(fds || nfds == 0);
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)
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) {
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_;
}
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. */
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.",
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.
*
* 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;
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;
#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! */
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;
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");
}
}
static void terminate_agents(Set *pids) {
- struct timespec ts;
- siginfo_t status = {};
sigset_t set;
void *p;
int r, signum;
*/
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;
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");
}
int manager_startup(Manager *m) {
- struct timeval ts;
int n, r;
assert(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);