From 3b8ea599f02b4fbfdc190b44a23c7d782a848cc9 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Thu, 20 Feb 2020 21:08:44 -0800 Subject: [PATCH] Fix switch_root implementation --- native/jni/init/mount.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/native/jni/init/mount.cpp b/native/jni/init/mount.cpp index 82f80e89e..929c0f3ae 100644 --- a/native/jni/init/mount.cpp +++ b/native/jni/init/mount.cpp @@ -128,7 +128,7 @@ static void switch_root(const string &path) { return true; // Do not include subtrees 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; } mounts.emplace_back(me->mnt_dir); @@ -137,7 +137,7 @@ static void switch_root(const string &path) { for (auto &dir : mounts) { auto new_path = path + dir; 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()); xmount(path.data(), "/", nullptr, MS_MOVE, nullptr);