Unshare mount namespace in bootchart's thread am: 1f85546be5

Original change: https://googleplex-android-review.googlesource.com/c/platform/system/core/+/17994482

Change-Id: I343cddbb8c78b44600e611c73fcb98afc0d0e093
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Jooyung Han 2022-04-28 00:51:44 +00:00 committed by Automerger Merge Worker
commit ad56552398

View file

@ -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;