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
parent 1468e606
......@@ -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");
......
......@@ -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;
......
......@@ -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;
......
......@@ -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] ="<stdin>";
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;
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment