From 8c92256df5880072f950adc28891398dce7ffe3a Mon Sep 17 00:00:00 2001 From: Gavin Corkery Date: Mon, 11 May 2020 14:10:09 +0100 Subject: [PATCH] Store userspace reboot info in /metadata Store pertinent information about userspace reboot events in the case of failure. This information is any services which failed to stop cleanly, the output of the default fstab and /proc/mounts, and a list of mounts which failed to unmount. This information is only stored as necessary (i.e. mount information will not be stored if everything unmounted, even if some services failed to stop). Added new /metadata/userspacereboot directory to persist this information. Information older than 3 days will be deleted. Test: adb reboot userspace with sigterm/sigkill timeouts set to very low values Test: Manual test of storing all other information Bug: 151820675 Change-Id: I6cfbfae92a7fc6f6c984475cad2c50c559924866 --- init/builtins.cpp | 4 ++++ init/reboot.cpp | 18 ++++++++++++++++-- rootdir/init.rc | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/init/builtins.cpp b/init/builtins.cpp index 0ac66f272..824bd1e78 100644 --- a/init/builtins.cpp +++ b/init/builtins.cpp @@ -1177,6 +1177,10 @@ static Result do_remount_userdata(const BuiltinArguments& args) { } // TODO(b/135984674): check that fstab contains /data. if (auto rc = fs_mgr_remount_userdata_into_checkpointing(&fstab); rc < 0) { + std::string proc_mounts_output; + android::base::ReadFileToString("/proc/mounts", &proc_mounts_output, true); + android::base::WriteStringToFile(proc_mounts_output, + "/metadata/userspacereboot/mount_info.txt"); trigger_shutdown("reboot,mount_userdata_failed"); } if (auto result = queue_fs_event(initial_mount_fstab_return_code, true); !result.ok()) { diff --git a/init/reboot.cpp b/init/reboot.cpp index ffd58a38d..310a99a33 100644 --- a/init/reboot.cpp +++ b/init/reboot.cpp @@ -799,11 +799,19 @@ static Result DoUserspaceReboot() { auto sigkill_timeout = GetMillisProperty("init.userspace_reboot.sigkill.timeoutmillis", 10s); LOG(INFO) << "Timeout to terminate services: " << sigterm_timeout.count() << "ms " << "Timeout to kill services: " << sigkill_timeout.count() << "ms"; + std::string services_file_name = "/metadata/userspacereboot/services.txt"; + const int flags = O_RDWR | O_CREAT | O_SYNC | O_APPEND | O_CLOEXEC; StopServicesAndLogViolations(stop_first, sigterm_timeout, true /* SIGTERM */); if (int r = StopServicesAndLogViolations(stop_first, sigkill_timeout, false /* SIGKILL */); r > 0) { + auto fd = unique_fd(TEMP_FAILURE_RETRY(open(services_file_name.c_str(), flags, 0666))); + android::base::WriteStringToFd("Post-data services still running: \n", fd); + for (const auto& s : stop_first) { + if (s->IsRunning()) { + android::base::WriteStringToFd(s->name() + "\n", fd); + } + } sub_reason = "sigkill"; - // TODO(b/135984674): store information about offending services for debugging. return Error() << r << " post-data services are still running"; } if (auto result = KillZramBackingDevice(); !result.ok()) { @@ -817,8 +825,14 @@ static Result DoUserspaceReboot() { if (int r = StopServicesAndLogViolations(GetDebuggingServices(true /* only_post_data */), sigkill_timeout, false /* SIGKILL */); r > 0) { + auto fd = unique_fd(TEMP_FAILURE_RETRY(open(services_file_name.c_str(), flags, 0666))); + android::base::WriteStringToFd("Debugging services still running: \n", fd); + for (const auto& s : GetDebuggingServices(true)) { + if (s->IsRunning()) { + android::base::WriteStringToFd(s->name() + "\n", fd); + } + } sub_reason = "sigkill_debug"; - // TODO(b/135984674): store information about offending services for debugging. return Error() << r << " debugging services are still running"; } { diff --git a/rootdir/init.rc b/rootdir/init.rc index 427ac4b0f..d9a3dd1a7 100644 --- a/rootdir/init.rc +++ b/rootdir/init.rc @@ -511,6 +511,7 @@ on post-fs mkdir /metadata/bootstat 0750 system log mkdir /metadata/ota 0700 root system mkdir /metadata/ota/snapshots 0700 root system + mkdir /metadata/userspacereboot 0770 root system mkdir /metadata/apex 0700 root system mkdir /metadata/apex/sessions 0700 root system