From 702ca9ada2ac3c5d61bd7ae4e13a0e986a472fcb Mon Sep 17 00:00:00 2001 From: Tom Cherry Date: Fri, 25 Aug 2017 10:36:52 -0700 Subject: [PATCH] init: log all failures of Service::Start() The move to returning Result from Service::Start() for better context when starting process through init's builtins stops Service::Start() failures from being logged from other contexts. This change adds those logs along with their context. Test: boot bullhead, fail to start services via `setprop ctl.start`, see the expected error in dmesg Change-Id: I45294f6abf00852f3d4c549a32eaf4920a51e6f0 --- init/init.cpp | 8 ++++++-- init/keychords.cpp | 7 +++++-- init/reboot.cpp | 11 +++++++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/init/init.cpp b/init/init.cpp index e1bd3a2cb..4a8459f1d 100644 --- a/init/init.cpp +++ b/init/init.cpp @@ -177,7 +177,9 @@ static std::optional RestartProcesses() { auto restart_time = s->time_started() + 5s; if (boot_clock::now() > restart_time) { - s->Start(); + if (auto result = s->Start(); !result) { + LOG(ERROR) << "Could not restart process '" << s->name() << "': " << result.error(); + } } else { if (!next_process_restart_time || restart_time < *next_process_restart_time) { next_process_restart_time = restart_time; @@ -195,7 +197,9 @@ void handle_control_message(const std::string& msg, const std::string& name) { } if (msg == "start") { - svc->Start(); + if (auto result = svc->Start(); !result) { + LOG(ERROR) << "Could not ctl.start service '" << name << "': " << result.error(); + } } else if (msg == "stop") { svc->Stop(); } else if (msg == "restart") { diff --git a/init/keychords.cpp b/init/keychords.cpp index 2ef0ce776..e686ce1e4 100644 --- a/init/keychords.cpp +++ b/init/keychords.cpp @@ -81,8 +81,11 @@ static void handle_keychord() { if (adb_enabled == "running") { Service* svc = ServiceList::GetInstance().FindService(id, &Service::keychord_id); if (svc) { - LOG(INFO) << "Starting service " << svc->name() << " from keychord " << id; - svc->Start(); + LOG(INFO) << "Starting service '" << svc->name() << "' from keychord " << id; + if (auto result = svc->Start(); !result) { + LOG(ERROR) << "Could not start service '" << svc->name() << "' from keychord " << id + << ": " << result.error(); + } } else { LOG(ERROR) << "Service for keychord " << id << " not found"; } diff --git a/init/reboot.cpp b/init/reboot.cpp index 5bae4bcfe..1f83582fe 100644 --- a/init/reboot.cpp +++ b/init/reboot.cpp @@ -378,10 +378,17 @@ void DoReboot(unsigned int cmd, const std::string& reason, const std::string& re if (kill_after_apps.count(s->name())) { s->SetShutdownCritical(); } else if (to_starts.count(s->name())) { - s->Start(); + if (auto result = s->Start(); !result) { + LOG(ERROR) << "Could not start shutdown 'to_start' service '" << s->name() + << "': " << result.error(); + } s->SetShutdownCritical(); } else if (s->IsShutdownCritical()) { - s->Start(); // start shutdown critical service if not started + // Start shutdown critical service if not started. + if (auto result = s->Start(); !result) { + LOG(ERROR) << "Could not start shutdown critical service '" << s->name() + << "': " << result.error(); + } } }