From 11537375e38ecd63840c4a0b936b5d3279af2e62 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sun, 27 Jun 2021 03:31:52 +0900 Subject: [PATCH] sd-netlink: use usec_sub_unsigned() and USEC_INFINITY And shorten code more. --- src/libsystemd/sd-netlink/sd-netlink.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/libsystemd/sd-netlink/sd-netlink.c b/src/libsystemd/sd-netlink/sd-netlink.c index 819ce71359..f8a1bde6a6 100644 --- a/src/libsystemd/sd-netlink/sd-netlink.c +++ b/src/libsystemd/sd-netlink/sd-netlink.c @@ -525,7 +525,7 @@ static usec_t calc_elapse(uint64_t usec) { return usec_add(now(CLOCK_MONOTONIC), usec); } -static int rtnl_poll(sd_netlink *rtnl, bool need_more, uint64_t timeout_usec) { +static int rtnl_poll(sd_netlink *rtnl, bool need_more, usec_t timeout_usec) { usec_t m = USEC_INFINITY; int r, e; @@ -541,23 +541,18 @@ static int rtnl_poll(sd_netlink *rtnl, bool need_more, uint64_t timeout_usec) { e |= POLLIN; else { usec_t until; + /* Caller wants to process if there is something to * process, but doesn't care otherwise */ r = sd_netlink_get_timeout(rtnl, &until); if (r < 0) return r; - if (r > 0) { - usec_t nw; - nw = now(CLOCK_MONOTONIC); - m = until > nw ? until - nw : 0; - } + + m = usec_sub_unsigned(until, now(CLOCK_MONOTONIC)); } - if (timeout_usec != UINT64_MAX && (m == USEC_INFINITY || timeout_usec < m)) - m = timeout_usec; - - r = fd_wait_for_event(rtnl->fd, e, m); + r = fd_wait_for_event(rtnl->fd, e, MIN(m, timeout_usec)); if (r <= 0) return r; @@ -716,9 +711,9 @@ int sd_netlink_read( if (n >= timeout) return -ETIMEDOUT; - left = timeout - n; + left = usec_sub_unsigned(timeout, n); } else - left = UINT64_MAX; + left = USEC_INFINITY; r = rtnl_poll(rtnl, true, left); if (r < 0)