Merge lp:~afrantzis/unity-system-compositor/no-external-spinner-zombie-processes-sigchld-with-test into lp:unity-system-compositor

Proposed by Alexandros Frantzis
Status: Merged
Approved by: Alexandros Frantzis
Approved revision: 226
Merged at revision: 234
Proposed branch: lp:~afrantzis/unity-system-compositor/no-external-spinner-zombie-processes-sigchld-with-test
Merge into: lp:unity-system-compositor
Prerequisite: lp:~afrantzis/unity-system-compositor/fix-1473418-external-spinner-tests
Diff against target: 77 lines (+45/-0)
2 files modified
src/external_spinner.cpp (+17/-0)
tests/integration-tests/test_external_spinner.cpp (+28/-0)
To merge this branch: bzr merge lp:~afrantzis/unity-system-compositor/no-external-spinner-zombie-processes-sigchld-with-test
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Kevin DuBois (community) Approve
Review via email: mp+264418@code.launchpad.net

This proposal supersedes a proposal from 2015-07-10.

Commit message

Don't leave zombie spinner processes

Description of the change

Don't leave zombie spinner processes

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

lgtm

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/external_spinner.cpp'
2--- src/external_spinner.cpp 2015-04-01 17:06:16 +0000
3+++ src/external_spinner.cpp 2015-07-10 13:38:55 +0000
4@@ -20,6 +20,18 @@
5
6 #include <unistd.h>
7 #include <signal.h>
8+#include <sys/wait.h>
9+
10+namespace
11+{
12+
13+void wait_for_child(int)
14+{
15+ while (waitpid(-1, nullptr, WNOHANG) > 0)
16+ continue;
17+}
18+
19+}
20
21 usc::ExternalSpinner::ExternalSpinner(
22 std::string const& executable,
23@@ -28,6 +40,11 @@
24 mir_socket{mir_socket},
25 spinner_pid{0}
26 {
27+ struct sigaction sa;
28+ sigfillset(&sa.sa_mask);
29+ sa.sa_handler = wait_for_child;
30+ sa.sa_flags = 0;
31+ sigaction(SIGCHLD, &sa, nullptr);
32 }
33
34 usc::ExternalSpinner::~ExternalSpinner()
35
36=== modified file 'tests/integration-tests/test_external_spinner.cpp'
37--- tests/integration-tests/test_external_spinner.cpp 2015-07-10 13:38:55 +0000
38+++ tests/integration-tests/test_external_spinner.cpp 2015-07-10 13:38:55 +0000
39@@ -71,6 +71,16 @@
40 return pids;
41 }
42
43+bool is_zombie(pid_t pid)
44+{
45+ std::ifstream stat("/proc/" + std::to_string(pid) + "/stat");
46+
47+ std::stringstream ss;
48+ ss << stat.rdbuf();
49+
50+ return ss.str().find(" Z ") != std::string::npos;
51+}
52+
53 struct AnExternalSpinner : testing::Test
54 {
55 std::vector<pid_t> spinner_pids()
56@@ -170,3 +180,21 @@
57
58 EXPECT_THAT(environment_of_spinner(), Contains("MIR_SOCKET=" + mir_socket));
59 }
60+
61+TEST_F(AnExternalSpinner, does_not_leave_zombie_process)
62+{
63+ using namespace testing;
64+
65+ spinner.ensure_running();
66+ auto const spinner_pid = spinner_pids()[0];
67+ spinner.kill();
68+
69+ wait_for_spinner_to_terminate();
70+
71+ // Wait a bit for zombie to be reaped by parent
72+ bool const spinner_is_not_zombie = usc::test::spin_wait_for_condition_or_timeout(
73+ [spinner_pid] { return !is_zombie(spinner_pid); },
74+ timeout);
75+
76+ EXPECT_TRUE(spinner_is_not_zombie);
77+}

Subscribers

People subscribed via source and target branches