Merge lp:~3v1n0/unity/cancellable-gnome-session-manager into lp:unity

Proposed by Marco Trevisan (Treviño)
Status: Merged
Approved by: Marco Trevisan (Treviño)
Approved revision: no longer in the source branch.
Merged at revision: 4219
Proposed branch: lp:~3v1n0/unity/cancellable-gnome-session-manager
Merge into: lp:unity
Diff against target: 189 lines (+24/-20)
5 files modified
UnityCore/GLibDBusProxy.cpp (+12/-8)
UnityCore/GLibDBusProxy.h (+2/-2)
UnityCore/GnomeSessionManager.cpp (+9/-9)
UnityCore/GnomeSessionManagerImpl.h (+1/-0)
unity-shared/SystemdWrapper.cpp (+0/-1)
To merge this branch: bzr merge lp:~3v1n0/unity/cancellable-gnome-session-manager
Reviewer Review Type Date Requested Status
Eleni Maria Stea (community) Approve
Review via email: mp+314925@code.launchpad.net

Commit message

GnomeSessionManager: add gcancellable to instance and use it for calls with temporary proxies

This fixes various crashes when the session manager is destroyed while a temporary proxy
call is still in progress, and the callback is called afterwards.

To post a comment you must log in.
Revision history for this message
Eleni Maria Stea (hikiko) wrote :

