summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Agner <stefan@agner.ch>2019-11-14 23:39:40 +0100
committerPekka Paalanen <pq@iki.fi>2020-01-30 12:11:37 +0000
commitbd1e39a78776f0fbd4270b7fcf9d19835fc06c70 (patch)
tree9f4f53f649a94d4433e1e4c50f931c9536ae55de
parent247392a322ebabea3a20f3fe4d0237e703137153 (diff)
weston-launch: reset tty properly
On weston-launch exit we see errors such as: failed to restore keyboard mode: Invalid argument failed to set KD_TEXT mode on tty: Invalid argument This has been resolved by making sure the tty file descriptor does not get closed. However, the ioctrl's KDSKBMODE/KDSETMODE and VT_SETMODE still fail with -EIO: failed to restore keyboard mode: Input/output error failed to set KD_TEXT mode on tty: Input/output error It turns out the reason for this lies in some very particular behavior of the kernel, the separation of weston-launch/weston and the fact that we restore the tty only after the weston process quits: When the controlling process for a TTY exits, all open file descriptors for that TTY are put in a hung-up state! For more details see this systemd-logind issue: https://github.com/systemd/systemd/issues/989 We can work around by reopening the particular TTY. This allows to properly restore the TTY settings such that a successive VT switch will show text terminals fine again. Signed-off-by: Stefan Agner <stefan@agner.ch> Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
-rw-r--r--libweston/weston-launch.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/libweston/weston-launch.c b/libweston/weston-launch.c
index 911748a5..05525e34 100644
--- a/libweston/weston-launch.c
+++ b/libweston/weston-launch.c
@@ -440,6 +440,7 @@ quit(struct weston_launch *wl, int status)
{
struct vt_mode mode = { 0 };
int err;
+ int oldtty;
close(wl->signalfd);
close(wl->sock[0]);
@@ -452,6 +453,19 @@ quit(struct weston_launch *wl, int status)
pam_end(wl->ph, err);
}
+ /*
+ * Get a fresh handle to the tty as the previous one is in
+ * hang-up state since weston (the controlling process for
+ * the tty) exit at this point. Reopen before closing the
+ * file descriptor to avoid a potential race condition.
+ *
+ * A similar fix exists in logind, see:
+ * https://github.com/systemd/systemd/pull/990
+ */
+ oldtty = wl->tty;
+ wl->tty = open_tty_by_number(wl->ttynr);
+ close(oldtty);
+
if (ioctl(wl->tty, KDSKBMUTE, 0) &&
ioctl(wl->tty, KDSKBMODE, wl->kb_mode))
fprintf(stderr, "failed to restore keyboard mode: %s\n",