Merge lp:~ted/ubuntu-app-launch/cgmanager-connection-timeout into lp:ubuntu-app-launch/rtm-14.09

Proposed by Ted Gould
Status: Merged
Approved by: Charles Kerr
Approved revision: 178
Merged at revision: 178
Proposed branch: lp:~ted/ubuntu-app-launch/cgmanager-connection-timeout
Merge into: lp:ubuntu-app-launch/rtm-14.09
Diff against target: 198 lines (+97/-22)
5 files modified
CMakeLists.txt (+1/-1)
helpers-shared.c (+93/-16)
libubuntu-app-launch/CMakeLists.txt (+1/-3)
tests/CMakeLists.txt (+1/-1)
tests/helper-test.cc (+1/-1)
To merge this branch: bzr merge lp:~ted/ubuntu-app-launch/cgmanager-connection-timeout
Reviewer Review Type Date Requested Status
Charles Kerr (community) Approve
Review via email: mp+241464@code.launchpad.net

Commit message

Attenting to connect to cgmanager for 1 second and then failing and reporting a recoverable error.

Description of the change

Make it so that we don't block on building the cgmanager connection, which might be failing because of an error in cgmanager. But instead of making all of Unity freeze, we want to handle the error and not block. We need to track it though so we can start getting an idea of how often and what conditions it's happening in.

