diff options
author | Christian Brauner <brauner@kernel.org> | 2022-09-30 15:05:02 +0200 |
---|---|---|
committer | Christian Brauner (Microsoft) <brauner@kernel.org> | 2022-10-04 18:51:30 +0200 |
commit | f7a2dc3dd507ffa04b2c337c163f0a6e523eb765 (patch) | |
tree | 5061c838d5dc57934a1db3230427b432597e7885 /src/nspawn/nspawn.c | |
parent | 2fe299a320757bf5a3e0362a00e570d3bf713eab (diff) | |
download | systemd-f7a2dc3dd507ffa04b2c337c163f0a6e523eb765.tar.gz |
nspawn: use in_same_namespace() helper
Diffstat (limited to 'src/nspawn/nspawn.c')
-rw-r--r-- | src/nspawn/nspawn.c | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index 056d4f1bc5..01a67b5553 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -5387,8 +5387,6 @@ static int initialize_rlimits(void) { } static int cant_be_in_netns(void) { - char udev_path[STRLEN("/proc//ns/net") + DECIMAL_STR_MAX(pid_t)]; - _cleanup_free_ char *udev_ns = NULL, *our_ns = NULL; _cleanup_close_ int fd = -1; struct ucred ucred; int r; @@ -5417,16 +5415,10 @@ static int cant_be_in_netns(void) { if (r < 0) return log_error_errno(r, "Failed to determine peer of udev control socket: %m"); - xsprintf(udev_path, "/proc/" PID_FMT "/ns/net", ucred.pid); - r = readlink_malloc(udev_path, &udev_ns); + r = in_same_namespace(ucred.pid, 0, NAMESPACE_NET); if (r < 0) - return log_error_errno(r, "Failed to read network namespace of udev: %m"); - - r = readlink_malloc("/proc/self/ns/net", &our_ns); - if (r < 0) - return log_error_errno(r, "Failed to read our own network namespace: %m"); - - if (!streq(our_ns, udev_ns)) + return log_error_errno(r, "Failed to determine network namespace of udev: %m"); + if (r == 0) return log_error_errno(SYNTHETIC_ERRNO(EOPNOTSUPP), "Sorry, but --image= is only supported in the main network namespace, since we need access to udev/AF_NETLINK."); return 0; |