From 6ff3ff57aa76aa8738383cbacc4e9f425e1da056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Wed, 2 Oct 2013 10:53:33 -0700 Subject: [PATCH] launcher: Add back support for specifying VT to run on This is only available when running weston directly as root typically for ssh logins. It's a somewhat destructive option, as it will take over any existing VT completely, unless there's already an display server running there. https://bugs.freedesktop.org/show_bug.cgi?id=69731 --- src/compositor-drm.c | 2 +- src/compositor-fbdev.c | 6 ++++-- src/compositor-rpi.c | 3 ++- src/launcher-util.c | 42 +++++++++++++++++++++++++++++++++++------- src/launcher-util.h | 2 +- 5 files changed, 43 insertions(+), 12 deletions(-) diff --git a/src/compositor-drm.c b/src/compositor-drm.c index 2770c851..0ac5efac 100644 --- a/src/compositor-drm.c +++ b/src/compositor-drm.c @@ -2564,7 +2564,7 @@ drm_compositor_create(struct wl_display *display, } /* Check if we run drm-backend using weston-launch */ - ec->base.launcher = weston_launcher_connect(&ec->base); + ec->base.launcher = weston_launcher_connect(&ec->base, tty); if (ec->base.launcher == NULL) { weston_log("fatal: drm backend should be run " "using weston-launch binary or as root\n"); diff --git a/src/compositor-fbdev.c b/src/compositor-fbdev.c index f0625cdf..92aefdac 100644 --- a/src/compositor-fbdev.c +++ b/src/compositor-fbdev.c @@ -880,7 +880,8 @@ fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[], goto out_free; /* Check if we run fbdev-backend using weston-launch */ - compositor->base.launcher = weston_launcher_connect(&compositor->base); + compositor->base.launcher = + weston_launcher_connect(&compositor->base, param->tty); if (compositor->base.launcher == NULL && geteuid() != 0) { weston_log("fatal: fbdev backend should be run " "using weston-launch binary or as root\n"); @@ -897,7 +898,8 @@ fbdev_compositor_create(struct wl_display *display, int *argc, char *argv[], compositor->session_listener.notify = session_notify; wl_signal_add(&compositor->base.session_signal, &compositor->session_listener); - compositor->base.launcher = weston_launcher_connect(&compositor->base); + compositor->base.launcher = + weston_launcher_connect(&compositor->base, param->tty); if (!compositor->base.launcher) { weston_log("Failed to set up launcher.\n"); goto out_udev; diff --git a/src/compositor-rpi.c b/src/compositor-rpi.c index 7c5ed0e6..05667fb4 100644 --- a/src/compositor-rpi.c +++ b/src/compositor-rpi.c @@ -751,7 +751,8 @@ rpi_compositor_create(struct wl_display *display, int *argc, char *argv[], compositor->session_listener.notify = session_notify; wl_signal_add(&compositor->base.session_signal, &compositor ->session_listener); - compositor->base.launcher = weston_launcher_connect(&compositor->base); + compositor->base.launcher = + weston_launcher_connect(&compositor->base, param->tty); if (!compositor->base.launcher) { weston_log("Failed to initialize tty.\n"); goto out_udev; diff --git a/src/launcher-util.c b/src/launcher-util.c index ad93d37b..6c28dc3e 100644 --- a/src/launcher-util.c +++ b/src/launcher-util.c @@ -247,22 +247,50 @@ vt_handler(int signal_number, void *data) } static int -setup_tty(struct weston_launcher *launcher) +setup_tty(struct weston_launcher *launcher, int tty) { struct wl_event_loop *loop; struct vt_mode mode = { 0 }; struct stat buf; - int ret; + char tty_device[32] =""; + int ret, kd_mode; - if (fstat(STDIN_FILENO, &buf) == -1 || + if (tty == 0) { + launcher->tty = tty; + } else { + snprintf(tty_device, sizeof tty_device, "/dev/tty%d", tty); + launcher->tty = open(tty_device, O_RDWR | O_CLOEXEC); + if (launcher->tty == -1) { + weston_log("couldn't open tty %s: %m\n", tty_device); + return -1; + } + } + + if (fstat(launcher->tty, &buf) == -1 || major(buf.st_rdev) != TTY_MAJOR || minor(buf.st_rdev) == 0) { - weston_log("stdin not a vt\n"); + weston_log("%s not a vt\n", tty_device); weston_log("if running weston from ssh, " "use --tty to specify a tty\n"); return -1; } - launcher->tty = STDIN_FILENO; + ret = ioctl(launcher->tty, KDGETMODE, &kd_mode); + if (ret) { + weston_log("failed to get VT mode: %m\n"); + return -1; + } + if (kd_mode != KD_TEXT) { + weston_log("%s is already in graphics mode, " + "is another display server running?\n", tty_device); + return -1; + } + + ret = ioctl(launcher->tty, VT_ACTIVATE, minor(buf.st_rdev)); + weston_log("VT_ACTIVATE ret=%d, %m vt\n", ret); + + ret = ioctl(launcher->tty, VT_WAITACTIVE, minor(buf.st_rdev)); + weston_log("VT_WAITACTIVE ret=%d, %m vt\n", ret); + if (ioctl(launcher->tty, KDGKBMODE, &launcher->kb_mode)) { weston_log("failed to read keyboard mode: %m\n"); return -1; @@ -304,7 +332,7 @@ weston_launcher_activate_vt(struct weston_launcher *launcher, int vt) } struct weston_launcher * -weston_launcher_connect(struct weston_compositor *compositor) +weston_launcher_connect(struct weston_compositor *compositor, int tty) { struct weston_launcher *launcher; struct wl_event_loop *loop; @@ -328,7 +356,7 @@ weston_launcher_connect(struct weston_compositor *compositor) return NULL; } } else if (geteuid() == 0) { - if (setup_tty(launcher) == -1) { + if (setup_tty(launcher, tty) == -1) { free(launcher); return NULL; } diff --git a/src/launcher-util.h b/src/launcher-util.h index ab669160..3e7ceb59 100644 --- a/src/launcher-util.h +++ b/src/launcher-util.h @@ -30,7 +30,7 @@ struct weston_launcher; struct weston_launcher * -weston_launcher_connect(struct weston_compositor *compositor); +weston_launcher_connect(struct weston_compositor *compositor, int tty); void weston_launcher_destroy(struct weston_launcher *launcher);