+1 :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'UnityCore/GLibDBusProxy.cpp'
2--- UnityCore/GLibDBusProxy.cpp 2015-11-24 16:40:03 +0000
3+++ UnityCore/GLibDBusProxy.cpp 2017-01-17 15:51:00 +0000
4@@ -609,7 +609,7 @@
5 return nullptr;
6 }
7
8-void DBusProxy::GetProperty(std::string const& name, ReplyCallback const& callback)
9+void DBusProxy::GetProperty(std::string const& name, ReplyCallback const& callback, GCancellable *cancellable)
10 {
11 if (!callback)
12 return;
13@@ -620,7 +620,8 @@
14 pimpl->name_.c_str(), pimpl->object_path_.c_str(),
15 "org.freedesktop.DBus.Properties",
16 "Get", g_variant_new ("(ss)", pimpl->interface_name_.c_str(), name.c_str()),
17- G_VARIANT_TYPE("(v)"), G_DBUS_CALL_FLAGS_NONE, -1, pimpl->cancellable_,
18+ G_VARIANT_TYPE("(v)"), G_DBUS_CALL_FLAGS_NONE, -1,
19+ cancellable ? cancellable : pimpl->cancellable_,
20 [] (GObject *source, GAsyncResult *res, gpointer user_data) {
21 glib::Error err;
22 std::unique_ptr<ReplyCallback> callback(static_cast<ReplyCallback*>(user_data));
23@@ -641,15 +642,16 @@
24 else
25 {
26 // This will get the property as soon as we have a connection
27+ glib::Object<GCancellable> canc(cancellable, AddRef());
28 auto conn = std::make_shared<sigc::connection>();
29- *conn = connected.connect([this, conn, name, callback] {
30- GetProperty(name, callback);
31+ *conn = connected.connect([this, conn, name, callback, canc] {
32+ GetProperty(name, callback, canc);
33 conn->disconnect();
34 });
35 }
36 }
37
38-void DBusProxy::SetProperty(std::string const& name, GVariant* value)
39+void DBusProxy::SetProperty(std::string const& name, GVariant* value, GCancellable *cancellable)
40 {
41 if (IsConnected())
42 {
43@@ -657,7 +659,8 @@
44 pimpl->name_.c_str(), pimpl->object_path_.c_str(),
45 "org.freedesktop.DBus.Properties",
46 "Set", g_variant_new ("(ssv)", pimpl->interface_name_.c_str(), name.c_str(), value),
47- nullptr, G_DBUS_CALL_FLAGS_NONE, -1, pimpl->cancellable_,
48+ nullptr, G_DBUS_CALL_FLAGS_NONE, -1,
49+ cancellable ? cancellable : pimpl->cancellable_,
50 [] (GObject *source, GAsyncResult *res, gpointer user_data) {
51 glib::Error err;
52 Variant result(g_dbus_connection_call_finish(G_DBUS_CONNECTION(source), res, &err), StealRef());
53@@ -670,9 +673,10 @@
54 else
55 {
56 // This will set the property as soon as we have a connection
57+ glib::Object<GCancellable> canc(cancellable, AddRef());
58 auto conn = std::make_shared<sigc::connection>();
59- *conn = connected.connect([this, conn, name, value] {
60- SetProperty(name, value);
61+ *conn = connected.connect([this, conn, name, value, canc] {
62+ SetProperty(name, value, canc);
63 conn->disconnect();
64 });
65 }
66
67=== modified file 'UnityCore/GLibDBusProxy.h'
68--- UnityCore/GLibDBusProxy.h 2014-10-10 11:35:40 +0000
69+++ UnityCore/GLibDBusProxy.h 2017-01-17 15:51:00 +0000
70@@ -74,8 +74,8 @@
71 bool IsConnected() const;
72
73 Variant GetProperty(std::string const& property_name) const;
74- void GetProperty(std::string const& property_name, ReplyCallback const&);
75- void SetProperty(std::string const& property_name, GVariant* value);
76+ void GetProperty(std::string const& property_name, ReplyCallback const&, GCancellable *cancellable = nullptr);
77+ void SetProperty(std::string const& property_name, GVariant* value, GCancellable *cancellable = nullptr);
78
79 void Connect(std::string const& signal_name, ReplyCallback const& callback);
80 void DisconnectSignal(std::string const& signal_name = "");
81
82=== modified file 'UnityCore/GnomeSessionManager.cpp'
83--- UnityCore/GnomeSessionManager.cpp 2017-01-04 17:38:14 +0000
84+++ UnityCore/GnomeSessionManager.cpp 2017-01-17 15:51:00 +0000
85@@ -130,7 +130,7 @@
86
87 glib::Variant tmp(g_variant_get_child_value(variant, 1), glib::StealRef());
88 SetupLogin1Proxy(tmp.GetObjectPath());
89- });
90+ }, cancellable_);
91 }
92 }
93
94@@ -424,7 +424,7 @@
95
96 if (cb)
97 cb(ret, e);
98- });
99+ }, cancellable_);
100 }
101
102 void GnomeManager::Impl::CallUPowerMethod(std::string const& method, glib::DBusProxy::ReplyCallback const& cb)
103@@ -443,7 +443,7 @@
104 {
105 cb(ret);
106 }
107- });
108+ }, cancellable_);
109 }
110
111 void GnomeManager::Impl::CallLogindMethod(std::string const& method, GVariant* parameters, glib::DBusProxy::CallFinishedCallback const& cb)
112@@ -465,7 +465,7 @@
113 {
114 cb(ret, e);
115 }
116- });
117+ }, cancellable_);
118 }
119
120 void GnomeManager::Impl::CallConsoleKitMethod(std::string const& method, GVariant* parameters)
121@@ -482,7 +482,7 @@
122 {
123 LOG_ERROR(logger) << "Fallback call failed: " << e.Message();
124 }
125- });
126+ }, cancellable_);
127 }
128
129 void GnomeManager::Impl::CallDisplayManagerSeatMethod(std::string const& method, GVariant* parameters)
130@@ -499,7 +499,7 @@
131 {
132 LOG_ERROR(logger) << "DisplayManager Seat call failed: " << e.Message();
133 }
134- });
135+ }, cancellable_);
136 }
137
138 void GnomeManager::Impl::LockScreen(bool prompt)
139@@ -552,7 +552,7 @@
140 glib::Variant inhibitors(g_dbus_connection_call_sync(bus, test_mode_ ? testing::DBUS_NAME.c_str() : "org.gnome.SessionManager",
141 "/org/gnome/SessionManager", "org.gnome.SessionManager",
142 "IsInhibited", g_variant_new("(u)", Inhibited::LOGOUT), nullptr,
143- G_DBUS_CALL_FLAGS_NONE, 500, nullptr, &error));
144+ G_DBUS_CALL_FLAGS_NONE, 500, cancellable_, &error));
145
146 if (error)
147 {
148@@ -600,7 +600,7 @@
149 glib::Variant user_path(g_dbus_connection_call_sync(bus, "org.freedesktop.Accounts",
150 "/org/freedesktop/Accounts", "org.freedesktop.Accounts",
151 "FindUserByName", g_variant_new("(s)",g_get_user_name()), nullptr,
152- G_DBUS_CALL_FLAGS_NONE, 500, nullptr, &error));
153+ G_DBUS_CALL_FLAGS_NONE, 500, cancellable_, &error));
154
155 if (error)
156 {
157@@ -611,7 +611,7 @@
158 glib::Variant autologin(g_dbus_connection_call_sync(bus, "org.freedesktop.Accounts",
159 user_path.GetObjectPath().c_str(), "org.freedesktop.DBus.Properties",
160 "Get", g_variant_new("(ss)", "org.freedesktop.Accounts.User", "AutomaticLogin"), nullptr,
161- G_DBUS_CALL_FLAGS_NONE, 500, nullptr, &error));
162+ G_DBUS_CALL_FLAGS_NONE, 500, cancellable_, &error));
163
164 if (error)
165 {
166
167=== modified file 'UnityCore/GnomeSessionManagerImpl.h'
168--- UnityCore/GnomeSessionManagerImpl.h 2017-01-04 15:46:47 +0000
169+++ UnityCore/GnomeSessionManagerImpl.h 2017-01-17 15:51:00 +0000
170@@ -85,6 +85,7 @@
171 glib::DBusProxy::Ptr dm_proxy_;
172 glib::DBusProxy::Ptr dm_seat_proxy_;
173
174+ glib::Cancellable cancellable_;
175 int open_sessions_;
176 };
177
178
179=== modified file 'unity-shared/SystemdWrapper.cpp'
180--- unity-shared/SystemdWrapper.cpp 2016-09-01 23:50:10 +0000
181+++ unity-shared/SystemdWrapper.cpp 2017-01-17 15:51:00 +0000
182@@ -39,7 +39,6 @@
183
184 private:
185 bool test_mode_;
186- glib::DBusProxy::Ptr systemd_proxy_;
187 };
188
189 SystemdWrapper::Impl::Impl(bool test)