From 84b856d90167d567238af95fceade30a0dc93d58 Mon Sep 17 00:00:00 2001 From: Tao Wu Date: Fri, 27 Oct 2017 11:29:13 -0700 Subject: [PATCH] Fix race condition between restart and stop/reset. If there is a restart follow a stop/reset immediately or vice versa, clear previous flag bits. Test: manual - trigger restart after stop immediately to check if service get started. Change-Id: I4503177d7cb5ed054dbcf50cd8e09728415404d4 --- init/service.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/init/service.cpp b/init/service.cpp index 765b61e56..864aa2ad9 100644 --- a/init/service.cpp +++ b/init/service.cpp @@ -940,6 +940,13 @@ void Service::StopOrReset(int how) { } else { flags_ |= how; } + // Make sure it's in right status when a restart immediately follow a + // stop/reset or vice versa. + if (how == SVC_RESTART) { + flags_ &= (~(SVC_DISABLED | SVC_RESET)); + } else { + flags_ &= (~SVC_RESTART); + } if (pid_) { KillProcessGroup(SIGKILL);