1
From 3665e8094e50f1f70b02a34d96c005ce152d62a6 Mon Sep 17 00:00:00 2001
2
From: Colin Watson <cjwatson@ubuntu.com>
3
Date: Sat, 20 Nov 2010 17:57:22 +0100
4
Subject: [PATCH] Retry opening console device on EIO
6
As reported in https://launchpad.net/bugs/544139, ConsoleKit sometimes fails to
7
track the active VT. This particular case was tracked down to a race condition
8
that happens if you try to open /dev/console while the current TTY is currently
9
being closed. This yields an -EIO error, in which case CK should just try
12
For a more detailled summary of the problem from a kernel perspective, please
13
see https://bugs.launchpad.net/ubuntu/+source/linux/+bug/554172/comments/245 .
15
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=31790
16
Bug-Ubuntu: https://launchpad.net/bugs/544139
18
src/ck-sysdeps-unix.c | 17 +++++++++++++++++
19
1 files changed, 17 insertions(+), 0 deletions(-)
21
diff --git a/src/ck-sysdeps-unix.c b/src/ck-sysdeps-unix.c
22
index e4ab16b..4a1736c 100644
23
--- a/src/ck-sysdeps-unix.c
24
+++ b/src/ck-sysdeps-unix.c
30
#include <sys/types.h>
32
#include <sys/socket.h>
33
@@ -150,9 +151,25 @@ open_a_console (char *fnam)
38
fd = open (fnam, O_RDONLY | O_NOCTTY);
39
if (fd < 0 && errno == EACCES)
40
fd = open (fnam, O_WRONLY | O_NOCTTY);
42
+ if (fd < 0 && errno == EIO) {
43
+ /* Linux can return EIO if the tty is currently closing,
44
+ * which can happen if multiple processes are opening and
45
+ * closing the console in parallel. Unfortunately it can
46
+ * also return EIO in more serious situations too (see
47
+ * https://bugs.launchpad.net/bugs/554172), but there isn't
48
+ * much we can do about that since we really need a console
51
+ struct timespec ts = { 0, 100000000 }; /* 0.1 seconds */
52
+ nanosleep (&ts, NULL);