Merge lp:~ted/ubuntu-app-launch/cgrouped-applications into lp:ubuntu-app-launch/14.10

Proposed by Ted Gould
Status: Merged
Approved by: Charles Kerr
Approved revision: 197
Merged at revision: 159
Proposed branch: lp:~ted/ubuntu-app-launch/cgrouped-applications
Merge into: lp:ubuntu-app-launch/14.10
Prerequisite: lp:~ted/ubuntu-app-launch/proper-job-test
Diff against target: 58 lines (+18/-1)
3 files modified
cgroup-reap-all.c (+4/-1)
tests/cgroup-reap-test.cc (+3/-0)
tests/manual (+11/-0)
To merge this branch: bzr merge lp:~ted/ubuntu-app-launch/cgrouped-applications
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+231574@code.launchpad.net

This proposal supersedes a proposal from 2014-08-14.

Commit message

CGroup test and clarification comments

Description of the change

Forgot to rebuild after adding these cleanup revisions, so CI Train didn't merge them.

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: Needs Fixing (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

According to the click-here-to-rebuild ubuntu-cui link, there've been two subsequent builds of this that were both successful, on 2014-08-20 and 2014-08-26, so I'm going to review this as if Jenkins is already happy :-)

Apologies for not inlining the comments...

In cgroup-reap-all.c, it makes more sense to call getpid() and getppid() once each before entering the while() loop, rather than calling them forever.

In cgroup-reap-all.c, it looks to me like maybe pids_from_cgroup() only returns NULL if something went wrong in the DBus call? If that reading is correct, maybe a g_critical() would be appropriate if NULL is returned?

In helpers-shared.c's cgroup_manager_connection()... couldn't we add g_setenv("DBUS_SESSION_BUS_ADDRESS", CGMANAGER_DBUS_PATH) to the test code instead of adding "if (g_getenv("UBUNTU_APP_LAUNCH_CG_MANAGER_SESSION_BUS"))" to the production code?

In helpers-shared.c's pids_from_cgroup()'s g_debug() call, need to use 'groupname ? groupname : ""'

In application-click.conf.in, I don't understand the cahnge to post-start.

In ubuntu-app-launch.c's ubuntu_app_launch_pid_in_app_id()... wow, that implementation gained a lot of scope :)

review: Approve
Revision history for this message
Charles Kerr (charlesk) wrote :

That should be "Comment only", rather than "Approve" ... meh.

Revision history for this message
Ted Gould (ted) wrote :

On Tue, 2014-08-26 at 19:40 +0000, Charles Kerr wrote:

> In cgroup-reap-all.c, it makes more sense to call getpid() and
> getppid() once each before entering the while() loop, rather than
> calling them forever.

Fixed, r197

> In cgroup-reap-all.c, it looks to me like maybe pids_from_cgroup()
> only returns NULL if something went wrong in the DBus call? If that
> reading is correct, maybe a g_critical() would be appropriate if NULL
> is returned?

I'm thinking no. In reality the reaper's pid should always be in the
list, but that's not explicitly defined behavior in Upstart, so if they
moves the post-stop job out of the cgroup it wouldn't be in the list.
(which would make sense to me actually, but eh, it is how it is)

> In helpers-shared.c's cgroup_manager_connection()... couldn't we add
> g_setenv("DBUS_SESSION_BUS_ADDRESS", CGMANAGER_DBUS_PATH) to the test
> code instead of adding "if
> (g_getenv("UBUNTU_APP_LAUNCH_CG_MANAGER_SESSION_BUS"))" to the
> production code?

Unfortunately we can't because the connection to the cgroup manager
isn't a bus connection, so it needs different auth. So we have to build
the connection slightly differently in the two cases.

> In helpers-shared.c's pids_from_cgroup()'s g_debug() call, need to use
> 'groupname ? groupname : ""'

g_debug() can handle null in that case and will print "(null)" for the
value.

