summaryrefslogtreecommitdiff
path: root/common/subprocess_unittest.cc
diff options
context:
space:
mode:
authorBen Chan <benchan@chromium.org>2017-01-10 19:56:50 -0800
committerSen Jiang <senj@google.com>2017-05-31 15:56:02 -0700
commit70a21191b545c7c9cc3416c17b3e794c77b2e475 (patch)
tree32bbc3b2c4b5d43b32ec58082b6190d5f4fee2a5 /common/subprocess_unittest.cc
parentdc1189f7c82faead502761da70a993d914de29e0 (diff)
update_engine: clean up sleep process in SubprocessTest.CancelTest
SubprocessTest.CancelTest terminates a 'sh' process, which is put into sleep by executing `sleep 60`. Upon receiving SIGTERM, the 'sleep' process isn't reaped and thus becomes orphaned. As a remedy, this CL modifies the shell command to trap SIGTERM and kill the 'sleep' process upon receiving SIGTERM. BUG=chromium:678643 TEST=Verified that no orphaned 'sleep' process is left after running SubprocessTest.CancelTest. Reviewed-on: https://chromium-review.googlesource.com/427059 Commit-Ready: Ben Chan <benchan@chromium.org> Tested-by: Ben Chan <benchan@chromium.org> Reviewed-by: Mike Frysinger <vapier@chromium.org> (cherry picked from commit efb56850475b27ab9197c6010a3f3910b078cdc2) Change-Id: I7a94b317b524c6de81e94a1f01c29aeb9b3de85c
Diffstat (limited to 'common/subprocess_unittest.cc')
-rw-r--r--common/subprocess_unittest.cc13
1 files changed, 12 insertions, 1 deletions
diff --git a/common/subprocess_unittest.cc b/common/subprocess_unittest.cc
index 7dbdf986..cbc9a85f 100644
--- a/common/subprocess_unittest.cc
+++ b/common/subprocess_unittest.cc
@@ -236,7 +236,18 @@ TEST_F(SubprocessTest, CancelTest) {
kBinPath "/sh",
"-c",
base::StringPrintf(
- "echo -n X >\"%s\"; sleep 60; echo -n Y >\"%s\"; exit 1",
+ // The 'sleep' launched below could be left behind as an orphaned
+ // process when the 'sh' process is terminated by SIGTERM. As a
+ // remedy, trap SIGTERM and kill the 'sleep' process, which requires
+ // launching 'sleep' in background and then waiting for it.
+ "cleanup() { kill \"${sleep_pid}\"; exit 0; }; "
+ "trap cleanup TERM; "
+ "sleep 60 & "
+ "sleep_pid=$!; "
+ "printf X >\"%s\"; "
+ "wait; "
+ "printf Y >\"%s\"; "
+ "exit 1",
fifo_path.c_str(),
fifo_path.c_str())};
uint32_t tag = Subprocess::Get().Exec(cmd, base::Bind(&CallbackBad));