summaryrefslogtreecommitdiff
blob: 206219d8e05900e9958e1985eec25b4e7e8f84c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
From 198d6392ff595f330430d92d5c380cd993be73d7 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= <mail@3v1n0.net>
Date: Tue, 16 Oct 2018 20:59:23 +0200
Subject: [PATCH] gdm3.service: wait for drm device before trying to start it

Bug-Ubuntu: https://bugs.launchpad.net/ubuntu/+source/gdm3/+bug/1794280
Forwarded: not-needed
---
 configure.ac             |   1 +
 data/Makefile.am         |   1 +
 data/gdm.service.in      |   1 +
 utils/Makefile.am        |   9 ++++
 utils/gdm-wait-for-drm.c | 101 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 113 insertions(+)
 create mode 100644 utils/gdm-wait-for-drm.c

diff --git a/configure.ac b/configure.ac
index a8dcfbef..2755c100 100644
--- a/configure.ac
+++ b/configure.ac
@@ -76,6 +76,7 @@ PKG_CHECK_MODULES(COMMON,
         gobject-2.0 >= $GLIB_REQUIRED_VERSION
         gio-2.0 >= $GLIB_REQUIRED_VERSION
         gio-unix-2.0 >= $GLIB_REQUIRED_VERSION
+        gudev-1.0
 )
 AC_SUBST(COMMON_CFLAGS)
 AC_SUBST(COMMON_LIBS)
diff --git a/data/Makefile.am b/data/Makefile.am
index 162074f1..5f426fea 100644
--- a/data/Makefile.am
+++ b/data/Makefile.am
@@ -204,6 +204,7 @@ systemdsystemunit =
 gdm.service: $(srcdir)/gdm.service.in
 	$(AM_V_GEN)sed \
 		-e 's,[@]sbindir[@],$(sbindir),g' \
+		-e 's,[@]libexecdir[@],$(libexecdir),g' \
 		-e 's,[@]GDM_INITIAL_VT[@],$(GDM_INITIAL_VT),g' \
 		-e 's,[@]LANG_CONFIG_FILE[@],$(LANG_CONFIG_FILE),g' \
 		-e 's,[@]PLYMOUTH_QUIT_SERVICE[@],$(PLYMOUTH_QUIT_SERVICE),g' \
diff --git a/data/gdm.service.in b/data/gdm.service.in
index 57d60ada..f7630ec4 100644
--- a/data/gdm.service.in
+++ b/data/gdm.service.in
@@ -30,6 +30,7 @@ StandardError=inherit
 EnvironmentFile=-@LANG_CONFIG_FILE@
 ExecReload=/bin/kill -SIGHUP $MAINPID
 KeyringMode=shared
+ExecStartPre=@libexecdir@/gdm-wait-for-drm
 
 [Install]
 Alias=display-manager.service
diff --git a/utils/Makefile.am b/utils/Makefile.am
index babe890b..3eb43c30 100644
--- a/utils/Makefile.am
+++ b/utils/Makefile.am
@@ -35,6 +35,7 @@ bin_PROGRAMS = \
 
 libexec_PROGRAMS = \
 	gdm-disable-wayland	\
+	gdm-wait-for-drm	\
 	$(NULL)
 
 gdmflexiserver_LDADD =		\
@@ -63,6 +64,14 @@ gdm_disable_wayland_SOURCES =	\
 	gdm-disable-wayland.c	\
 	$(NULL)
 
+gdm_wait_for_drm_LDADD =	\
+	$(COMMON_LIBS)		\
+	$(NULL)
+
+gdm_wait_for_drm_SOURCES =	\
+	gdm-wait-for-drm.c	\
+	$(NULL)
+
 CLEANFILES = 			\
 	$(NULL)
 
diff --git a/utils/gdm-wait-for-drm.c b/utils/gdm-wait-for-drm.c
new file mode 100644
index 00000000..aeffb3c0
--- /dev/null
+++ b/utils/gdm-wait-for-drm.c
@@ -0,0 +1,101 @@
+#include <glib.h>
+#include <gudev/gudev.h>
+
+/*
+ * Workaround for LP: #1794280.
+ *
+ * That bug is because the DRM device isn't ready by the time GDM tries to
+ * start wayland/X.
+ * This is a script to add to ExecStartPre of gdm.service. It does the
+ * following:
+ *
+ * 1. Enumerate drm devices from udev, looking for a DRM master. If found,
+ *    exit.
+ * 2. Connect to the 'uevent' signal of gudev, watching for the same to be
+ *    added. Again exit if any are found.
+ * 3. If, after 10 seconds, we haven't seen anything, try to proceed anyway as
+ *    a failsafe.
+ */
+
+static gboolean
+handle_device (GUdevDevice *device)
+{
+        const gchar * const * tags;
+        tags = g_udev_device_get_tags (device);
+        g_debug ("%s\n", g_udev_device_get_name (device));
+        if (g_strv_contains (tags, "master-of-seat"))
+        {
+                g_debug ("    is seat master\n");
+                return TRUE;
+        }
+
+        return FALSE;
+}
+
+static void
+uevent_cb (GUdevClient *client G_GNUC_UNUSED,
+           gchar       *action,
+           GUdevDevice *device,
+           gpointer     user_data)
+{
+        GMainLoop *loop;
+
+        g_debug ("uevent action: %s\n", action);
+
+        loop = (GMainLoop *) user_data;
+
+        if (g_strcmp0 (action, "add") == 0)
+        {
+                if (handle_device (device))
+                {
+                        g_debug ("        this is good\n");
+                        g_main_loop_quit (loop);
+                }
+                else
+                {
+                        g_debug ("        this is bad\n");
+                }
+        }
+}
+
+int
+main()
+{
+        const gchar * const subsystems[] = { "drm", NULL };
+
+        g_autoptr(GList) devices = NULL;
+        g_autoptr(GMainLoop) loop = NULL;
+        g_autoptr(GUdevClient) udev_client = NULL;
+        g_autoptr(GUdevEnumerator) enumerator = NULL;
+
+        loop = g_main_loop_new (NULL, FALSE);
+
+        udev_client = g_udev_client_new (subsystems);
+        enumerator = g_udev_enumerator_new (udev_client);
+        g_udev_enumerator_add_match_is_initialized (enumerator);
+        g_udev_enumerator_add_match_subsystem (enumerator, "drm");
+
+        devices = g_udev_enumerator_execute (enumerator);
+
+        g_debug ("enumerating devices...\n");
+
+        for (GList *l = devices; l != NULL; l = l->next)
+        {
+                g_autoptr(GUdevDevice) device = G_UDEV_DEVICE (l->data);
+
+                if (handle_device (device))
+                {
+                        g_debug ("        good enough for gdm\n");
+                        return EXIT_SUCCESS;
+                }
+        }
+
+        g_signal_connect (udev_client, "uevent", G_CALLBACK (uevent_cb), loop);
+
+        /* after 10 seconds we try anyway */
+        g_timeout_add_seconds (10, (GSourceFunc) g_main_loop_quit, loop);
+
+        g_main_loop_run (loop);
+
+        return EXIT_SUCCESS;
+}
-- 
2.17.0