> In application-click.conf.in, I don't understand the cahnge to
> post-start.

What we used to do was send kill to everyone in the pgroup for the main
process. It was a hack to handle the fact that we didn't have cgroup
support. We're now adding cgroup support and removing the hack. To the
reaper replaces the kill.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Makes sense. Thanks for the explanation wrt application-click.conf.in

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'cgroup-reap-all.c'
2--- cgroup-reap-all.c 2014-08-08 03:58:38 +0000
3+++ cgroup-reap-all.c 2014-08-26 20:00:00 +0000
4@@ -31,6 +31,9 @@
5 GDBusConnection * cgmanager = cgroup_manager_connection();
6 g_return_val_if_fail(cgmanager != NULL, -1);
7
8+ GPid selfpid = getpid();
9+ GPid parentpid = getppid();
10+
11 /* We're gonna try to kill things forever, literally. It's important
12 enough that we can't consider failure an option. */
13 gboolean killed = TRUE;
14@@ -46,7 +49,7 @@
15 /* We don't want to kill ourselves, or if we're being executed by
16 a script, that script, either. We also don't want things in our
17 process group which we forked at the opening */
18- if (pid != getpid() && pid != getppid() && getpgid(pid) != getpid()) {
19+ if (pid != selfpid && pid != parentpid && getpgid(pid) != selfpid) {
20 g_debug("Killing pid: %d", pid);
21 kill(pid, SIGKILL);
22 killed = TRUE;
23
24=== modified file 'tests/cgroup-reap-test.cc'
25--- tests/cgroup-reap-test.cc 2014-08-08 03:10:26 +0000
26+++ tests/cgroup-reap-test.cc 2014-08-26 20:00:00 +0000
27@@ -47,6 +47,9 @@
28 g_setenv("UBUNTU_APP_LAUNCH_CG_MANAGER_NAME", "org.test.cgmock", TRUE);
29
30 DbusTestDbusMockObject * cgobject = dbus_test_dbus_mock_get_object(cgmock, "/org/linuxcontainers/cgmanager", "org.linuxcontainers.cgmanager0_0", NULL);
31+ /* This Python code executes in dbusmock and checks to see if the sleeping
32+ process is running. If it is, it returns its PID in the list of PIDs, if
33+ not it doesn't return any PIDs. */
34 gchar * pythoncode = g_strdup_printf(
35 "if os.spawnlp(os.P_WAIT, 'ps', 'ps', '%d') == 0 :\n"
36 " ret = [ %d ]\n"
37
38=== modified file 'tests/manual'
39--- tests/manual 2014-08-26 20:00:00 +0000
40+++ tests/manual 2014-08-26 20:00:00 +0000
41@@ -50,6 +50,17 @@
42 <dd>Ensure that all applications start and stop correctly</dd>
43 </dl>
44
45+Test-case ubuntu-app-launch/cgroup-containment
46+<dl>
47+ <dt>Install the Terminal app if not already installed</dt>
48+ <dd>It can be found in the Application Store if not currently installed</dd>
49+ <dt>Launch the Terminal app</dt>
50+ <dd>A new application should open with a terminal prompt where you can type commands</dd>
51+ <dt>Ensure the Terminal is in a terminal specific cgroup</dt>
52+ <dd>Type the command <tt>cat /proc/self/cgroup</tt></dd>
53+ <dd>Under the "freeze" cgroup the end of the path should include the AppID of the terminal. An example would be (the version many change): <tt>4:freezer:/user.slice/user-32011.slice/session-c2.scope/upstart/application-click-com.ubuntu.terminal_terminal_0.5.106</tt></dd>
54+</dl>
55+
56 Test-case ubuntu-app-launch/correct-job-type
57 <dl>
58 <dt>Launch the settings application: <tt>ubuntu-app-launch ubuntu-system-settings</tt></dt>

Subscribers

People subscribed via source and target branches