init: even better logging around subsequent sys.powerctl messages

Bug: 150863651
Test: add delays during critical parts of shutdown and see the
      expected debug information
Change-Id: Ida586903fd3eefc32ca9ee34ea2db037896ed9f4
This commit is contained in:
Tom Cherry 2020-03-27 14:31:08 -07:00
parent 22d6348845
commit 080fa98815
3 changed files with 18 additions and 9 deletions

View File

@ -235,15 +235,6 @@ static class ShutdownState {
// action queue. Instead we set this flag and ensure that shutdown happens before the next
// command is run in the main init loop.
auto lock = std::lock_guard{shutdown_command_lock_};
if (do_shutdown_) {
LOG(ERROR) << "TriggerShutdown called while a previous shutdown command '"
<< shutdown_command_ << "' has not been handled";
UnwindMainThreadStack();
}
if (IsShuttingDown()) {
LOG(ERROR) << "TriggerShutdown called while init is already shutting down";
UnwindMainThreadStack();
}
shutdown_command_ = command;
do_shutdown_ = true;
WakeMainInitThread();
@ -258,12 +249,27 @@ static class ShutdownState {
return {};
}
bool do_shutdown() const { return do_shutdown_; }
private:
std::mutex shutdown_command_lock_;
std::string shutdown_command_;
bool do_shutdown_ = false;
} shutdown_state;
void DebugRebootLogging() {
LOG(INFO) << "do_shutdown: " << shutdown_state.do_shutdown()
<< " IsShuttingDown: " << IsShuttingDown();
if (shutdown_state.do_shutdown()) {
LOG(ERROR) << "sys.powerctl set while a previous shutdown command has not been handled";
UnwindMainThreadStack();
}
if (IsShuttingDown()) {
LOG(ERROR) << "sys.powerctl set while init is already shutting down";
UnwindMainThreadStack();
}
}
void DumpState() {
ServiceList::GetInstance().DumpState();
ActionManager::GetInstance().DumpState();

View File

@ -42,6 +42,8 @@ void SendLoadPersistentPropertiesMessage();
void PropertyChanged(const std::string& name, const std::string& value);
bool QueueControlMessage(const std::string& message, const std::string& name, pid_t pid, int fd);
void DebugRebootLogging();
int SecondStageMain(int argc, char** argv);
} // namespace init

View File

@ -489,6 +489,7 @@ uint32_t HandlePropertySet(const std::string& name, const std::string& value,
}
LOG(INFO) << "Received sys.powerctl='" << value << "' from pid: " << cr.pid
<< process_log_string;
DebugRebootLogging();
}
// If a process other than init is writing a non-empty value, it means that process is