lxccontainer: do_lxcapi_mount() coding-style

parent 117deb70
...@@ -4992,14 +4992,15 @@ static bool do_lxcapi_restore(struct lxc_container *c, char *directory, bool ver ...@@ -4992,14 +4992,15 @@ static bool do_lxcapi_restore(struct lxc_container *c, char *directory, bool ver
WRAP_API_2(bool, lxcapi_restore, char *, bool) WRAP_API_2(bool, lxcapi_restore, char *, bool)
static int do_lxcapi_mount(struct lxc_container *c, static int do_lxcapi_mount(struct lxc_container *c, const char *source,
const char *source, const char *target, const char *target, const char *filesystemtype,
const char *filesystemtype, unsigned long mountflags, unsigned long mountflags, const void *data,
const void *data, struct lxc_mount *mnt) { struct lxc_mount *mnt)
{
char *suff, *sret; char *suff, *sret;
size_t len;
char template[MAXPATHLEN], path[MAXPATHLEN]; char template[MAXPATHLEN], path[MAXPATHLEN];
pid_t pid, init_pid; pid_t pid, init_pid;
size_t len;
struct stat sb; struct stat sb;
int ret = -1, fd = -EBADF; int ret = -1, fd = -EBADF;
...@@ -5032,28 +5033,18 @@ static int do_lxcapi_mount(struct lxc_container *c, ...@@ -5032,28 +5033,18 @@ static int do_lxcapi_mount(struct lxc_container *c,
} }
} }
if ((sb.st_mode & S_IFMT) == S_IFDIR) { if (S_ISDIR(sb.st_mode)) {
sret = mkdtemp(template); sret = mkdtemp(template);
if (!sret) { if (!sret) {
SYSERROR("Could not create shmounts temporary dir"); SYSERROR("Could not create shmounts temporary dir");
goto out; goto out;
} }
ret = chmod(template, 0);
if (ret < 0) {
SYSERROR("Could not chmod shmounts temporary dir \"%s\"", template);
goto out;
}
} else { } else {
fd = lxc_make_tmpfile(template, false); fd = lxc_make_tmpfile(template, false);
if (fd < 0) { if (fd < 0) {
SYSERROR("Could not create shmounts temporary file"); SYSERROR("Could not create shmounts temporary file");
goto out; goto out;
} }
ret = fchmod(fd, 0);
if (ret < 0) {
SYSERROR("Could not chmod shmounts temporary file");
goto out;
}
} }
/* Do the fork */ /* Do the fork */
...@@ -5070,6 +5061,7 @@ static int do_lxcapi_mount(struct lxc_container *c, ...@@ -5070,6 +5061,7 @@ static int do_lxcapi_mount(struct lxc_container *c,
SYSERROR("Failed to mount onto \"%s\"", template); SYSERROR("Failed to mount onto \"%s\"", template);
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
} }
TRACE("Mounted \"%s\" onto \"%s\"", source, template);
init_pid = do_lxcapi_init_pid(c); init_pid = do_lxcapi_init_pid(c);
if (init_pid < 0) { if (init_pid < 0) {
...@@ -5084,6 +5076,7 @@ static int do_lxcapi_mount(struct lxc_container *c, ...@@ -5084,6 +5076,7 @@ static int do_lxcapi_mount(struct lxc_container *c,
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
} }
} }
if (!switch_to_ns(init_pid, "mnt")) { if (!switch_to_ns(init_pid, "mnt")) {
ERROR("Failed to enter mount namespace"); ERROR("Failed to enter mount namespace");
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
...@@ -5092,6 +5085,7 @@ static int do_lxcapi_mount(struct lxc_container *c, ...@@ -5092,6 +5085,7 @@ static int do_lxcapi_mount(struct lxc_container *c,
ret = create_mount_target(sb.st_mode, target); ret = create_mount_target(sb.st_mode, target);
if (ret < 0) if (ret < 0)
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
TRACE("Created mount target \"%s\"", target);
suff = strrchr(template, '/'); suff = strrchr(template, '/');
if (!suff) if (!suff)
...@@ -5104,11 +5098,12 @@ static int do_lxcapi_mount(struct lxc_container *c, ...@@ -5104,11 +5098,12 @@ static int do_lxcapi_mount(struct lxc_container *c,
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
} }
ret = mount(path, target, NULL, MS_REC | MS_MOVE, NULL); ret = mount(path, target, NULL, MS_MOVE | MS_REC, NULL);
if (ret < 0) { if (ret < 0) {
SYSERROR("Failed to move the mount from \"%s\" to \"%s\"", path, target); SYSERROR("Failed to move the mount from \"%s\" to \"%s\"", path, target);
_exit(EXIT_FAILURE); _exit(EXIT_FAILURE);
} }
TRACE("Moved mount from \"%s\" to \"%s\"", path, target);
_exit(EXIT_SUCCESS); _exit(EXIT_SUCCESS);
} }
...@@ -5127,6 +5122,7 @@ static int do_lxcapi_mount(struct lxc_container *c, ...@@ -5127,6 +5122,7 @@ static int do_lxcapi_mount(struct lxc_container *c,
out: out:
if (fd >= 0) if (fd >= 0)
close(fd); close(fd);
return ret; return ret;
} }
......
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