summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJooyung Han <jooyung@google.com>2022-04-22 12:05:09 +0900
committerJooyung Han <jooyung@google.com>2022-04-27 22:15:10 +0000
commit1f85546be5f58c2edcf19fa5b7efb36a6568251e (patch)
tree7dd75b4300a42d5d423d0d5dcd654defb9310dbc
parent1a2dbd917e8b2f178915cd50c39fc670f9fca6d4 (diff)
downloadcore-1f85546be5f58c2edcf19fa5b7efb36a6568251e.tar.gz
Unshare mount namespace in bootchart's thread
When bootchart is enabled its thread shares the mount namespace context with the main thread. This prevents the main thread to switch the mount namespace later with setns(). So, unshare() the mount namespace of the bootchart thread. Bug: 229983560 Test: rebooted with bootcharting on/off enter_default_mount_ns should succeeded. Change-Id: Idac0d0efcb4f7f7d8a7cbcebf8fa2fa29f104c35 Merged-In: Idac0d0efcb4f7f7d8a7cbcebf8fa2fa29f104c35 (cherry picked from commit 7f8721b9926c2cac6834ff8e4ffd7b38c3b1b3de)
-rw-r--r--init/bootchart.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/init/bootchart.cpp b/init/bootchart.cpp
index b7db9b6d6..f46fb0993 100644
--- a/init/bootchart.cpp
+++ b/init/bootchart.cpp
@@ -140,6 +140,20 @@ static void log_processes(FILE* log) {
static void bootchart_thread_main() {
LOG(INFO) << "Bootcharting started";
+ // Unshare the mount namespace of this thread so that the init process itself can switch
+ // the mount namespace later while this thread is still running.
+ // Otherwise, setns() call invoked as part of `enter_default_mount_ns` fails with EINVAL.
+ //
+ // Note that after unshare()'ing the mount namespace from the main thread, this thread won't
+ // receive mount/unmount events from the other mount namespace unless the events are happening
+ // from under a sharable mount.
+ //
+ // The bootchart thread is safe to unshare the mount namespace because it only reads from /proc
+ // and write to /data which are not private mounts.
+ if (unshare(CLONE_NEWNS) == -1) {
+ PLOG(ERROR) << "Cannot create mount namespace";
+ return;
+ }
// Open log files.
auto stat_log = fopen_unique("/data/bootchart/proc_stat.log", "we");
if (!stat_log) return;