[CRIU] [PATCH 1/2] tty: Make parasite to consider major and minors

Pavel Emelyanov xemul at parallels.com
Thu Oct 9 04:35:15 PDT 2014


On 10/07/2014 02:09 PM, Cyrill Gorcunov wrote:
> For example TIOCGPKT and TIOCGPTLCK are pty specific
> and should not be called for anything else (this
> will be needed for other kind of terminals).
> 
> Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
> ---
>  include/parasite-syscall.h |  2 +-
>  include/parasite.h         |  2 ++
>  parasite-syscall.c         |  4 ++-
>  pie/parasite.c             | 70 +++++++++++++++++++++++++++-------------------
>  tty.c                      |  2 +-
>  5 files changed, 48 insertions(+), 32 deletions(-)
> 
> diff --git a/include/parasite-syscall.h b/include/parasite-syscall.h
> index 67840fcc658e..abdb5f8c1670 100644
> --- a/include/parasite-syscall.h
> +++ b/include/parasite-syscall.h
> @@ -106,7 +106,7 @@ extern struct parasite_ctl *parasite_prep_ctl(pid_t pid,
>  					      struct vm_area_list *vma_area_list);
>  extern int parasite_map_exchange(struct parasite_ctl *ctl, unsigned long size);
>  
> -extern struct parasite_tty_args *parasite_dump_tty(struct parasite_ctl *ctl, int fd);
> +extern struct parasite_tty_args *parasite_dump_tty(struct parasite_ctl *ctl, int fd, int major, int minor);
>  
>  extern int parasite_init_threads_seized(struct parasite_ctl *ctl, struct pstree_item *item);
>  extern int parasite_fini_threads_seized(struct parasite_ctl *ctl);
> diff --git a/include/parasite.h b/include/parasite.h
> index 774eba0c6d31..e14e4e1c7dcf 100644
> --- a/include/parasite.h
> +++ b/include/parasite.h
> @@ -209,6 +209,8 @@ static inline int drain_fds_size(struct parasite_drain_fd *dfds)
>  
>  struct parasite_tty_args {
>  	int	fd;
> +	int	major;
> +	int	minor;
>  
>  	int	sid;
>  	int	pgrp;
> diff --git a/parasite-syscall.c b/parasite-syscall.c
> index 7cc1a84e0450..7a8d133a6a35 100644
> --- a/parasite-syscall.c
> +++ b/parasite-syscall.c
> @@ -715,12 +715,14 @@ int parasite_dump_misc_seized(struct parasite_ctl *ctl, struct parasite_dump_mis
>  	return 0;
>  }
>  
> -struct parasite_tty_args *parasite_dump_tty(struct parasite_ctl *ctl, int fd)
> +struct parasite_tty_args *parasite_dump_tty(struct parasite_ctl *ctl, int fd, int major, int minor)
>  {
>  	struct parasite_tty_args *p;
>  
>  	p = parasite_args(ctl, struct parasite_tty_args);
>  	p->fd = fd;
> +	p->major = major;
> +	p->minor = minor;
>  
>  	if (parasite_execute_daemon(PARASITE_CMD_DUMP_TTY, ctl) < 0)
>  		return NULL;
> diff --git a/pie/parasite.c b/pie/parasite.c
> index bab67f8db089..dc2c4b9d9a09 100644
> --- a/pie/parasite.c
> +++ b/pie/parasite.c
> @@ -6,6 +6,7 @@
>  #include <sys/mount.h>
>  #include <stdarg.h>
>  #include <sys/ioctl.h>
> +#include <linux/major.h>
>  
>  #include "syscall.h"
>  #include "parasite.h"
> @@ -317,6 +318,13 @@ static int parasite_dump_tty(struct parasite_tty_args *args)
>  {
>  	int ret;
>  
> +	args->sid = 0;
> +	args->pgrp = 0;
> +	args->st_pckt = 0;
> +	args->st_lock = 0;
> +	args->st_excl = 0;
> +	args->hangup = true;
> +
>  #ifndef TIOCGPKT
>  # define TIOCGPKT	_IOR('T', 0x38, int)
>  #endif
> @@ -329,44 +337,48 @@ static int parasite_dump_tty(struct parasite_tty_args *args)
>  # define TIOCGEXCL	_IOR('T', 0x40, int)
>  #endif
>  
> -	ret = tty_ioctl(args->fd, TIOCGSID, &args->sid);
> -	if (ret < 0)
> -		goto err;
> -
> -	ret = tty_ioctl(args->fd, TIOCGPGRP, &args->pgrp);
> -	if (ret < 0)
> -		goto err;
> -
> -	ret = tty_ioctl(args->fd, TIOCGPKT, &args->st_pckt);
> -	if (ret < 0)
> -		goto err;
> -
> -	ret = tty_ioctl(args->fd, TIOCGPTLCK, &args->st_lock);
> -	if (ret < 0)
> -		goto err;
> -
> -	ret = tty_ioctl(args->fd, TIOCGEXCL, &args->st_excl);
> -	if (ret < 0)
> -		goto err;
> +#define __tty_ioctl(cmd, arg)					\
> +	do {							\
> +		ret = tty_ioctl(args->fd, cmd, &arg);		\
> +		if (ret < 0) {					\
> +			if (ret == -ENOTTY)			\
> +				arg = 0;			\
> +			else if (ret == -EIO)			\
> +				goto err_io;			\
> +			else					\
> +				goto err;			\
> +		}						\
> +	} while (0)
> +
> +	__tty_ioctl(TIOCGSID,	args->sid);
> +	__tty_ioctl(TIOCGPGRP,	args->pgrp);
> +	switch (args->major) {
> +	case TTYAUX_MAJOR:
> +		if (args->minor == 0 || args->minor == 2) {
> +			__tty_ioctl(TIOCGPKT,	args->st_pckt);
> +			__tty_ioctl(TIOCGPTLCK,	args->st_lock);
> +		}
> +		break;
> +	case UNIX98_PTY_MASTER_MAJOR ... (UNIX98_PTY_MASTER_MAJOR + UNIX98_PTY_MAJOR_COUNT - 1):
> +	case UNIX98_PTY_SLAVE_MAJOR:
> +		__tty_ioctl(TIOCGPKT,	args->st_pckt);
> +		__tty_ioctl(TIOCGPTLCK,	args->st_lock);
> +		break;
> +	}

Please, don't re-introduce this switch() for the 3rd time. Make
all the decisions in files.c and go to parasite with simple questions :)

> +	__tty_ioctl(TIOCGEXCL,	args->st_excl);
>  
>  	args->hangup = false;
>  	return 0;
>  
>  err:
> -	if (ret != -EIO) {
> -		pr_err("TTY: Can't get sid/pgrp: %d\n", ret);
> -		return -1;
> -	}
> +	pr_err("tty: Can't fetch params: err = %d\n", ret);
> +	return -1;
>  
> +err_io:
>  	/* kernel reports EIO for get ioctls on pair-less ptys */
> -	args->sid = 0;
> -	args->pgrp = 0;
> -	args->st_pckt = 0;
> -	args->st_lock = 0;
> -	args->st_excl = 0;
>  	args->hangup = true;
> -
>  	return 0;
> +#undef __tty_ioctl
>  }
>  
>  #ifdef CONFIG_VDSO
> diff --git a/tty.c b/tty.c
> index edbe85e7505a..e86c60f3b91d 100644
> --- a/tty.c
> +++ b/tty.c
> @@ -1072,7 +1072,7 @@ static int dump_pty_info(int lfd, u32 id, const struct fd_parms *p, int major, i
>  	BUILD_BUG_ON(sizeof(termios.c_cc) != sizeof(void *));
>  	BUILD_BUG_ON((sizeof(termios.c_cc) * TERMIOS_NCC) < sizeof(t.c_cc));
>  
> -	pti = parasite_dump_tty(p->ctl, p->fd);
> +	pti = parasite_dump_tty(p->ctl, p->fd, major, minor);
>  	if (!pti)
>  		return -1;
>  
> 



More information about the CRIU mailing list