[systemd-devel] [PATCH] vconsole-setup.c: prevent EIO failure
harald at redhat.com
harald at redhat.com
Tue May 3 07:39:34 PDT 2011
From: Harald Hoyer <harald at redhat.com>
There might be a race condition that happens if you try to open
/dev/tty0 while the current TTY is currently being closed.
This would yield an -EIO error.
---
src/vconsole-setup.c | 14 ++++++++++++++
1 files changed, 14 insertions(+), 0 deletions(-)
diff --git a/src/vconsole-setup.c b/src/vconsole-setup.c
index 1be260b..60a5f14 100644
--- a/src/vconsole-setup.c
+++ b/src/vconsole-setup.c
@@ -176,7 +176,21 @@ int main(int argc, char **argv) {
else
vc = "/dev/tty0";
+again:
if ((fd = open(vc, O_RDWR|O_CLOEXEC)) < 0) {
+ if (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;
+ }
log_error("Failed to open %s: %m", vc);
goto finish;
}
--
1.7.3.4
More information about the systemd-devel
mailing list