[PATCH v3] weston-launch: Fixed TTY switching
Giulio Camuffo
giuliocamuffo at gmail.com
Sun Oct 4 03:31:47 PDT 2015
This is broken for me, see comments below.
<snip>
> + /* 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);
> + }
I wonder, in case wl->tty is STDIN_FILENO, is everything all right?
> +
> 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,11 @@ 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);
> + if (snprintf(wl->tty_path, PATH_MAX, "%s", tty) >= PATH_MAX)
> + error(1, 0, "tty filename too long");
> + }
> } else {
> int tty0 = open("/dev/tty0", O_WRONLY | O_CLOEXEC);
> char filename[16];
> @@ -536,6 +548,8 @@ 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);
> close(tty0);
> + if (snprintf(wl->tty_path, PATH_MAX, "%s", filename) >= PATH_MAX)
> + error(1, 0, "tty filename too long");
> }
>
> if (wl->tty < 0)
> @@ -555,6 +569,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. */
> + if (ioctl(wl->tty, VT_ACTIVATE, wl->ttynr))
> + error(1, errno, "failed to activate tty: %m\n");
If no tty was specified, so tty==0, wl->ttynr will be 0 and the ioctl
here will fail with ENXIO.
> +
> if (ioctl(wl->tty, KDGKBMODE, &wl->kb_mode))
> error(1, errno, "failed to get current keyboard mode: %m\n");
>
> @@ -744,8 +762,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];
> --
> 1.7.7.6
>
> --------------------------------------------------------------
> Intel Shannon Limited
> Registered in Ireland
> Registered Office: Collinstown Industrial Park, Leixlip, County Kildare
> Registered Number: 308263
> Business address: Dromore House, East Park, Shannon, Co. Clare
>
> This e-mail and any attachments may contain confidential material for the sole use of the intended recipient(s). Any review or distribution by others is strictly prohibited. If you are not the intended recipient, please contact the sender and delete all copies.
>
>
> _______________________________________________
> wayland-devel mailing list
> wayland-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/wayland-devel
More information about the wayland-devel
mailing list