commit dd0b216

Michael Forney  ·  2014-08-06 02:45:06 +0000 UTC
parent 9643dcb
launch: Stop devices *before* activating old VT

Otherwise, if there is a display server running on the old VT, it may
try to acquire DRM master before we have released it.
1 files changed,  +12, -11
+12, -11
 1@@ -121,19 +121,21 @@ static void stop_devices(bool fatal)
 2 
 3 static void cleanup()
 4 {
 5-    /* Cleanup VT */
 6-    if (original_vt_state.altered)
 7-    {
 8-        struct vt_mode mode = { .mode = VT_AUTO };
 9+    struct vt_mode mode = { .mode = VT_AUTO };
10 
11-        fprintf(stderr, "Restoring VT to original state\n");
12-        ioctl(launcher.tty_fd, VT_SETMODE, &mode);
13-        ioctl(launcher.tty_fd, KDSETMODE, original_vt_state.console_mode);
14-        ioctl(launcher.tty_fd, KDSKBMODE, original_vt_state.kb_mode);
15-        ioctl(launcher.tty_fd, VT_ACTIVATE, original_vt_state.vt);
16-    }
17+    if (!original_vt_state.altered)
18+        return;
19 
20+    /* Cleanup VT */
21+    fprintf(stderr, "Restoring VT to original state\n");
22+    ioctl(launcher.tty_fd, VT_SETMODE, &mode);
23+    ioctl(launcher.tty_fd, KDSETMODE, original_vt_state.console_mode);
24+    ioctl(launcher.tty_fd, KDSKBMODE, original_vt_state.kb_mode);
25+
26+    /* Stop devices before switching the VT to make sure we have released the
27+     * DRM device before the next session tries to claim it. */
28     stop_devices(false);
29+    ioctl(launcher.tty_fd, VT_ACTIVATE, original_vt_state.vt);
30 }
31 
32 void __attribute__((noreturn,format(printf,1,2)))
33@@ -317,7 +319,6 @@ static int find_vt()
34         die("Could not find unused VT");
35 
36     close(tty0_fd);
37-
38     fprintf(stderr, "Running on VT %d\n", vt);
39 
40   done: