Magellan Linux

Contents of /trunk/xorg-server/patches/xorg-server-1.17.1-systemd-logind-dont-second-guess-dbus-default-tim.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2576 - (show annotations) (download)
Mon Jun 15 13:02:17 2015 UTC (8 years, 11 months ago) by niro
File size: 14773 byte(s)
-fixed garbage patches
1 From 89250c82a01062775f8f840737a757125138fbce Mon Sep 17 00:00:00 2001
2 From: Ray Strode <rstrode@redhat.com>
3 Date: Fri, 10 Apr 2015 14:19:50 -0400
4 Subject: [PATCH] systemd-logind: don't second guess D-Bus default timeout
5
6 At the moment, the X server uses a non-default timeout for D-Bus
7 messages to systemd-logind. The only timeouts normally used with
8 D-Bus are:
9
10 1) Infinite
11 2) Default
12
13 Anything else is just as arbitrary as Default, and so rarely makes
14 sense to use instead of Default.
15
16 Put another way, there's little reason to be fault tolerant against
17 a local root running daemon (logind), that in some configurations, the
18 X server already depends on for proper functionality.
19
20 This commit changes systemd-logind to just use the default timeouts.
21
22 https://bugzilla.redhat.com/show_bug.cgi?id=1209347
23 ---
24 hw/xfree86/os-support/linux/systemd-logind.c | 14 ++++++--------
25 1 file changed, 6 insertions(+), 8 deletions(-)
26
27 diff --git a/hw/xfree86/os-support/linux/systemd-logind.c b/hw/xfree86/os-support/linux/systemd-logind.c
28 index 57c87c0..4ad41a3 100644
29 --- a/hw/xfree86/os-support/linux/systemd-logind.c
30 +++ b/hw/xfree86/os-support/linux/systemd-logind.c
31 @@ -13,62 +13,60 @@
32 * Software.
33 *
34 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
36 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
37 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
38 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
39 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
40 * DEALINGS IN THE SOFTWARE.
41 *
42 * Author: Hans de Goede <hdegoede@redhat.com>
43 */
44
45 #ifdef HAVE_XORG_CONFIG_H
46 #include <xorg-config.h>
47 #endif
48
49 #include <dbus/dbus.h>
50 #include <string.h>
51 #include <sys/types.h>
52 #include <unistd.h>
53
54 #include "os.h"
55 #include "dbus-core.h"
56 #include "xf86.h"
57 #include "xf86platformBus.h"
58 #include "xf86Xinput.h"
59
60 #include "systemd-logind.h"
61
62 -#define DBUS_TIMEOUT 500 /* Wait max 0.5 seconds */
63 -
64 struct systemd_logind_info {
65 DBusConnection *conn;
66 char *session;
67 Bool active;
68 Bool vt_active;
69 };
70
71 static struct systemd_logind_info logind_info;
72
73 static InputInfoPtr
74 systemd_logind_find_info_ptr_by_devnum(InputInfoPtr start,
75 int major, int minor)
76 {
77 InputInfoPtr pInfo;
78
79 for (pInfo = start; pInfo; pInfo = pInfo->next)
80 if (pInfo->major == major && pInfo->minor == minor &&
81 (pInfo->flags & XI86_SERVER_FD))
82 return pInfo;
83
84 return NULL;
85 }
86
87 static void
88 systemd_logind_set_input_fd_for_all_devs(int major, int minor, int fd,
89 Bool enable)
90 {
91 InputInfoPtr pInfo;
92
93 pInfo = systemd_logind_find_info_ptr_by_devnum(xf86InputDevs, major, minor);
94 @@ -103,61 +101,61 @@ systemd_logind_take_fd(int _major, int _minor, const char *path,
95 if (strstr(path, "mouse"))
96 return -1;
97
98 /* Check if we already have an InputInfo entry with this major, minor
99 * (shared device-nodes happen ie with Wacom tablets). */
100 pInfo = systemd_logind_find_info_ptr_by_devnum(xf86InputDevs, major, minor);
101 if (pInfo) {
102 LogMessage(X_INFO, "systemd-logind: returning pre-existing fd for %s %u:%u\n",
103 path, major, minor);
104 *paused_ret = FALSE;
105 return pInfo->fd;
106 }
107
108 dbus_error_init(&error);
109
110 msg = dbus_message_new_method_call("org.freedesktop.login1", info->session,
111 "org.freedesktop.login1.Session", "TakeDevice");
112 if (!msg) {
113 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
114 goto cleanup;
115 }
116
117 if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, &major,
118 DBUS_TYPE_UINT32, &minor,
119 DBUS_TYPE_INVALID)) {
120 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
121 goto cleanup;
122 }
123
124 reply = dbus_connection_send_with_reply_and_block(info->conn, msg,
125 - DBUS_TIMEOUT, &error);
126 + DBUS_TIMEOUT_USE_DEFAULT, &error);
127 if (!reply) {
128 LogMessage(X_ERROR, "systemd-logind: failed to take device %s: %s\n",
129 path, error.message);
130 goto cleanup;
131 }
132
133 if (!dbus_message_get_args(reply, &error,
134 DBUS_TYPE_UNIX_FD, &fd,
135 DBUS_TYPE_BOOLEAN, &paused,
136 DBUS_TYPE_INVALID)) {
137 LogMessage(X_ERROR, "systemd-logind: TakeDevice %s: %s\n",
138 path, error.message);
139 goto cleanup;
140 }
141
142 *paused_ret = paused;
143
144 LogMessage(X_INFO, "systemd-logind: got fd for %s %u:%u fd %d paused %d\n",
145 path, major, minor, fd, paused);
146
147 cleanup:
148 if (msg)
149 dbus_message_unref(msg);
150 if (reply)
151 dbus_message_unref(reply);
152 dbus_error_free(&error);
153
154 return fd;
155 }
156
157 @@ -180,61 +178,61 @@ systemd_logind_release_fd(int _major, int _minor, int fd)
158 * and minor, otherwise other InputInfo's are still referencing the fd. */
159 pInfo = systemd_logind_find_info_ptr_by_devnum(xf86InputDevs, major, minor);
160 while (pInfo) {
161 matches++;
162 pInfo = systemd_logind_find_info_ptr_by_devnum(pInfo->next, major, minor);
163 }
164 if (matches > 1) {
165 LogMessage(X_INFO, "systemd-logind: not releasing fd for %u:%u, still in use\n", major, minor);
166 return;
167 }
168
169 LogMessage(X_INFO, "systemd-logind: releasing fd for %u:%u\n", major, minor);
170
171 dbus_error_init(&error);
172
173 msg = dbus_message_new_method_call("org.freedesktop.login1", info->session,
174 "org.freedesktop.login1.Session", "ReleaseDevice");
175 if (!msg) {
176 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
177 goto cleanup;
178 }
179
180 if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, &major,
181 DBUS_TYPE_UINT32, &minor,
182 DBUS_TYPE_INVALID)) {
183 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
184 goto cleanup;
185 }
186
187 reply = dbus_connection_send_with_reply_and_block(info->conn, msg,
188 - DBUS_TIMEOUT, &error);
189 + DBUS_TIMEOUT_USE_DEFAULT, &error);
190 if (!reply)
191 LogMessage(X_ERROR, "systemd-logind: failed to release device: %s\n",
192 error.message);
193
194 cleanup:
195 if (msg)
196 dbus_message_unref(msg);
197 if (reply)
198 dbus_message_unref(reply);
199 dbus_error_free(&error);
200 close:
201 if (fd != -1)
202 close(fd);
203 }
204
205 int
206 systemd_logind_controls_session(void)
207 {
208 return logind_info.session ? 1 : 0;
209 }
210
211 void
212 systemd_logind_vtenter(void)
213 {
214 struct systemd_logind_info *info = &logind_info;
215 InputInfoPtr pInfo;
216 int i;
217
218 if (!info->session)
219 return; /* Not using systemd-logind */
220 @@ -262,61 +260,61 @@ systemd_logind_vtenter(void)
221
222 /* Do delayed input probing, this must be done after the above enabling */
223 xf86InputEnableVTProbe();
224 }
225
226 static void
227 systemd_logind_ack_pause(struct systemd_logind_info *info,
228 dbus_int32_t minor, dbus_int32_t major)
229 {
230 DBusError error;
231 DBusMessage *msg = NULL;
232 DBusMessage *reply = NULL;
233
234 dbus_error_init(&error);
235
236 msg = dbus_message_new_method_call("org.freedesktop.login1", info->session,
237 "org.freedesktop.login1.Session", "PauseDeviceComplete");
238 if (!msg) {
239 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
240 goto cleanup;
241 }
242
243 if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, &major,
244 DBUS_TYPE_UINT32, &minor,
245 DBUS_TYPE_INVALID)) {
246 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
247 goto cleanup;
248 }
249
250 reply = dbus_connection_send_with_reply_and_block(info->conn, msg,
251 - DBUS_TIMEOUT, &error);
252 + DBUS_TIMEOUT_USE_DEFAULT, &error);
253 if (!reply)
254 LogMessage(X_ERROR, "systemd-logind: failed to ack pause: %s\n",
255 error.message);
256
257 cleanup:
258 if (msg)
259 dbus_message_unref(msg);
260 if (reply)
261 dbus_message_unref(reply);
262 dbus_error_free(&error);
263 }
264
265 static DBusHandlerResult
266 message_filter(DBusConnection * connection, DBusMessage * message, void *data)
267 {
268 struct systemd_logind_info *info = data;
269 struct xf86_platform_device *pdev = NULL;
270 InputInfoPtr pInfo = NULL;
271 int ack = 0, pause = 0, fd = -1;
272 DBusError error;
273 dbus_int32_t major, minor;
274 char *pause_str;
275
276 if (dbus_message_get_type (message) != DBUS_MESSAGE_TYPE_SIGNAL)
277 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
278
279 dbus_error_init(&error);
280
281 if (dbus_message_is_signal(message,
282 "org.freedesktop.DBus", "NameOwnerChanged")) {
283 @@ -430,96 +428,96 @@ message_filter(DBusConnection * connection, DBusMessage * message, void *data)
284 }
285
286 static void
287 connect_hook(DBusConnection *connection, void *data)
288 {
289 struct systemd_logind_info *info = data;
290 DBusError error;
291 DBusMessage *msg = NULL;
292 DBusMessage *reply = NULL;
293 dbus_int32_t arg;
294 char *session = NULL;
295
296 dbus_error_init(&error);
297
298 msg = dbus_message_new_method_call("org.freedesktop.login1",
299 "/org/freedesktop/login1", "org.freedesktop.login1.Manager",
300 "GetSessionByPID");
301 if (!msg) {
302 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
303 goto cleanup;
304 }
305
306 arg = getpid();
307 if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, &arg,
308 DBUS_TYPE_INVALID)) {
309 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
310 goto cleanup;
311 }
312
313 reply = dbus_connection_send_with_reply_and_block(connection, msg,
314 - DBUS_TIMEOUT, &error);
315 + DBUS_TIMEOUT_USE_DEFAULT, &error);
316 if (!reply) {
317 LogMessage(X_ERROR, "systemd-logind: failed to get session: %s\n",
318 error.message);
319 goto cleanup;
320 }
321 dbus_message_unref(msg);
322
323 if (!dbus_message_get_args(reply, &error, DBUS_TYPE_OBJECT_PATH, &session,
324 DBUS_TYPE_INVALID)) {
325 LogMessage(X_ERROR, "systemd-logind: GetSessionByPID: %s\n",
326 error.message);
327 goto cleanup;
328 }
329 session = XNFstrdup(session);
330
331 dbus_message_unref(reply);
332 reply = NULL;
333
334
335 msg = dbus_message_new_method_call("org.freedesktop.login1",
336 session, "org.freedesktop.login1.Session", "TakeControl");
337 if (!msg) {
338 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
339 goto cleanup;
340 }
341
342 arg = FALSE; /* Don't forcibly take over over the session */
343 if (!dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &arg,
344 DBUS_TYPE_INVALID)) {
345 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
346 goto cleanup;
347 }
348
349 reply = dbus_connection_send_with_reply_and_block(connection, msg,
350 - DBUS_TIMEOUT, &error);
351 + DBUS_TIMEOUT_USE_DEFAULT, &error);
352 if (!reply) {
353 LogMessage(X_ERROR, "systemd-logind: TakeControl failed: %s\n",
354 error.message);
355 goto cleanup;
356 }
357
358 dbus_bus_add_match(connection,
359 "type='signal',sender='org.freedesktop.DBus',interface='org.freedesktop.DBus',member='NameOwnerChanged',path='/org/freedesktop/DBus'",
360 &error);
361 if (dbus_error_is_set(&error)) {
362 LogMessage(X_ERROR, "systemd-logind: could not add match: %s\n",
363 error.message);
364 goto cleanup;
365 }
366
367 /*
368 * HdG: This is not useful with systemd <= 208 since the signal only
369 * contains invalidated property names there, rather than property, val
370 * pairs as it should. Instead we just use the first resume / pause now.
371 */
372 #if 0
373 snprintf(match, sizeof(match),
374 "type='signal',sender='org.freedesktop.login1',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',path='%s'",
375 session);
376 dbus_bus_add_match(connection, match, &error);
377 if (dbus_error_is_set(&error)) {
378 LogMessage(X_ERROR, "systemd-logind: could not add match: %s\n",
379 error.message);
380 goto cleanup;
381 }
382 @@ -537,61 +535,61 @@ connect_hook(DBusConnection *connection, void *data)
383 info->session = session;
384 info->vt_active = info->active = TRUE; /* The server owns the vt during init */
385 session = NULL;
386
387 cleanup:
388 free(session);
389 if (msg)
390 dbus_message_unref(msg);
391 if (reply)
392 dbus_message_unref(reply);
393 dbus_error_free(&error);
394 }
395
396 static void
397 systemd_logind_release_control(struct systemd_logind_info *info)
398 {
399 DBusError error;
400 DBusMessage *msg = NULL;
401 DBusMessage *reply = NULL;
402
403 dbus_error_init(&error);
404
405 msg = dbus_message_new_method_call("org.freedesktop.login1",
406 info->session, "org.freedesktop.login1.Session", "ReleaseControl");
407 if (!msg) {
408 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
409 goto cleanup;
410 }
411
412 reply = dbus_connection_send_with_reply_and_block(info->conn, msg,
413 - DBUS_TIMEOUT, &error);
414 + DBUS_TIMEOUT_USE_DEFAULT, &error);
415 if (!reply) {
416 LogMessage(X_ERROR, "systemd-logind: ReleaseControl failed: %s\n",
417 error.message);
418 goto cleanup;
419 }
420
421 cleanup:
422 if (msg)
423 dbus_message_unref(msg);
424 if (reply)
425 dbus_message_unref(reply);
426 dbus_error_free(&error);
427 }
428
429 static void
430 disconnect_hook(void *data)
431 {
432 struct systemd_logind_info *info = data;
433
434 free(info->session);
435 info->session = NULL;
436 info->conn = NULL;
437 }
438
439 static struct dbus_core_hook core_hook = {
440 .connect = connect_hook,
441 .disconnect = disconnect_hook,
442 .data = &logind_info,
443 };
444
445 --
446 2.3.3