From 971fea32035b642eda6154ef963a6269e9d271ec Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 27 Nov 2017 16:28:53 +0100 Subject: [PATCH 1/2] sd-resolve: propagate timeouts in sd_resolve_wait() the same way as in sd_bus_wait(): ETIMEDOUT Thankfully this is an internal API still, so we can mkae changes like this. --- src/basic/io-util.c | 1 - src/libsystemd/sd-resolve/sd-resolve.c | 2 ++ 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/basic/io-util.c b/src/basic/io-util.c index 98bb1857d9..77c9bdc739 100644 --- a/src/basic/io-util.c +++ b/src/basic/io-util.c @@ -200,7 +200,6 @@ int fd_wait_for_event(int fd, int event, usec_t t) { r = ppoll(&pollfd, 1, t == USEC_INFINITY ? NULL : timespec_store(&ts, t), NULL); if (r < 0) return -errno; - if (r == 0) return 0; diff --git a/src/libsystemd/sd-resolve/sd-resolve.c b/src/libsystemd/sd-resolve/sd-resolve.c index 986768e7b3..61a0a4c1de 100644 --- a/src/libsystemd/sd-resolve/sd-resolve.c +++ b/src/libsystemd/sd-resolve/sd-resolve.c @@ -890,6 +890,8 @@ _public_ int sd_resolve_wait(sd_resolve *resolve, uint64_t timeout_usec) { if (r < 0) return r; + if (r == 0) + return -ETIMEDOUT; return sd_resolve_process(resolve); } From 5bf5510b8f1637c64638000f09ca9b5123046d26 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Mon, 27 Nov 2017 16:29:41 +0100 Subject: [PATCH 2/2] test-resolve: make sure we don't hang forever If test-resolve is running in some CI environment that doesn't have reliably working DNS, it's a good idea not to hang forever, let's time-out after 20s --- src/libsystemd/sd-resolve/test-resolve.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/libsystemd/sd-resolve/test-resolve.c b/src/libsystemd/sd-resolve/test-resolve.c index 93083f8975..752eb15228 100644 --- a/src/libsystemd/sd-resolve/test-resolve.c +++ b/src/libsystemd/sd-resolve/test-resolve.c @@ -34,6 +34,8 @@ #include "socket-util.h" #include "string-util.h" +#define TEST_TIMEOUT_USEC (20*USEC_PER_SEC) + static int getaddrinfo_handler(sd_resolve_query *q, int ret, const struct addrinfo *ai, void *userdata) { const struct addrinfo *i; @@ -102,9 +104,18 @@ int main(int argc, char *argv[]) { /* Wait until all queries are completed */ for (;;) { - r = sd_resolve_wait(resolve, (uint64_t) -1); + r = sd_resolve_wait(resolve, TEST_TIMEOUT_USEC); if (r == 0) break; + if (r == -ETIMEDOUT) { + /* Let's catch time-outs here, so that we can run safely in a CI that has no reliable DNS. Note + * that we invoke exit() directly here, as the stuck NSS call will not allow us to exit + * cleanly. */ + + log_notice_errno(r, "sd_resolve_wait() timed out, but that's OK"); + exit(EXIT_SUCCESS); + break; + } if (r < 0) { log_error_errno(r, "sd_resolve_wait(): %m"); assert_not_reached("sd_resolve_wait() failed");