conf: cleanup macros lxc_pivot_root

parent 4fdd1f72
...@@ -1472,8 +1472,8 @@ int lxc_chroot(const struct lxc_rootfs *rootfs) ...@@ -1472,8 +1472,8 @@ int lxc_chroot(const struct lxc_rootfs *rootfs)
*/ */
static int lxc_pivot_root(const char *rootfs) static int lxc_pivot_root(const char *rootfs)
{ {
int oldroot; __do_close_prot_errno int oldroot = -EBADF, newroot = -EBADF;
int newroot = -1, ret = -1; int ret;
oldroot = open("/", O_DIRECTORY | O_RDONLY | O_CLOEXEC); oldroot = open("/", O_DIRECTORY | O_RDONLY | O_CLOEXEC);
if (oldroot < 0) { if (oldroot < 0) {
...@@ -1484,23 +1484,21 @@ static int lxc_pivot_root(const char *rootfs) ...@@ -1484,23 +1484,21 @@ static int lxc_pivot_root(const char *rootfs)
newroot = open(rootfs, O_DIRECTORY | O_RDONLY | O_CLOEXEC); newroot = open(rootfs, O_DIRECTORY | O_RDONLY | O_CLOEXEC);
if (newroot < 0) { if (newroot < 0) {
SYSERROR("Failed to open new root directory"); SYSERROR("Failed to open new root directory");
goto on_error; return -1;
} }
/* change into new root fs */ /* change into new root fs */
ret = fchdir(newroot); ret = fchdir(newroot);
if (ret < 0) { if (ret < 0) {
ret = -1;
SYSERROR("Failed to change to new rootfs \"%s\"", rootfs); SYSERROR("Failed to change to new rootfs \"%s\"", rootfs);
goto on_error; return -1;
} }
/* pivot_root into our new root fs */ /* pivot_root into our new root fs */
ret = pivot_root(".", "."); ret = pivot_root(".", ".");
if (ret < 0) { if (ret < 0) {
ret = -1;
SYSERROR("Failed to pivot_root()"); SYSERROR("Failed to pivot_root()");
goto on_error; return -1;
} }
/* At this point the old-root is mounted on top of our new-root. To /* At this point the old-root is mounted on top of our new-root. To
...@@ -1509,9 +1507,8 @@ static int lxc_pivot_root(const char *rootfs) ...@@ -1509,9 +1507,8 @@ static int lxc_pivot_root(const char *rootfs)
*/ */
ret = fchdir(oldroot); ret = fchdir(oldroot);
if (ret < 0) { if (ret < 0) {
ret = -1;
SYSERROR("Failed to enter old root directory"); SYSERROR("Failed to enter old root directory");
goto on_error; return -1;
} }
/* Make oldroot rslave to make sure our umounts don't propagate to the /* Make oldroot rslave to make sure our umounts don't propagate to the
...@@ -1519,36 +1516,25 @@ static int lxc_pivot_root(const char *rootfs) ...@@ -1519,36 +1516,25 @@ static int lxc_pivot_root(const char *rootfs)
*/ */
ret = mount("", ".", "", MS_SLAVE | MS_REC, NULL); ret = mount("", ".", "", MS_SLAVE | MS_REC, NULL);
if (ret < 0) { if (ret < 0) {
ret = -1;
SYSERROR("Failed to make oldroot rslave"); SYSERROR("Failed to make oldroot rslave");
goto on_error; return -1;
} }
ret = umount2(".", MNT_DETACH); ret = umount2(".", MNT_DETACH);
if (ret < 0) { if (ret < 0) {
ret = -1;
SYSERROR("Failed to detach old root directory"); SYSERROR("Failed to detach old root directory");
goto on_error; return -1;
} }
ret = fchdir(newroot); ret = fchdir(newroot);
if (ret < 0) { if (ret < 0) {
ret = -1;
SYSERROR("Failed to re-enter new root directory"); SYSERROR("Failed to re-enter new root directory");
goto on_error; return -1;
} }
ret = 0;
TRACE("pivot_root(\"%s\") successful", rootfs); TRACE("pivot_root(\"%s\") successful", rootfs);
on_error: return 0;
close(oldroot);
if (newroot >= 0)
close(newroot);
return ret;
} }
static int lxc_setup_rootfs_switch_root(const struct lxc_rootfs *rootfs) static int lxc_setup_rootfs_switch_root(const struct lxc_rootfs *rootfs)
......
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