summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Yuan <me@yhndnzj.com>2024-06-10 17:45:39 +0200
committerMike Yuan <me@yhndnzj.com>2024-07-23 19:30:55 +0200
commit974e34a018cb54d85cd17e189b99c44341715427 (patch)
tree567db72c4119bf87b324176fcf150d35e2719b22
parentmount-util: clean up mount_exchange_graceful a bit, don't duplicate move_moun... (diff)
downloadsystemd-974e34a018cb54d85cd17e189b99c44341715427.tar.xz
systemd-974e34a018cb54d85cd17e189b99c44341715427.zip
mount-util: do not unnecessarily acquire mountns fd twice
This also enables us to use pidref_namespace_open().
-rw-r--r--src/shared/mount-util.c10
1 files changed, 3 insertions, 7 deletions
diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c
index 0b3154fbd9..f5073db7f9 100644
--- a/src/shared/mount-util.c
+++ b/src/shared/mount-util.c
@@ -1105,20 +1105,16 @@ static int mount_in_namespace(
if (!pidref_is_set(target))
return -ESRCH;
- r = namespace_open(target->pid, &pidns_fd, &mntns_fd, /* ret_netns_fd = */ NULL, /* ret_userns_fd = */ NULL, &root_fd);
+ r = pidref_namespace_open(target, &pidns_fd, &mntns_fd, /* ret_netns_fd = */ NULL, /* ret_userns_fd = */ NULL, &root_fd);
if (r < 0)
return log_debug_errno(r, "Failed to retrieve FDs of the target process' namespace: %m");
- r = in_same_namespace(target->pid, 0, NAMESPACE_MOUNT);
+ r = inode_same_at(mntns_fd, "", AT_FDCWD, "/proc/self/ns/mnt", AT_EMPTY_PATH);
if (r < 0)
return log_debug_errno(r, "Failed to determine if mount namespaces are equal: %m");
/* We can't add new mounts at runtime if the process wasn't started in a namespace */
if (r > 0)
- return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to activate bind mount in target, not running in a mount namespace");
-
- r = pidref_verify(target);
- if (r < 0)
- return log_debug_errno(r, "Failed to verify target process '" PID_FMT "': %m", target->pid);
+ return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to activate bind mount in target, not running in a mount namespace.");
r = chase(src, NULL, 0, &chased_src_path, &chased_src_fd);
if (r < 0)