summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorColin Watson <cjwatson@ubuntu.com>2010-11-20 17:57:22 +0100
committerLennart Poettering <lennart@poettering.net>2011-05-03 01:51:07 +0200
commit4a1e58fd29c7cdf48dea879191a45db2cfcca0d1 (patch)
tree05fa153e4296ed999fa288fe78b8091947a7329f
parent14d5ef815d3f1a1a7d72bdc242c7ebb085372c8d (diff)
Retry opening console device on EIO0.4.5
As reported in https://launchpad.net/bugs/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. For a more detailled summary of the problem from a kernel perspective, please see https://bugs.launchpad.net/ubuntu/+source/linux/+bug/554172/comments/245 . https://bugs.freedesktop.org/show_bug.cgi?id=31790
-rw-r--r--src/ck-sysdeps-unix.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/ck-sysdeps-unix.c b/src/ck-sysdeps-unix.c
index e4ab16b..4a1736c 100644
--- a/src/ck-sysdeps-unix.c
+++ b/src/ck-sysdeps-unix.c
@@ -26,6 +26,7 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
+#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/socket.h>
@@ -150,9 +151,25 @@ open_a_console (char *fnam)
{
int fd;
+again:
fd = open (fnam, O_RDONLY | O_NOCTTY);
if (fd < 0 && errno == EACCES)
fd = open (fnam, O_WRONLY | O_NOCTTY);
+#ifdef __linux__
+ if (fd < 0 && errno == EIO) {
+ /* Linux can return EIO if the tty is currently closing,
+ * which can happen if multiple processes are opening and
+ * closing the console in parallel. Unfortunately it can
+ * also return EIO in more serious situations too (see
+ * https://bugs.launchpad.net/bugs/554172), but there isn't
+ * much we can do about that since we really need a console
+ * fd.
+ */
+ struct timespec ts = { 0, 100000000 }; /* 0.1 seconds */
+ nanosleep (&ts, NULL);
+ goto again;
+ }
+#endif
if (fd < 0)
return -1;