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

« back to all changes in this revision

Viewing changes to debian/patches/10-retry_console_open_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
 
Index: b/src/ck-sysdeps-unix.c
2
 
===================================================================
3
 
--- a/src/ck-sysdeps-unix.c
4
 
+++ b/src/ck-sysdeps-unix.c
5
 
@@ -26,6 +26,7 @@
6
 
 #include <unistd.h>
7
 
 #include <string.h>
8
 
 #include <errno.h>
9
 
+#include <time.h>
10
 
 #include <sys/types.h>
11
 
 #include <sys/stat.h>
12
 
 #include <sys/socket.h>
13
 
@@ -150,9 +151,25 @@
14
 
 {
15
 
         int fd;
16
 
 
17
 
+again:
18
 
         fd = open (fnam, O_RDONLY | O_NOCTTY);
19
 
         if (fd < 0 && errno == EACCES)
20
 
                 fd = open (fnam, O_WRONLY | O_NOCTTY);
21
 
+#ifdef __linux__
22
 
+       if (fd < 0 && errno == EIO) {
23
 
+               /* Linux can return EIO if the tty is currently closing,
24
 
+                * which can happen if multiple processes are opening and
25
 
+                * closing the console in parallel.  Unfortunately it can
26
 
+                * also return EIO in more serious situations too (see
27
 
+                * https://bugs.launchpad.net/bugs/554172), but there isn't
28
 
+                * much we can do about that since we really need a console
29
 
+                * fd.
30
 
+                */
31
 
+               struct timespec ts = { 0, 100000000 }; /* 0.1 seconds */
32
 
+               nanosleep (&ts, NULL);
33
 
+               goto again;
34
 
+       }
35
 
+#endif
36
 
 
37
 
         if (fd < 0)
38
 
                 return -1;