From fc97d2a1168c9764584cd01424433ee6742f15f9 Mon Sep 17 00:00:00 2001 From: Jiyong Park Date: Thu, 28 Feb 2019 15:16:23 +0900 Subject: [PATCH] Revert "Handle adb sync with Bionic under /bionic" This reverts commit 7c7189c46948761cc668c9362d0b5aefb4004c70. Bug: 125549215 Test: system/core/fs_mgr/tests/adb-remount-test.sh Change-Id: I4ee40cda9c3b94b116dc822c7b9736cfe2c9c9f0 --- adb/daemon/file_sync_service.cpp | 86 -------------------------------- 1 file changed, 86 deletions(-) diff --git a/adb/daemon/file_sync_service.cpp b/adb/daemon/file_sync_service.cpp index 70deb31fd..29bd798d4 100644 --- a/adb/daemon/file_sync_service.cpp +++ b/adb/daemon/file_sync_service.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include #include #include @@ -211,22 +210,6 @@ done: return WriteFdExactly(s, &msg.dent, sizeof(msg.dent)); } -static bool is_mountpoint(const std::string& path, pid_t tid) { - const std::string mountinfo_path = "/proc/" + std::to_string(tid) + "/mountinfo"; - std::string mountinfo; - if (!android::base::ReadFileToString(mountinfo_path, &mountinfo)) { - PLOG(ERROR) << "Failed to open " << mountinfo_path; - return false; - } - std::vector lines = android::base::Split(mountinfo, "\n"); - return std::find_if(lines.begin(), lines.end(), [&path](const auto& line) { - auto tokens = android::base::Split(line, " "); - // line format is ... - // mountid parentmountid major:minor sourcepath targetpath option ... - return tokens.size() >= 4 && tokens[4] == path; - }) != lines.end(); -} - // Make sure that SendFail from adb_io.cpp isn't accidentally used in this file. #pragma GCC poison SendFail @@ -432,18 +415,6 @@ static bool do_send(int s, const std::string& spec, std::vector& buffer) { struct stat st; bool do_unlink = (lstat(path.c_str(), &st) == -1) || S_ISREG(st.st_mode) || (S_ISLNK(st.st_mode) && !S_ISLNK(mode)); - - // If the path is a file that is a mount point, don't unlink it, but instead - // truncate to zero. If unlinked, existing mounts on the path is all - // unmounted - if (S_ISREG(st.st_mode) && is_mountpoint(path, getpid())) { - do_unlink = false; - if (truncate(path.c_str(), 0) == -1) { - SendSyncFail(s, "truncate to zero failed"); - return false; - } - } - if (do_unlink) { adb_unlink(path.c_str()); } @@ -591,64 +562,7 @@ static bool handle_sync_command(int fd, std::vector& buffer) { return true; } -#if defined(__ANDROID__) -class FileSyncPreparer { - public: - FileSyncPreparer() : saved_ns_fd_(-1), rooted_(getuid() == 0) { - const std::string namespace_path = "/proc/" + std::to_string(gettid()) + "/ns/mnt"; - const int ns_fd = adb_open(namespace_path.c_str(), O_RDONLY | O_CLOEXEC); - if (ns_fd == -1) { - if (rooted_) PLOG(ERROR) << "Failed to save mount namespace"; - return; - } - saved_ns_fd_.reset(ns_fd); - - // Note: this is for the current thread only - if (unshare(CLONE_NEWNS) != 0) { - if (rooted_) PLOG(ERROR) << "Failed to clone mount namespace"; - return; - } - - // Set the propagation type of / to private so that unmount below is - // not propagated to other mount namespaces. - if (mount(nullptr, "/", nullptr, MS_PRIVATE | MS_REC, nullptr) == -1) { - if (rooted_) PLOG(ERROR) << "Could not change propagation type of / to MS_PRIVATE"; - return; - } - - // unmount /bionic which is bind-mount to itself by init. Under /bionic, - // there are other bind mounts for the bionic files. By unmounting this, - // we unmount them all thus revealing the raw file system that is the - // same as the local file system seen by the adb client. - if (umount2("/bionic", MNT_DETACH) == -1 && errno != ENOENT) { - if (rooted_) PLOG(ERROR) << "Could not unmount /bionic to reveal raw filesystem"; - return; - } - } - - ~FileSyncPreparer() { - if (saved_ns_fd_.get() != -1) { - // In fact, this is not strictly required because this thread for file - // sync service will be destroyed after the current transfer is all - // done. However, let's restore the ns in case the same thread is - // reused by multiple transfers in the future refactoring. - if (setns(saved_ns_fd_, CLONE_NEWNS) == -1) { - PLOG(ERROR) << "Failed to restore saved mount namespace"; - } - } - } - - private: - unique_fd saved_ns_fd_; - bool rooted_; -}; -#endif - void file_sync_service(unique_fd fd) { -#if defined(__ANDROID__) - FileSyncPreparer preparer; -#endif - std::vector buffer(SYNC_DATA_MAX); while (handle_sync_command(fd.get(), buffer)) {