~ubuntu-branches/ubuntu/raring/consolekit/raring

« back to all changes in this revision

Viewing changes to debian/patches/01-retry-console-open-on-EIO.patch

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2010-11-20 18:17:28 UTC
  • mfrom: (0.1.16 sid)
  • Revision ID: james.westby@ubuntu.com-20101120181728-8e5bwe4ttgmk4j41
Tags: 0.4.3-2
Add 01-retry-console-open-on-EIO.patch: As reported in LP: #544139,
ConsoleKit sometimes fails to track the active VT. This particular case
was tracked down to a race condition that happens if you try to open
/dev/console while the current TTY is currently being closed. This yields
an -EIO error, in which case CK should just try again. Thanks Colin Watson
for the patch!

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
5
 
 
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
 
10
again.
 
11
 
 
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 .
 
14
 
 
15
Bug: https://bugs.freedesktop.org/show_bug.cgi?id=31790
 
16
Bug-Ubuntu: https://launchpad.net/bugs/544139
 
17
---
 
18
 src/ck-sysdeps-unix.c |   17 +++++++++++++++++
 
19
 1 files changed, 17 insertions(+), 0 deletions(-)
 
20
 
 
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
 
25
@@ -26,6 +26,7 @@
 
26
 #include <unistd.h>
 
27
 #include <string.h>
 
28
 #include <errno.h>
 
29
+#include <time.h>
 
30
 #include <sys/types.h>
 
31
 #include <sys/stat.h>
 
32
 #include <sys/socket.h>
 
33
@@ -150,9 +151,25 @@ open_a_console (char *fnam)
 
34
 {
 
35
         int fd;
 
36
 
 
37
+again:
 
38
         fd = open (fnam, O_RDONLY | O_NOCTTY);
 
39
         if (fd < 0 && errno == EACCES)
 
40
                 fd = open (fnam, O_WRONLY | O_NOCTTY);
 
41
+#ifdef __linux__
 
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
 
49
+                * fd.
 
50
+                */
 
51
+               struct timespec ts = { 0, 100000000 }; /* 0.1 seconds */
 
52
+               nanosleep (&ts, NULL);
 
53
+               goto again;
 
54
+       }
 
55
+#endif
 
56
 
 
57
         if (fd < 0)
 
58
                 return -1;
 
59
-- 
 
60
1.7.2.3
 
61