summaryrefslogtreecommitdiffstats
path: root/src/basic
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2024-11-08 23:06:44 +0100
committerLuca Boccassi <luca.boccassi@gmail.com>2024-11-13 15:18:05 +0100
commit9466fe014f6083825ed819fe17bf98f72baa3af9 (patch)
treea795538d80786d786d845a22ae3f8ce4bf29a4bf /src/basic
parentnetwork/ndisc: fix removal of unnecessary routes (#35128) (diff)
downloadsystemd-9466fe014f6083825ed819fe17bf98f72baa3af9.tar.xz
systemd-9466fe014f6083825ed819fe17bf98f72baa3af9.zip
namespace-util: pin pid via pidfd during namespace_open()
Diffstat (limited to 'src/basic')
-rw-r--r--src/basic/namespace-util.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/basic/namespace-util.c b/src/basic/namespace-util.c
index a80ed32791..2c61506149 100644
--- a/src/basic/namespace-util.c
+++ b/src/basic/namespace-util.c
@@ -136,12 +136,14 @@ int namespace_open(
int *ret_userns_fd,
int *ret_root_fd) {
- assert(pid >= 0);
+ _cleanup_(pidref_done) PidRef pidref = PIDREF_NULL;
+ int r;
- if (pid == 0)
- pid = getpid_cached();
+ r = pidref_set_pid(&pidref, pid);
+ if (r < 0)
+ return r;
- return pidref_namespace_open(&PIDREF_MAKE_FROM_PID(pid), ret_pidns_fd, ret_mntns_fd, ret_netns_fd, ret_userns_fd, ret_root_fd);
+ return pidref_namespace_open(&pidref, ret_pidns_fd, ret_mntns_fd, ret_netns_fd, ret_userns_fd, ret_root_fd);
}
int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int root_fd) {