1
0
mirror of https://github.com/systemd/systemd.git synced 2025-03-19 22:50:17 +03:00

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.
This commit is contained in:
Luca Boccassi 2024-03-03 18:14:31 +00:00
parent ba3c8e685a
commit 1e61de81f2

View File

@ -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