namespace-util: introduce helper for combining unshare() + MS_SLAVE remount
We have multiple places we do these two non-trivial operations together, let's introduce a unified helper for doing both at once.
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/mount.h>
|
||||
|
||||
#include "fd-util.h"
|
||||
#include "missing_fs.h"
|
||||
@@ -169,3 +170,16 @@ int fd_is_network_ns(int fd) {
|
||||
|
||||
return r == CLONE_NEWNET;
|
||||
}
|
||||
|
||||
int detach_mount_namespace(void) {
|
||||
|
||||
/* Detaches the mount namespace, disabling propagation from our namespace to the host */
|
||||
|
||||
if (unshare(CLONE_NEWNS) < 0)
|
||||
return -errno;
|
||||
|
||||
if (mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL) < 0)
|
||||
return -errno;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -7,3 +7,5 @@ int namespace_open(pid_t pid, int *pidns_fd, int *mntns_fd, int *netns_fd, int *
|
||||
int namespace_enter(int pidns_fd, int mntns_fd, int netns_fd, int userns_fd, int root_fd);
|
||||
|
||||
int fd_is_network_ns(int fd);
|
||||
|
||||
int detach_mount_namespace(void);
|
||||
|
||||
Reference in New Issue
Block a user