Commit 9cef1a00 authored by Pavel Emelyanov's avatar Pavel Emelyanov

mount: Factor out detached mountpoint opening

The difficulty is that this code is required in both -- pie
and non-pie contexts.
Signed-off-by: 's avatarPavel Emelyanov <xemul@parallels.com>
parent 72ec39f1
......@@ -59,4 +59,5 @@ static inline int recv_fd(int sock)
return fd;
}
int open_detach_mount(char *dir);
#endif /* __CR_UTIL_NET_H__ */
......@@ -15,6 +15,7 @@
#include "crtools.h"
#include "asm/types.h"
#include "util.h"
#include "util-pie.h"
#include "log.h"
#include "mount.h"
#include "proc_parse.h"
......@@ -289,20 +290,7 @@ static DIR *open_mountpoint(struct mount_info *pm)
goto out;
}
fd = open(mnt_path, O_RDONLY | O_DIRECTORY);
if (fd < 0)
pr_perror("Can't open %s\n", mnt_path);
if (umount2(mnt_path, MNT_DETACH)) {
pr_perror("Can't umount %s", mnt_path);
goto out;
}
if (rmdir(mnt_path)) {
pr_perror("Can't remove the directory %s", mnt_path);
goto out;
}
fd = open_detach_mount(mnt_path);
if (fd < 0)
goto out;
......
......@@ -237,22 +237,11 @@ static int parasite_get_proc_fd()
if (sys_mount("proc", proc_mountpoint, "proc", MS_MGC_VAL, NULL)) {
pr_err("mount failed\n");
goto out_rmdir;
}
fd = sys_open(proc_mountpoint, O_RDONLY, 0);
if (sys_umount2(proc_mountpoint, MNT_DETACH)) {
pr_err("Can't umount procfs\n");
return -1;
}
out_rmdir:
if (sys_rmdir(proc_mountpoint)) {
pr_err("Can't remove directory\n");
sys_rmdir(proc_mountpoint);
return -1;
}
fd = open_detach_mount(proc_mountpoint);
out_send_fd:
if (fd < 0)
return fd;
......
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/mount.h>
#include <errno.h>
......@@ -7,7 +8,7 @@
#include "asm/string.h"
#include "asm/types.h"
#include "syscall.h"
#include "log.h"
#include "util-pie.h"
static void scm_fdset_init_chunk(struct scm_fdset *fdset, int nr_fds)
......@@ -149,3 +150,28 @@ int recv_fds(int sock, int *fds, int nr_fds, struct fd_opts *opts)
return 0;
}
int open_detach_mount(char *dir)
{
int fd;
fd = sys_open(dir, O_RDONLY | O_DIRECTORY, 0);
if (fd < 0)
pr_perror("Can't open directory");
if (sys_umount2(dir, MNT_DETACH)) {
pr_perror("Can't detach mount");
goto err_close;
}
if (sys_rmdir(dir)) {
pr_perror("Can't remove tmp dir");
goto err_close;
}
return fd;
err_close:
if (fd >= 0)
sys_close(fd);
return -1;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment