Implement susped, resume and cancel for the Postinstall action.
This patch sends SIGSTOP/SIGCONT to the running postinstall program to
suspend/resume the child process, and SIGKILL when cancelling it.
Bug: 27272144
TEST=Added unittest to check the signal being sent.
Change-Id: Iebe9bd34448ad1d0a5340c82e1fd839ff8c69dd2
diff --git a/common/subprocess.cc b/common/subprocess.cc
index f43aaac..61f2d54 100644
--- a/common/subprocess.cc
+++ b/common/subprocess.cc
@@ -207,7 +207,12 @@
if (pid_record == subprocess_records_.end())
return;
pid_record->second->callback.Reset();
- kill(pid, SIGTERM);
+ if (kill(pid, SIGTERM) != 0) {
+ PLOG(WARNING) << "Error sending SIGTERM to " << pid;
+ }
+ // Release the pid now so we don't try to kill it if Subprocess is destroyed
+ // before the corresponding ChildExitedCallback() is called.
+ pid_record->second->proc.Release();
}
bool Subprocess::SynchronousExec(const vector<string>& cmd,