#include <endian.h>
#include <netdb.h>
-#include <poll.h>
#include <pthread.h>
#include <signal.h>
#include <stdlib.h>
#include "fd-util.h"
#include "hexdecoct.h"
#include "hostname-util.h"
+#include "io-util.h"
#include "macro.h"
#include "memory-util.h"
#include "missing_syscall.h"
.creds_mask = SD_BUS_CREDS_WELL_KNOWN_NAMES|SD_BUS_CREDS_UNIQUE_NAME,
.accept_fd = true,
.original_pid = getpid_cached(),
- .n_groups = (size_t) -1,
+ .n_groups = SIZE_MAX,
.close_on_exit = true,
};
* hence let's fill something in for synthetic messages. Since
* synthetic messages might have a fake sender and we don't
* want to interfere with the real sender's serial numbers we
- * pick a fixed, artificial one. We use (uint32_t) -1 rather
- * than (uint64_t) -1 since dbus1 only had 32bit identifiers,
+ * pick a fixed, artificial one. We use UINT32_MAX rather
+ * than UINT64_MAX since dbus1 only had 32bit identifiers,
* even though kdbus can do 64bit. */
return sd_bus_message_seal(m, 0xFFFFFFFFULL, 0);
}
static usec_t calc_elapse(sd_bus *bus, uint64_t usec) {
assert(bus);
- if (usec == (uint64_t) -1)
+ assert_cc(sizeof(usec_t) == sizeof(uint64_t));
+
+ if (usec == USEC_INFINITY)
return 0;
/* We start all timeouts the instant we enter BUS_HELLO/BUS_RUNNING state, so that the don't run in parallel
if (IN_SET(bus->state, BUS_WATCH_BIND, BUS_OPENING, BUS_AUTHENTICATING))
return usec;
else
- return now(CLOCK_MONOTONIC) + usec;
+ return usec_add(now(CLOCK_MONOTONIC), usec);
}
static int timeout_compare(const void *a, const void *b) {
if (r > 0)
continue;
- r = sd_bus_wait(bus, (uint64_t) -1);
+ r = sd_bus_wait(bus, UINT64_MAX);
if (r < 0)
return r;
}
left = timeout - n;
} else
- left = (uint64_t) -1;
+ left = UINT64_MAX;
r = bus_poll(bus, true, left);
if (r < 0)
c = prioq_peek(bus->reply_callbacks_prioq);
if (!c) {
- *timeout_usec = (uint64_t) -1;
+ *timeout_usec = UINT64_MAX;
return 0;
}
if (c->timeout_usec == 0) {
- *timeout_usec = (uint64_t) -1;
+ *timeout_usec = UINT64_MAX;
return 0;
}
case BUS_WATCH_BIND:
case BUS_OPENING:
- *timeout_usec = (uint64_t) -1;
+ *timeout_usec = UINT64_MAX;
return 0;
default:
static int bus_poll(sd_bus *bus, bool need_more, uint64_t timeout_usec) {
struct pollfd p[2] = {};
- int r, n;
- struct timespec ts;
usec_t m = USEC_INFINITY;
+ int r, n;
assert(bus);
}
}
- if (timeout_usec != (uint64_t) -1 && (m == USEC_INFINITY || timeout_usec < m))
+ if (timeout_usec != UINT64_MAX && (m == USEC_INFINITY || timeout_usec < m))
m = timeout_usec;
- r = ppoll(p, n, m == USEC_INFINITY ? NULL : timespec_store(&ts, m), NULL);
- if (r < 0)
- return -errno;
- if (r == 0)
- return 0;
-
- if (p[0].revents & POLLNVAL)
- return -EBADF;
- if (n >= 2 && (p[1].revents & POLLNVAL))
- return -EBADF;
+ r = ppoll_usec(p, n, m);
+ if (r <= 0)
+ return r;
return 1;
}
if (bus->wqueue_size <= 0)
return 0;
- r = bus_poll(bus, false, (uint64_t) -1);
+ r = bus_poll(bus, false, UINT64_MAX);
if (r < 0)
return r;
}