[CRIU] [PATCH 11/11] tty: Add dump and restore of /dev/console opened

Pavel Emelyanov xemul at parallels.com
Mon Sep 29 11:31:59 PDT 2014


> @@ -1214,6 +1256,111 @@ static int dump_one_pty(int lfd, u32 id, const struct fd_parms *p, int major, in
>  	return ret;
>  }
>  
> +static int dump_console_info(int lfd, u32 id, const struct fd_parms *p, int major, int minor, int index)
> +{

How many code below coincide with the dump_pty_info?

> +	TtyInfoEntry info		= TTY_INFO_ENTRY__INIT;
> +	TermiosEntry termios		= TERMIOS_ENTRY__INIT;
> +	TermiosEntry termios_locked	= TERMIOS_ENTRY__INIT;
> +	WinsizeEntry winsize		= WINSIZE_ENTRY__INIT;
> +	struct tty_dump_info *dinfo;
> +
> +	struct termios t;
> +	struct winsize w;
> +
> +	int ret = -1;
> +
> +	/*
> +	 * Make sure the structures the system provides us
> +	 * correlates well with protobuf templates.
> +	 */
> +	BUILD_BUG_ON(ARRAY_SIZE(t.c_cc) < TERMIOS_NCC);
> +	BUILD_BUG_ON(sizeof(termios.c_cc) != sizeof(void *));
> +	BUILD_BUG_ON((sizeof(termios.c_cc) * TERMIOS_NCC) < sizeof(t.c_cc));
> +
> +	dinfo = xmalloc(sizeof(*dinfo));
> +	if (!dinfo)
> +		return -1;
> +
> +	/*
> +	 * Make sure no @sid and @pgrp here since
> +	 * that's how we check if we need to validate
> +	 * this particular peer as a contol terminal
> +	 * (which system console can't be).
> +	 */
> +	dinfo->id		= id;
> +	dinfo->sid		= 0;
> +	dinfo->pgrp		= 0;
> +	dinfo->fd		= p->fd;
> +	dinfo->major		= major;
> +	dinfo->minor		= minor;
> +
> +	list_add_tail(&dinfo->list, &all_ttys);
> +
> +	info.id			= id;
> +	info.type		= TTY_TYPE__CONSOLE;
> +	info.sid		= 0;
> +	info.pgrp		= 0;
> +	info.rdev		= p->stat.st_rdev;
> +
> +	info.termios		= &termios;
> +	info.termios_locked	= &termios_locked;
> +	info.winsize		= &winsize;
> +
> +	termios.n_c_cc		= TERMIOS_NCC;
> +	termios.c_cc		= xmalloc(pb_repeated_size(&termios, c_cc));
> +
> +	termios_locked.n_c_cc	= TERMIOS_NCC;
> +	termios_locked.c_cc	= xmalloc(pb_repeated_size(&termios_locked, c_cc));
> +
> +	if (!termios.c_cc || !termios_locked.c_cc)
> +		goto out;
> +
> +	memzero(&t, sizeof(t));
> +	if (ioctl(lfd, TCGETS, &t) < 0) {
> +		pr_perror("Can't get tty params on %x", id);
> +		goto out;
> +	}
> +	termios_copy(&termios, &t);
> +
> +	memzero(&t, sizeof(t));
> +	if (ioctl(lfd, TIOCGLCKTRMIOS, &t) < 0) {
> +		pr_perror("Can't get tty locked params on %x", id);
> +		goto out;
> +	}
> +	termios_copy(&termios_locked, &t);
> +
> +	memzero(&w, sizeof(w));
> +	if (ioctl(lfd, TIOCGWINSZ, &w) < 0) {
> +		pr_perror("Can't get tty window params on %x", id);
> +		goto out;
> +	}
> +	winsize_copy(&winsize, &w);
> +
> +	ret = pb_write_one(fdset_fd(glob_fdset, CR_FD_TTY_INFO), &info, PB_TTY_INFO);
> +out:
> +	xfree(termios.c_cc);
> +	xfree(termios_locked.c_cc);
> +	return ret;
> +}
> +



More information about the CRIU mailing list