sd-bus: Don't fork unnecessarily to connect to container
Let's check if we're already in the right namespaces and call connect() directly if that's the case. This can easily happen when the machine is specified as .host or so.
This commit is contained in:
@@ -373,6 +373,42 @@ int is_our_namespace(int fd, NamespaceType type) {
|
||||
return fd_inode_same(fd, our_ns);
|
||||
}
|
||||
|
||||
int are_our_namespaces(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int root_fd) {
|
||||
int r;
|
||||
|
||||
if (pidns_fd >= 0) {
|
||||
r = is_our_namespace(pidns_fd, NAMESPACE_PID);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (mntns_fd >= 0) {
|
||||
r = is_our_namespace(mntns_fd, NAMESPACE_MOUNT);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (netns_fd >= 0) {
|
||||
r = is_our_namespace(netns_fd, NAMESPACE_NET);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (userns_fd >= 0) {
|
||||
r = is_our_namespace(userns_fd, NAMESPACE_USER);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (root_fd >= 0) {
|
||||
r = dir_fd_is_root(root_fd);
|
||||
if (r <= 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int namespace_is_init(NamespaceType type) {
|
||||
int r;
|
||||
|
||||
|
||||
@@ -50,6 +50,7 @@ int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int
|
||||
|
||||
int fd_is_namespace(int fd, NamespaceType type);
|
||||
int is_our_namespace(int fd, NamespaceType type);
|
||||
int are_our_namespaces(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int root_fd);
|
||||
|
||||
int namespace_is_init(NamespaceType type);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user