summaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-02-17 16:29:47 +0100
committerLennart Poettering <lennart@poettering.net>2011-02-17 16:29:49 +0100
commitf73f76acff4fd1d90bfbef486eedb25c4462809b (patch)
treeb4a126d054e8739714abcfc7416f3c8fa569ac08 /src/util.c
parentfc116c6a19877275eabb085cf03f0df23b17c0e9 (diff)
util: retry opening a TTY on EIO
https://bugs.freedesktop.org/show_bug.cgi?id=33996 https://bugs.launchpad.net/ubuntu/+source/linux/+bug/554172/comments/245
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c26
1 files changed, 25 insertions, 1 deletions
diff --git a/src/util.c b/src/util.c
index 92268b69a9..b8e73ef4bf 100644
--- a/src/util.c
+++ b/src/util.c
@@ -2134,8 +2134,32 @@ finish:
int open_terminal(const char *name, int mode) {
int fd, r;
+ unsigned c = 0;
- if ((fd = open(name, mode)) < 0)
+ /*
+ * If a TTY is in the process of being closed opening it might
+ * cause EIO. This is horribly awful, but unlikely to be
+ * changed in the kernel. Hence we work around this problem by
+ * retrying a couple of times.
+ *
+ * https://bugs.launchpad.net/ubuntu/+source/linux/+bug/554172/comments/245
+ */
+
+ for (;;) {
+ if ((fd = open(name, mode)) >= 0)
+ break;
+
+ if (errno != EIO)
+ return -errno;
+
+ if (c >= 20)
+ return -errno;
+
+ usleep(50 * USEC_PER_MSEC);
+ c++;
+ }
+
+ if (fd < 0)
return -errno;
if ((r = isatty(fd)) < 0) {