1 From 4c68f5d395c66f28b56e488cb3cd12f36820357b Mon Sep 17 00:00:00 2001
2 From: Peter Hutterer <peter.hutterer@who-t.net>
3 Date: Wed, 9 May 2012 09:21:28 +1000
4 Subject: [PATCH 12/12] dix: disable all devices before shutdown
6 f3410b97cf9b48a47bee3d15d232f8a88e75f4ef introduced a regression on server
7 shutdown. If any button or key was held on shutdown (ctrl, alt, backspace
8 are usually still down) sending a raw event will segfault the server. The
9 the root windows are set to NULL before calling CloseDownDevices().
11 Avoid this by disabling all devices first when shutting down. Disabled
12 devices won't send events anymore.
14 Master keyboards must be disabled first, otherwise disabling the pointer
15 will trigger DisableDevice(keyboard) and the keyboard is removed from the
16 inputInfo.devices list and moved to inputInfo.off_devices. A regular loop
17 through inputInfo.devices would thus jump to off_devices and not recover.
19 Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
20 Acked-by: Chase Douglas <chase.douglas@canonical.com>
21 Reviewed-by: Chase Douglas <chase.douglas@canonical.com>
22 ---
23 dix/devices.c | 20 ++++++++++++++++++++
24 dix/main.c | 4 ++++
25 include/input.h | 2 +-
26 3 files changed, 25 insertions(+), 1 deletion(-)
28 --- a/dix/devices.c
29 +++ b/dix/devices.c
30 @@ -524,6 +524,26 @@
31 return TRUE;
32 }
34 +void
35 +DisableAllDevices(void)
36 +{
37 + DeviceIntPtr dev, tmp;
38 +
39 + nt_list_for_each_entry_safe(dev, tmp, inputInfo.devices, next) {
40 + if (!IsMaster(dev))
41 + DisableDevice(dev, FALSE);
42 + }
43 + /* master keyboards need to be disabled first */
44 + nt_list_for_each_entry_safe(dev, tmp, inputInfo.devices, next) {
45 + if (dev->enabled && IsMaster(dev) && IsKeyboardDevice(dev))
46 + DisableDevice(dev, FALSE);
47 + }
48 + nt_list_for_each_entry_safe(dev, tmp, inputInfo.devices, next) {
49 + if (dev->enabled)
50 + DisableDevice(dev, FALSE);
51 + }
52 +}
53 +
54 /**
55 * Initialise a new device through the driver and tell all clients about the
56 * new device.
57 --- a/dix/main.c
58 +++ b/dix/main.c
59 @@ -105,6 +105,7 @@
60 #include "privates.h"
61 #include "registry.h"
62 #include "client.h"
63 +#include "exevents.h"
64 #ifdef PANORAMIX
65 #include "panoramiXsrv.h"
66 #else
67 @@ -294,6 +295,7 @@
68 #endif
70 UndisplayDevices();
71 + DisableAllDevices();
73 /* Now free up whatever must be freed */
74 if (screenIsSaved == SCREEN_SAVER_ON)
75 --- a/include/input.h
76 +++ b/include/input.h
77 @@ -280,7 +280,7 @@
78 extern _X_EXPORT Bool DisableDevice(
79 DeviceIntPtr /*device*/,
80 BOOL /* sendevent */);
81 -
82 +extern void DisableAllDevices(void);
83 extern int InitAndStartDevices(void);
85 extern void CloseDownDevices(void);