From 109932146d392da31139c43d4e34e8178bbc73b8 Mon Sep 17 00:00:00 2001 From: Kelvin Zhang Date: Mon, 13 Nov 2023 13:42:13 -0800 Subject: [PATCH] Attempt process kill even if cgroup is already removed Test: th Bug: 308900853 Change-Id: I21ae5bacf4a25cc06a1fd47e2aadbf5ae22661a7 --- init/service.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/init/service.cpp b/init/service.cpp index 311a13299..d351a8fe1 100644 --- a/init/service.cpp +++ b/init/service.cpp @@ -196,11 +196,12 @@ void Service::NotifyStateChange(const std::string& new_state) const { } void Service::KillProcessGroup(int signal) { - // If we've already seen a successful result from killProcessGroup*(), then we have removed - // the cgroup already and calling these functions a second time will simply result in an error. - // This is true regardless of which signal was sent. - // These functions handle their own logging, so no additional logging is needed. - if (!process_cgroup_empty_) { + // Always attempt the process kill if process is still running. + // Cgroup clean up routines are idempotent. It's safe to call + // killProcessGroup repeatedly. During shutdown, `init` will + // call this function to send SIGTERM/SIGKILL to all processes. + // These signals must be sent for a successful shutdown. + if (!process_cgroup_empty_ || IsRunning()) { LOG(INFO) << "Sending signal " << signal << " to service '" << name_ << "' (pid " << pid_ << ") process group..."; int r;