Commit 3b8ea599 authored by topjohnwu's avatar topjohnwu

Fix switch_root implementation

parent 3e70a61e
...@@ -128,7 +128,7 @@ static void switch_root(const string &path) { ...@@ -128,7 +128,7 @@ static void switch_root(const string &path) {
return true; return true;
// Do not include subtrees // Do not include subtrees
for (const auto &m : mounts) { for (const auto &m : mounts) {
if (strncmp(me->mnt_dir, m.data(), m.length()) == 0) if (strncmp(me->mnt_dir, m.data(), m.length()) == 0 && me->mnt_dir[m.length()] == '/')
return true; return true;
} }
mounts.emplace_back(me->mnt_dir); mounts.emplace_back(me->mnt_dir);
...@@ -137,7 +137,7 @@ static void switch_root(const string &path) { ...@@ -137,7 +137,7 @@ static void switch_root(const string &path) {
for (auto &dir : mounts) { for (auto &dir : mounts) {
auto new_path = path + dir; auto new_path = path + dir;
mkdir(new_path.data(), 0755); mkdir(new_path.data(), 0755);
xmount(dir.data(), new_path.c_str(), nullptr, MS_MOVE, nullptr); xmount(dir.data(), new_path.data(), nullptr, MS_MOVE, nullptr);
} }
chdir(path.data()); chdir(path.data());
xmount(path.data(), "/", nullptr, MS_MOVE, nullptr); xmount(path.data(), "/", nullptr, MS_MOVE, nullptr);
......
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