[CRIU] Re: [PATCH 14/14] tty: Migrate tty slave peer connection

Pavel Emelyanov xemul at parallels.com
Mon Oct 8 11:09:56 EDT 2012


On 10/06/2012 10:58 AM, Cyrill Gorcunov wrote:
> 
> In case if we've dumped a slave peer only (say a user dumped
> `top' application) we should migrate it on current active
> terminal, which barely an own standart stream prepared for us
> by file engine.
> 
> Note only one external slave peer is allowed simply because
> otherwise we can't distinguish which indices should be used
> for each of them.
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  cr-dump.c     |    2 +-
>  include/tty.h |    2 +-
>  tty.c         |  101 ++++++++++++++++++++++++++++++++++++++++++++------------
>  3 files changed, 81 insertions(+), 24 deletions(-)
> 


> @@ -541,31 +552,67 @@ static int receive_tty(struct tty_info *info)
>  	return fd;
>  }
>  
> -static int pty_open_fake_ptmx(struct tty_info *slave)
> +static int pty_open_unpaired_slave(struct file_desc *d, struct tty_info *slave)
>  {
>  	int master = -1, ret = -1, fd = -1;
> -	char pts_name[64];
>  
> -	snprintf(pts_name, sizeof(pts_name), PTS_FMT, slave->tie->pty->index);
> +	/*
> +	 * We may have 2 cases here:
> +	 *
> +	 *  - @termios present thus it's external slave peer
> +	 *    which should be migrated on current pts
> +	 *
> +	 *  - no @termios means the peer is dead so we need
> +	 *    a fake master peer
> +	 */
>  
> -	master = pty_open_ptmx_index(O_RDONLY, slave->tie->pty->index);
> -	if (master < 0) {
> -		pr_perror("Can't open fale %x (index %d)",
> -			  slave->tfe->id, slave->tie->pty->index);
> -		return -1;
> -	}
> +	if (likely(slave->tie->termios)) {
> +		fd = dup(get_service_fd(SELF_STDIN_OFF));
> +		if (fd < 0) {
> +			pr_perror("Can't dup SELF_STDIN_OFF");
> +			return -1;
> +		}
> +		pr_info("Migrated slave peer %x -> to fd %d\n",
> +			slave->tfe->id, fd);
> +	} else {
> +		char pts_name[64];
>  
> -	unlock_pty(master);
> +		snprintf(pts_name, sizeof(pts_name), PTS_FMT, slave->tie->pty->index);
> +
> +		master = pty_open_ptmx_index(O_RDONLY, slave->tie->pty->index);
> +		if (master < 0) {
> +			pr_perror("Can't open fale %x (index %d)",
> +				  slave->tfe->id, slave->tie->pty->index);
> +			return -1;
> +		}
> +
> +		unlock_pty(master);
> +
> +		fd = open(pts_name, slave->tfe->flags);
> +		if (fd < 0) {
> +			pr_perror("Can't open slave %s", pts_name);
> +			goto err;
> +		}
>  
> -	fd = open(pts_name, slave->tfe->flags);
> -	if (fd < 0) {
> -		pr_perror("Can't open slave %s", pts_name);
> -		goto err;
>  	}
>  
>  	if (restore_tty_params(fd, slave))
>  		goto err;
>  
> +	/*
> +	 * If tty is migrated we need to set its group
> +	 * to the parent group, because signals on key
> +	 * presses are delivered to a group of terminal.
> +	 *
> +	 * Note, at this point the group/session should
> +	 * be already restored properly thus we can simply
> +	 * use syscalls intead of lookup via process tree.
> +	 */
> +	if (likely(slave->tie->termios)) {
> +		if (tty_set_prgp(fd, getpgid(getppid())))
> +			goto err;
> +	}
> +
>  	if (pty_open_slaves(slave))
>  		goto err;
>  

Split this, it's unreadable.


More information about the CRIU mailing list