nspawn: Join network namespace with setns()

We don't have /proc mounted which means namespace_enter() won't work
on older kernels, so use setns() instead.
This commit is contained in:
Daan De Meyer
2026-02-17 11:45:01 +01:00
parent f9dbf6fd5a
commit f6bcd125db
+2 -9
View File
@@ -4368,15 +4368,8 @@ static int outer_child(
/* The inner child has all namespaces that are requested, so that we all are owned by the
* user if user namespaces are turned on. */
if (arg_network_namespace_path) {
r = namespace_enter(/* pidns_fd= */ -EBADF,
/* mntns_fd= */ -EBADF,
netns_fd,
/* userns_fd= */ -EBADF,
/* root_fd= */ -EBADF);
if (r < 0)
return log_error_errno(r, "Failed to join network namespace: %m");
}
if (arg_network_namespace_path && setns(netns_fd, CLONE_NEWNET) < 0)
return log_error_errno(errno, "Failed to join network namespace: %m");
if (arg_userns_mode == USER_NAMESPACE_MANAGED) {
/* In managed usernamespace operation, sysfs + procfs are special, we'll have to