To post a comment you must log in.
Revision history for this message
Charles Kerr (charlesk) wrote :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'CMakeLists.txt'
2--- CMakeLists.txt 2014-09-29 19:31:36 +0000
3+++ CMakeLists.txt 2014-11-11 22:11:41 +0000
4@@ -78,7 +78,7 @@
5 # Helpers
6 ####################
7
8-add_library(helpers STATIC helpers.c helpers-shared.c)
9+add_library(helpers STATIC helpers.c helpers-shared.c libubuntu-app-launch/recoverable-problem.c)
10 target_link_libraries(helpers ${GIO2_LIBRARIES} ${JSONGLIB_LIBRARIES} ${CLICK_LIBRARIES})
11
12 ####################
13
14=== modified file 'helpers-shared.c'
15--- helpers-shared.c 2014-08-11 16:41:40 +0000
16+++ helpers-shared.c 2014-11-11 22:11:41 +0000
17@@ -22,6 +22,7 @@
18 #include <cgmanager/cgmanager.h>
19
20 #include "ual-tracepoint.h"
21+#include "libubuntu-app-launch/recoverable-problem.h"
22
23 /* Check to make sure we have the sections and keys we want */
24 static gboolean
25@@ -97,34 +98,110 @@
26 return keyfile;
27 }
28
29+/* Quick way to get the pid of cgmanager to report a bug on it */
30+static GPid
31+discover_cgmanager_pid (void)
32+{
33+ gchar * outbuf = NULL;
34+ GPid outpid = 0;
35+
36+ if (g_spawn_command_line_sync("pidof cgmanager", &outbuf, NULL, NULL, NULL)) {
37+ outpid = g_ascii_strtoull(outbuf, NULL, 10);
38+ }
39+
40+ g_free(outbuf);
41+
42+ return outpid;
43+}
44+
45+/* Structure to handle data for the cgmanager connection
46+ set of callbacks */
47+typedef struct {
48+ GMainLoop * loop;
49+ GCancellable * cancel;
50+ GDBusConnection * con;
51+} cgm_connection_t;
52+
53+/* Function that gets executed when we timeout trying to connect. This
54+ is related to: LP #1377332 */
55+static gboolean
56+cgroup_manager_connection_timeout_cb (gpointer data)
57+{
58+ GPid cgmanager_pid = 0;
59+ cgm_connection_t * connection = (cgm_connection_t *)data;
60+
61+ g_cancellable_cancel(connection->cancel);
62+
63+ cgmanager_pid = discover_cgmanager_pid();
64+ if (cgmanager_pid != 0) {
65+ report_recoverable_problem("ubuntu-app-launch-cgmanager-connection-timeout", cgmanager_pid, FALSE, NULL);
66+ }
67+
68+ return G_SOURCE_CONTINUE;
69+}
70+
71+static void
72+cgroup_manager_connection_core_cb (GDBusConnection *(*finish_func)(GAsyncResult * res, GError ** error), GAsyncResult * res, cgm_connection_t * connection)
73+{
74+ GError * error = NULL;
75+
76+ connection->con = finish_func(res, &error);
77+
78+ if (error != NULL) {
79+ g_warning("Unable to get cgmanager connection: %s", error->message);
80+ g_error_free(error);
81+ }
82+
83+ g_main_loop_quit(connection->loop);
84+}
85+
86+static void
87+cgroup_manager_connection_bus_cb (GObject * obj, GAsyncResult * res, gpointer data)
88+{
89+ cgroup_manager_connection_core_cb(g_bus_get_finish, res, (cgm_connection_t *)data);
90+}
91+
92+static void
93+cgroup_manager_connection_addr_cb (GObject * obj, GAsyncResult * res, gpointer data)
94+{
95+ cgroup_manager_connection_core_cb(g_dbus_connection_new_for_address_finish, res, (cgm_connection_t *)data);
96+}
97+
98 /* Get the connection to the cgroup manager */
99 GDBusConnection *
100 cgroup_manager_connection (void)
101 {
102- GError * error = NULL;
103-
104- GDBusConnection * cgmanager = NULL;
105+ cgm_connection_t connection = {
106+ .loop = g_main_loop_new(NULL, FALSE),
107+ .con = NULL,
108+ .cancel = g_cancellable_new()
109+ };
110+ guint timeout = g_timeout_add_seconds(1, cgroup_manager_connection_timeout_cb, &connection);
111
112 if (g_getenv("UBUNTU_APP_LAUNCH_CG_MANAGER_SESSION_BUS")) {
113 /* For working dbusmock */
114 g_debug("Connecting to CG Manager on session bus");
115- cgmanager = g_bus_get_sync(G_BUS_TYPE_SESSION, NULL, &error);
116+ g_bus_get(G_BUS_TYPE_SESSION,
117+ connection.cancel,
118+ cgroup_manager_connection_bus_cb,
119+ &connection);
120 } else {
121- cgmanager = g_dbus_connection_new_for_address_sync(
122+ g_dbus_connection_new_for_address(
123 CGMANAGER_DBUS_PATH,
124 G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT,
125 NULL, /* Auth Observer */
126- NULL, /* Cancellable */
127- &error);
128- }
129-
130- if (error != NULL) {
131- g_warning("Unable to connect to cgroup manager: %s", error->message);
132- g_error_free(error);
133- return NULL;
134- }
135-
136- return cgmanager;
137+ connection.cancel, /* Cancellable */
138+ cgroup_manager_connection_addr_cb,
139+ &connection);
140+ }
141+
142+ g_main_loop_run(connection.loop);
143+
144+ g_source_remove(timeout);
145+ g_main_loop_unref(connection.loop);
146+ g_object_unref(connection.cancel);
147+
148+ return connection.con;
149 }
150
151 /* Get the PIDs for a particular cgroup */
152
153=== modified file 'libubuntu-app-launch/CMakeLists.txt'
154--- libubuntu-app-launch/CMakeLists.txt 2014-09-29 19:57:03 +0000
155+++ libubuntu-app-launch/CMakeLists.txt 2014-11-11 22:11:41 +0000
156@@ -29,9 +29,6 @@
157 click-exec.c
158 desktop-exec.c
159 ubuntu-app-launch-trace.c
160-recoverable-problem.c
161-"${CMAKE_SOURCE_DIR}/helpers-shared.c"
162-"${CMAKE_SOURCE_DIR}/helpers.c"
163 )
164
165 add_library(ubuntu-launcher SHARED ${LAUNCHER_SOURCES})
166@@ -51,6 +48,7 @@
167 ${JSONGLIB_LIBRARIES}
168 ${CLICK_LIBRARIES}
169 ${ZEITGEIST_LIBRARIES}
170+ helpers
171 -Wl,--no-undefined
172 )
173
174
175=== modified file 'tests/CMakeLists.txt'
176--- tests/CMakeLists.txt 2014-09-15 19:40:02 +0000
177+++ tests/CMakeLists.txt 2014-11-11 22:11:41 +0000
178@@ -35,7 +35,7 @@
179
180 add_executable (libual-test
181 libual-test.cc)
182-target_link_libraries (libual-test helpers gtest ${GTEST_LIBS} ${LIBUPSTART_LIBRARIES} ${DBUSTEST_LIBRARIES} ubuntu-launcher)
183+target_link_libraries (libual-test gtest ${GTEST_LIBS} ${LIBUPSTART_LIBRARIES} ${DBUSTEST_LIBRARIES} ubuntu-launcher)
184
185 add_executable (data-spew
186 data-spew.c)
187
188=== modified file 'tests/helper-test.cc'
189--- tests/helper-test.cc 2014-06-14 16:05:36 +0000
190+++ tests/helper-test.cc 2014-11-11 22:11:41 +0000
191@@ -428,7 +428,7 @@
192 g_setenv("TEST_CLICK_USER", "test-user", TRUE);
193
194 desktop = manifest_to_desktop(CMAKE_SOURCE_DIR "/click-app-dir/", "com.test.good_application_1.2.3");
195- ASSERT_STREQ(desktop, CMAKE_SOURCE_DIR "/click-app-dir/application.desktop");
196+ ASSERT_STREQ(CMAKE_SOURCE_DIR "/click-app-dir/application.desktop", desktop);
197 g_free(desktop);
198 desktop = NULL;
199

Subscribers

People subscribed via source and target branches