From ba3c8e685a5d8d81c2c825f79a8cea23f4edf01e Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sun, 3 Mar 2024 18:15:26 +0000 Subject: [PATCH 1/2] test: fix test-loopback failure when lacking privileges Setting up the loopback might fail due to lack of privileges, as it happens when running unit tests in the Noble CI environment. Skip the test when it happens. 1584s 862/1330 systemd:test / test-loopback FAIL 0.01s exit status 1 1584s /* test_loopback_setup */ 1584s Failed to configure loopback network device, ignoring: Operation not permitted 1584s loopback: Operation not permitted --- src/test/test-loopback.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/test-loopback.c b/src/test/test-loopback.c index 48869ae337..db6ee0f32d 100644 --- a/src/test/test-loopback.c +++ b/src/test/test-loopback.c @@ -19,6 +19,8 @@ TEST_RET(loopback_setup) { } r = loopback_setup(); + if (ERRNO_IS_NEG_PRIVILEGE(r)) + return log_tests_skipped("lacking privileges"); if (r < 0) return log_error_errno(r, "loopback: %m"); From 1e61de81f222056df9b0a045aa4faa3b23d91520 Mon Sep 17 00:00:00 2001 From: Luca Boccassi Date: Sun, 3 Mar 2024 18:14:31 +0000 Subject: [PATCH 2/2] test: fix test-resolved-stream unit test failure On Noble setting this ioctl fails: 1570s 819/1330 systemd:resolve / test-resolved-stream FAIL 0.14s killed by signal 6 SIGABRT 1570s Successfully forked off '(usernstest)' as PID 27737. 1570s Skipping PR_SET_MM, as we don't have privileges. 1570s (usernstest) succeeded. 1570s Assertion 'ioctl(socket_fd, SIOCSIFFLAGS, &req) >= 0' failed at src/resolve/test-resolved-stream.c:372, function try_isolate_network(). Aborting. Ignore the result. --- src/resolve/test-resolved-stream.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/resolve/test-resolved-stream.c b/src/resolve/test-resolved-stream.c index 847de04f90..4f27eac3da 100644 --- a/src/resolve/test-resolved-stream.c +++ b/src/resolve/test-resolved-stream.c @@ -329,7 +329,7 @@ static void test_dns_stream(bool tls) { log_info("test-resolved-stream: Finished %s test", tls ? "TLS" : "TCP"); } -static void try_isolate_network(void) { +static int try_isolate_network(void) { _cleanup_close_ int socket_fd = -EBADF; int r; @@ -356,20 +356,25 @@ static void try_isolate_network(void) { _exit(EXIT_SUCCESS); } if (r == -EPROTO) /* EPROTO means nonzero exit code of child, i.e. the tests in the child failed */ - return; + return 0; assert_se(r > 0); /* Now that we know that the unshare() is safe, let's actually do it */ assert_se(unshare(CLONE_NEWUSER | CLONE_NEWNET) >= 0); - /* Bring up the loopback interfaceon the newly created network namespace */ + /* Bring up the loopback interface on the newly created network namespace */ struct ifreq req = { .ifr_ifindex = 1 }; assert_se((socket_fd = socket(AF_INET, SOCK_STREAM | SOCK_CLOEXEC, 0)) >= 0); assert_se(ioctl(socket_fd, SIOCGIFNAME, &req) >= 0); assert_se(ioctl(socket_fd, SIOCGIFFLAGS, &req) >= 0); assert_se(FLAGS_SET(req.ifr_flags, IFF_LOOPBACK)); req.ifr_flags |= IFF_UP; - assert_se(ioctl(socket_fd, SIOCSIFFLAGS, &req) >= 0); + /* Do not assert on this, fails in the Ubuntu 24.04 CI environment */ + r = RET_NERRNO(ioctl(socket_fd, SIOCSIFFLAGS, &req)); + if (r < 0) + return r; + + return 0; } int main(int argc, char **argv) { @@ -378,10 +383,14 @@ int main(int argc, char **argv) { .in.sin_port = htobe16(random_u64_range(UINT16_MAX - 1024) + 1024), .in.sin_addr.s_addr = htobe32(INADDR_LOOPBACK) }; + int r; test_setup_logging(LOG_DEBUG); - try_isolate_network(); + r = try_isolate_network(); + if (ERRNO_IS_NEG_PRIVILEGE(r)) + return log_tests_skipped("lacking privileges"); + assert_se(r >= 0); test_dns_stream(false); #if ENABLE_DNS_OVER_TLS