Merge lp:~afrantzis/powerd/fix-1531158 into lp:powerd

Proposed by Alexandros Frantzis
Status: Merged
Approved by: Alexandros Frantzis
Approved revision: 181
Merged at revision: 181
Proposed branch: lp:~afrantzis/powerd/fix-1531158
Merge into: lp:powerd
Diff against target: 110 lines (+40/-22)
2 files modified
debian/changelog (+8/-0)
src/display.c (+32/-22)
To merge this branch: bzr merge lp:~afrantzis/powerd/fix-1531158
Reviewer Review Type Date Requested Status
PS Jenkins bot continuous-integration Approve
Ubuntu Phablet Team Pending
Review via email: mp+282169@code.launchpad.net

Commit message

Keep the dbus proxy to Unity.Screen (implemented by USC) alive for
the lifetime of the process. Otherwise we may block when trying to
create the proxy while servicing a request from USC (LP: #1531158)

Description of the change

Keep the dbus proxy to Unity.Screen (implemented by USC) alive for
the lifetime of the process. Otherwise we may block when trying to
create the proxy while servicing a request from USC (LP: #1531158)

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/changelog'
2--- debian/changelog 2015-09-30 12:29:39 +0000
3+++ debian/changelog 2016-01-11 13:36:27 +0000
4@@ -1,3 +1,11 @@
5+powerd (0.16+16.04.20160111-0ubuntu1) xenial; urgency=medium
6+
7+ * Keep the dbus proxy to Unity.Screen (implemented by USC) alive for
8+ the lifetime of the process. Otherwise we may block when trying to
9+ create the proxy while servicing a request from USC (LP: #1531158)
10+
11+ -- Alexandros Frantzis <alexandros.frantzis@canonical.com> Mon, 11 Jan 2016 13:12:11 +0000
12+
13 powerd (0.16+15.10.20150930-0ubuntu1) wily; urgency=medium
14
15 [ Alexandros Frantzis ]
16
17=== modified file 'src/display.c'
18--- src/display.c 2014-06-18 18:06:10 +0000
19+++ src/display.c 2016-01-11 13:36:27 +0000
20@@ -29,26 +29,39 @@
21 #include "powerd-internal.h"
22 #include "log.h"
23
24-static GDBusProxy* create_uscreen_proxy()
25+static GDBusProxy* uscreen_proxy_get()
26 {
27- GError *error = NULL;
28- GDBusProxy *uscreen_proxy = NULL;
29- uscreen_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
30- G_DBUS_PROXY_FLAGS_NONE,
31- NULL,
32- "com.canonical.Unity.Screen",
33- "/com/canonical/Unity/Screen",
34- "com.canonical.Unity.Screen",
35- NULL,
36- &error);
37-
38- if (error != NULL) {
39- powerd_warn("could not connect to Unity.Screen: %s", error->message);
40- g_error_free(error);
41- return NULL;
42+ static GMutex mutex;
43+ static GDBusProxy *uscreen_proxy = NULL;
44+ GDBusProxy *uscreen_proxy_tmp = NULL;
45+
46+ g_mutex_lock(&mutex);
47+
48+ if (uscreen_proxy == NULL)
49+ {
50+ GError *error = NULL;
51+
52+ uscreen_proxy = g_dbus_proxy_new_for_bus_sync(G_BUS_TYPE_SYSTEM,
53+ G_DBUS_PROXY_FLAGS_NONE,
54+ NULL,
55+ "com.canonical.Unity.Screen",
56+ "/com/canonical/Unity/Screen",
57+ "com.canonical.Unity.Screen",
58+ NULL,
59+ &error);
60+
61+ if (error != NULL) {
62+ powerd_warn("could not connect to Unity.Screen: %s", error->message);
63+ g_error_free(error);
64+ uscreen_proxy = NULL;
65+ }
66 }
67
68- return uscreen_proxy;
69+ uscreen_proxy_tmp = uscreen_proxy;
70+
71+ g_mutex_unlock(&mutex);
72+
73+ return uscreen_proxy_tmp;
74 }
75
76 static void request_keep_display_on(GDBusConnection *connection,
77@@ -63,7 +76,7 @@
78
79 powerd_debug("request_keep_display_on");
80
81- uscreen_proxy = create_uscreen_proxy();
82+ uscreen_proxy = uscreen_proxy_get();
83 if (uscreen_proxy == NULL)
84 {
85 powerd_warn("failed creating unity screen proxy to keep display on");
86@@ -88,7 +101,6 @@
87 powerd_debug("keepDisplayOn request succeeded - id: %d", request_id);
88
89 g_variant_unref(ret);
90- g_object_unref(uscreen_proxy);
91 }
92
93 gboolean turn_display_on(gboolean on, enum DisplayStateChangeReason reason)
94@@ -100,7 +112,7 @@
95 if (on)
96 powerd_hal_signal_activity();
97
98- uscreen_proxy = create_uscreen_proxy();
99+ uscreen_proxy = uscreen_proxy_get();
100 if (uscreen_proxy == NULL)
101 return FALSE;
102
103@@ -113,8 +125,6 @@
104 NULL,
105 NULL);
106
107- g_object_unref(uscreen_proxy);
108-
109 return TRUE;
110 }
111

Subscribers

People subscribed via source and target branches