Magellan Linux

Annotation 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 - (hide 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 niro 2576 From 89250c82a01062775f8f840737a757125138fbce Mon Sep 17 00:00:00 2001
2     From: Ray Strode <rstrode@redhat.com>
3 niro 2575 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 niro 2576 ---
24 niro 2575 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 niro 2576 --- 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 niro 2575 * Software.
33     *
34 niro 2576 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
35 niro 2575 * 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 niro 2576 * Author: Hans de Goede <hdegoede@redhat.com>
43 niro 2575 */
44    
45     #ifdef HAVE_XORG_CONFIG_H
46 niro 2576 #include <xorg-config.h>
47 niro 2575 #endif
48    
49 niro 2576 #include <dbus/dbus.h>
50     #include <string.h>
51     #include <sys/types.h>
52     #include <unistd.h>
53 niro 2575
54 niro 2576 #include "os.h"
55     #include "dbus-core.h"
56     #include "xf86.h"
57     #include "xf86platformBus.h"
58     #include "xf86Xinput.h"
59 niro 2575
60 niro 2576 #include "systemd-logind.h"
61 niro 2575
62 niro 2576 -#define DBUS_TIMEOUT 500 /* Wait max 0.5 seconds */
63     -
64 niro 2575 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 niro 2576 for (pInfo = start; pInfo; pInfo = pInfo->next)
80     if (pInfo->major == major && pInfo->minor == minor &&
81     (pInfo->flags & XI86_SERVER_FD))
82 niro 2575 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 niro 2576 @@ -103,61 +101,61 @@ systemd_logind_take_fd(int _major, int _minor, const char *path,
95     if (strstr(path, "mouse"))
96 niro 2575 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 niro 2576 LogMessage(X_INFO, "systemd-logind: returning pre-existing fd for %s %u:%u\n",
103 niro 2575 path, major, minor);
104     *paused_ret = FALSE;
105 niro 2576 return pInfo->fd;
106 niro 2575 }
107    
108 niro 2576 dbus_error_init(&error);
109 niro 2575
110 niro 2576 msg = dbus_message_new_method_call("org.freedesktop.login1", info->session,
111     "org.freedesktop.login1.Session", "TakeDevice");
112 niro 2575 if (!msg) {
113 niro 2576 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
114 niro 2575 goto cleanup;
115     }
116    
117 niro 2576 if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, &major,
118     DBUS_TYPE_UINT32, &minor,
119 niro 2575 DBUS_TYPE_INVALID)) {
120 niro 2576 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
121 niro 2575 goto cleanup;
122     }
123    
124 niro 2576 reply = dbus_connection_send_with_reply_and_block(info->conn, msg,
125     - DBUS_TIMEOUT, &error);
126     + DBUS_TIMEOUT_USE_DEFAULT, &error);
127 niro 2575 if (!reply) {
128 niro 2576 LogMessage(X_ERROR, "systemd-logind: failed to take device %s: %s\n",
129 niro 2575 path, error.message);
130     goto cleanup;
131     }
132    
133 niro 2576 if (!dbus_message_get_args(reply, &error,
134     DBUS_TYPE_UNIX_FD, &fd,
135     DBUS_TYPE_BOOLEAN, &paused,
136 niro 2575 DBUS_TYPE_INVALID)) {
137 niro 2576 LogMessage(X_ERROR, "systemd-logind: TakeDevice %s: %s\n",
138 niro 2575 path, error.message);
139     goto cleanup;
140     }
141    
142     *paused_ret = paused;
143    
144 niro 2576 LogMessage(X_INFO, "systemd-logind: got fd for %s %u:%u fd %d paused %d\n",
145 niro 2575 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 niro 2576 dbus_error_free(&error);
153 niro 2575
154     return fd;
155     }
156    
157 niro 2576 @@ -180,61 +178,61 @@ systemd_logind_release_fd(int _major, int _minor, int fd)
158 niro 2575 * 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 niro 2576 pInfo = systemd_logind_find_info_ptr_by_devnum(pInfo->next, major, minor);
163 niro 2575 }
164 niro 2576 if (matches > 1) {
165     LogMessage(X_INFO, "systemd-logind: not releasing fd for %u:%u, still in use\n", major, minor);
166 niro 2575 return;
167     }
168    
169 niro 2576 LogMessage(X_INFO, "systemd-logind: releasing fd for %u:%u\n", major, minor);
170 niro 2575
171 niro 2576 dbus_error_init(&error);
172 niro 2575
173 niro 2576 msg = dbus_message_new_method_call("org.freedesktop.login1", info->session,
174     "org.freedesktop.login1.Session", "ReleaseDevice");
175 niro 2575 if (!msg) {
176 niro 2576 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
177 niro 2575 goto cleanup;
178     }
179    
180 niro 2576 if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, &major,
181     DBUS_TYPE_UINT32, &minor,
182 niro 2575 DBUS_TYPE_INVALID)) {
183 niro 2576 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
184 niro 2575 goto cleanup;
185     }
186    
187 niro 2576 reply = dbus_connection_send_with_reply_and_block(info->conn, msg,
188     - DBUS_TIMEOUT, &error);
189     + DBUS_TIMEOUT_USE_DEFAULT, &error);
190 niro 2575 if (!reply)
191 niro 2576 LogMessage(X_ERROR, "systemd-logind: failed to release device: %s\n",
192 niro 2575 error.message);
193    
194     cleanup:
195     if (msg)
196     dbus_message_unref(msg);
197     if (reply)
198     dbus_message_unref(reply);
199 niro 2576 dbus_error_free(&error);
200 niro 2575 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 niro 2576 struct systemd_logind_info *info = &logind_info;
215 niro 2575 InputInfoPtr pInfo;
216     int i;
217    
218 niro 2576 if (!info->session)
219 niro 2575 return; /* Not using systemd-logind */
220 niro 2576 @@ -262,61 +260,61 @@ systemd_logind_vtenter(void)
221 niro 2575
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 niro 2576 dbus_error_init(&error);
235 niro 2575
236 niro 2576 msg = dbus_message_new_method_call("org.freedesktop.login1", info->session,
237     "org.freedesktop.login1.Session", "PauseDeviceComplete");
238 niro 2575 if (!msg) {
239 niro 2576 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
240 niro 2575 goto cleanup;
241     }
242    
243 niro 2576 if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, &major,
244     DBUS_TYPE_UINT32, &minor,
245 niro 2575 DBUS_TYPE_INVALID)) {
246 niro 2576 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
247 niro 2575 goto cleanup;
248     }
249    
250 niro 2576 reply = dbus_connection_send_with_reply_and_block(info->conn, msg,
251     - DBUS_TIMEOUT, &error);
252     + DBUS_TIMEOUT_USE_DEFAULT, &error);
253 niro 2575 if (!reply)
254 niro 2576 LogMessage(X_ERROR, "systemd-logind: failed to ack pause: %s\n",
255 niro 2575 error.message);
256    
257     cleanup:
258     if (msg)
259     dbus_message_unref(msg);
260     if (reply)
261     dbus_message_unref(reply);
262 niro 2576 dbus_error_free(&error);
263 niro 2575 }
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 niro 2576 dbus_error_init(&error);
280 niro 2575
281     if (dbus_message_is_signal(message,
282 niro 2576 "org.freedesktop.DBus", "NameOwnerChanged")) {
283     @@ -430,96 +428,96 @@ message_filter(DBusConnection * connection, DBusMessage * message, void *data)
284 niro 2575 }
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 niro 2576 dbus_error_init(&error);
297 niro 2575
298 niro 2576 msg = dbus_message_new_method_call("org.freedesktop.login1",
299     "/org/freedesktop/login1", "org.freedesktop.login1.Manager",
300     "GetSessionByPID");
301 niro 2575 if (!msg) {
302 niro 2576 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
303 niro 2575 goto cleanup;
304     }
305    
306     arg = getpid();
307 niro 2576 if (!dbus_message_append_args(msg, DBUS_TYPE_UINT32, &arg,
308 niro 2575 DBUS_TYPE_INVALID)) {
309 niro 2576 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
310 niro 2575 goto cleanup;
311     }
312    
313     reply = dbus_connection_send_with_reply_and_block(connection, msg,
314 niro 2576 - DBUS_TIMEOUT, &error);
315     + DBUS_TIMEOUT_USE_DEFAULT, &error);
316 niro 2575 if (!reply) {
317 niro 2576 LogMessage(X_ERROR, "systemd-logind: failed to get session: %s\n",
318 niro 2575 error.message);
319     goto cleanup;
320     }
321     dbus_message_unref(msg);
322    
323 niro 2576 if (!dbus_message_get_args(reply, &error, DBUS_TYPE_OBJECT_PATH, &session,
324 niro 2575 DBUS_TYPE_INVALID)) {
325 niro 2576 LogMessage(X_ERROR, "systemd-logind: GetSessionByPID: %s\n",
326 niro 2575 error.message);
327     goto cleanup;
328     }
329     session = XNFstrdup(session);
330    
331     dbus_message_unref(reply);
332     reply = NULL;
333    
334    
335 niro 2576 msg = dbus_message_new_method_call("org.freedesktop.login1",
336     session, "org.freedesktop.login1.Session", "TakeControl");
337 niro 2575 if (!msg) {
338 niro 2576 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
339 niro 2575 goto cleanup;
340     }
341    
342     arg = FALSE; /* Don't forcibly take over over the session */
343 niro 2576 if (!dbus_message_append_args(msg, DBUS_TYPE_BOOLEAN, &arg,
344 niro 2575 DBUS_TYPE_INVALID)) {
345 niro 2576 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
346 niro 2575 goto cleanup;
347     }
348    
349     reply = dbus_connection_send_with_reply_and_block(connection, msg,
350 niro 2576 - DBUS_TIMEOUT, &error);
351     + DBUS_TIMEOUT_USE_DEFAULT, &error);
352 niro 2575 if (!reply) {
353 niro 2576 LogMessage(X_ERROR, "systemd-logind: TakeControl failed: %s\n",
354 niro 2575 error.message);
355     goto cleanup;
356     }
357    
358     dbus_bus_add_match(connection,
359 niro 2576 "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 niro 2575 error.message);
364     goto cleanup;
365     }
366    
367     /*
368 niro 2576 * HdG: This is not useful with systemd <= 208 since the signal only
369 niro 2575 * 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 niro 2576 "type='signal',sender='org.freedesktop.login1',interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',path='%s'",
375 niro 2575 session);
376 niro 2576 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 niro 2575 error.message);
380     goto cleanup;
381     }
382 niro 2576 @@ -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 niro 2575 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 niro 2576 dbus_error_free(&error);
394 niro 2575 }
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 niro 2576 dbus_error_init(&error);
404 niro 2575
405 niro 2576 msg = dbus_message_new_method_call("org.freedesktop.login1",
406     info->session, "org.freedesktop.login1.Session", "ReleaseControl");
407 niro 2575 if (!msg) {
408 niro 2576 LogMessage(X_ERROR, "systemd-logind: out of memory\n");
409 niro 2575 goto cleanup;
410     }
411    
412 niro 2576 reply = dbus_connection_send_with_reply_and_block(info->conn, msg,
413     - DBUS_TIMEOUT, &error);
414     + DBUS_TIMEOUT_USE_DEFAULT, &error);
415 niro 2575 if (!reply) {
416 niro 2576 LogMessage(X_ERROR, "systemd-logind: ReleaseControl failed: %s\n",
417 niro 2575 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 niro 2576 dbus_error_free(&error);
427 niro 2575 }
428    
429     static void
430     disconnect_hook(void *data)
431     {
432     struct systemd_logind_info *info = data;
433    
434 niro 2576 free(info->session);
435     info->session = NULL;
436     info->conn = NULL;
437 niro 2575 }
438    
439     static struct dbus_core_hook core_hook = {
440     .connect = connect_hook,
441     .disconnect = disconnect_hook,
442 niro 2576 .data = &logind_info,
443 niro 2575 };
444    
445 niro 2576 --
446     2.3.3