[5/5] tty: allocate a separate tty info id for each external tty

Submitted by Andrey Vagin on Sept. 20, 2018, 10:22 p.m.

Details

Message ID 20180920221817.29697-6-avagin@virtuozzo.com
State New
Series "files: save inherited file descriptors in fdstore"
Headers show

Commit Message

Andrey Vagin Sept. 20, 2018, 10:22 p.m.
Otherwise all external tty-s will share the same tty info,
what is obviously wrong.

Cc: Cyrill Gorcunov <gorcunov@openvz.org>
Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
---
 criu/tty.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/criu/tty.c b/criu/tty.c
index 214d97a8e..7fd4d86b1 100644
--- a/criu/tty.c
+++ b/criu/tty.c
@@ -2005,6 +2005,7 @@  static int dump_one_tty(int lfd, u32 id, const struct fd_parms *p)
 	TtyFileEntry e = TTY_FILE_ENTRY__INIT;
 	int ret = 0, index = -1;
 	struct tty_driver *driver;
+	static int idx = 0;
 
 	pr_info("Dumping tty %d with id %#x\n", lfd, id);
 
@@ -2012,7 +2013,7 @@  static int dump_one_tty(int lfd, u32 id, const struct fd_parms *p)
 	if (driver->fd_get_index)
 		index = driver->fd_get_index(lfd, p);
 	else
-		index = driver->index;
+		index = ++idx;
 
 	if (index == INDEX_ERR) {
 		pr_info("Can't obtain index on tty %d id %#x\n", lfd, id);

Comments

Cyrill Gorcunov Sept. 21, 2018, 9:02 a.m.
On Thu, Sep 20, 2018 at 10:22:38PM +0000, Andrey Vagin wrote:
> Otherwise all external tty-s will share the same tty info,
> what is obviously wrong.
> 
> Cc: Cyrill Gorcunov <gorcunov@openvz.org>
> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
> ---
>  criu/tty.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/criu/tty.c b/criu/tty.c
> index 214d97a8e..7fd4d86b1 100644
> --- a/criu/tty.c
> +++ b/criu/tty.c
> @@ -2005,6 +2005,7 @@ static int dump_one_tty(int lfd, u32 id, const struct fd_parms *p)
>  	TtyFileEntry e = TTY_FILE_ENTRY__INIT;
>  	int ret = 0, index = -1;
>  	struct tty_driver *driver;
> +	static int idx = 0;
>  
>  	pr_info("Dumping tty %d with id %#x\n", lfd, id);
>  
> @@ -2012,7 +2013,7 @@ static int dump_one_tty(int lfd, u32 id, const struct fd_parms *p)
>  	if (driver->fd_get_index)
>  		index = driver->fd_get_index(lfd, p);
>  	else
> -		index = driver->index;
> +		index = ++idx;
>  
>  	if (index == INDEX_ERR) {
>  		pr_info("Can't obtain index on tty %d id %#x\n", lfd, id);

I think there is an issue: the pty indices are going in pairs starting
from base 0, and here we can suddently overwrite it. Most likely we need
either provide fd_get_index for ext terminals with own numbering base
either simply skip carrying terminus info into image for such terminal
impliying that the caller already configured fd for us.