[PATCH] weston-launch: Fixed TTY switching
Pekka Paalanen
ppaalanen at gmail.com
Wed Apr 8 02:28:20 PDT 2015
David,
would you happen to have a moment to look at this, please?
Thanks,
pq
On Wed, 1 Apr 2015 08:10:44 +0100
mateuszx.potrola at intel.com wrote:
> From: Mateusz Polrola <mateuszx.potrola at intel.com>
>
> After weston-launch is executing weston it cannot close TTY file,
> because it is still required to properly handle SIGUSR1 and SIGUSR2
> signals that are used for switching TTY.
>
> Additionally after opening TTY it has to be activated, so that user
> don't have to manually switch to TTY used by weston first to be able to switch
> to other TTY.
> During shutdown TTY file has to be reopened, as device was already deinitialize by child
> process, but it is still required to cleanup VT handling and leave
> system in sane state.
>
> Signed-off-by: Mateusz Polrola <mateuszx.potrola at intel.com>
> ---
> src/weston-launch.c | 20 +++++++++++++++++---
> 1 files changed, 17 insertions(+), 3 deletions(-)
>
> diff --git a/src/weston-launch.c b/src/weston-launch.c
> index 10c66de..312b955 100644
> --- a/src/weston-launch.c
> +++ b/src/weston-launch.c
> @@ -46,6 +46,7 @@
> #include <linux/vt.h>
> #include <linux/major.h>
> #include <linux/kd.h>
> +#include <linux/limits.h>
>
> #include <pwd.h>
> #include <grp.h>
> @@ -105,6 +106,7 @@ struct weston_launch {
> pid_t child;
> int verbose;
> char *new_user;
> + char tty_path[PATH_MAX];
> };
>
> union cmsg_data { unsigned char b[4]; int fd; };
> @@ -419,6 +421,13 @@ quit(struct weston_launch *wl, int status)
> pam_end(wl->ph, err);
> }
>
> + /* tty will be deinitialized by child process, so it has to be
> + * opened again to correctly cleanup vt handling. */
> + if (wl->tty != STDIN_FILENO) {
> + close(wl->tty);
> + wl->tty = open(wl->tty_path, O_RDWR | O_NOCTTY);
> + }
> +
> if (ioctl(wl->tty, KDSKBMUTE, 0) &&
> ioctl(wl->tty, KDSKBMODE, wl->kb_mode))
> fprintf(stderr, "failed to restore keyboard mode: %m\n");
> @@ -521,8 +530,10 @@ setup_tty(struct weston_launch *wl, const char *tty)
> t = ttyname(STDIN_FILENO);
> if (t && strcmp(t, tty) == 0)
> wl->tty = STDIN_FILENO;
> - else
> + else {
> wl->tty = open(tty, O_RDWR | O_NOCTTY);
> + strcpy(wl->tty_path, tty);
> + }
> } else {
> int tty0 = open("/dev/tty0", O_WRONLY | O_CLOEXEC);
> char filename[16];
> @@ -535,6 +546,7 @@ setup_tty(struct weston_launch *wl, const char *tty)
>
> snprintf(filename, sizeof filename, "/dev/tty%d", wl->ttynr);
> wl->tty = open(filename, O_RDWR | O_NOCTTY);
> + strcpy(wl->tty_path, filename);
> close(tty0);
> }
>
> @@ -555,6 +567,10 @@ setup_tty(struct weston_launch *wl, const char *tty)
> wl->ttynr = minor(buf.st_rdev);
> }
>
> + /* Activate tty, otherwise tty switches won't work right away. */
> + ioctl(wl->tty, VT_ACTIVATE, wl->ttynr);
> + ioctl(wl->tty, VT_WAITACTIVE, wl->ttynr);
> +
> if (ioctl(wl->tty, KDGKBMODE, &wl->kb_mode))
> error(1, errno, "failed to get current keyboard mode: %m\n");
>
> @@ -744,8 +760,6 @@ main(int argc, char *argv[])
> launch_compositor(&wl, argc - optind, argv + optind);
>
> close(wl.sock[1]);
> - if (wl.tty != STDIN_FILENO)
> - close(wl.tty);
>
> while (1) {
> struct pollfd fds[2];
More information about the wayland-devel
mailing list