[CRIU] Re: [PATCH 2/3] tty: Fix tty inheritance in case if zero
sid fetched
Cyrill Gorcunov
gorcunov at openvz.org
Fri Oct 26 04:33:32 EDT 2012
On Fri, Oct 26, 2012 at 12:12:53PM +0400, Pavel Emelyanov wrote:
>
> This also tosses the code around.
> Plz, split into two -- fix and toss.
These three instead of this one.
-------------- next part --------------
>From cc31bbf79c1bcf207081668aec196f153e84f7ac Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Fri, 26 Oct 2012 12:28:38 +0400
Subject: [PATCH 1/3] tty: Lookup for controlling tty iif sid provided
This is rather a code tossing for the next patch.
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
tty.c | 18 +++++++++++-------
1 files changed, 11 insertions(+), 7 deletions(-)
diff --git a/tty.c b/tty.c
index d3d1576..562952d 100644
--- a/tty.c
+++ b/tty.c
@@ -682,15 +682,19 @@ static int tty_find_restoring_task(struct tty_info *info)
{
struct pstree_item *item;
- if (info->tie->sid == 0)
+ if (info->tie->sid) {
+ pr_info("Set a control terminal %x to %d\n",
+ info->tfe->id, info->tie->sid);
+
+ for_each_pstree_item(item) {
+ if (item->sid == info->tie->sid)
+ return prepare_ctl_tty(item->pid.virt,
+ item->rst,
+ info->tfe->id);
+ }
+ } else
return 0;
- pr_info("Set a control terminal to %d\n", info->tie->sid);
-
- for_each_pstree_item(item)
- if (item->sid == info->tie->sid)
- return prepare_ctl_tty(item->pid.virt, item->rst, info->tfe->id);
-
if (opts.shell_job && !pty_is_master(info)) {
info->tie->sid = info->tie->pgrp = INHERIT_SID;
return 0;
--
1.7.7.6
-------------- next part --------------
>From d054e96fef856c5e00185eaf1d0c7a0ea44659a5 Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Fri, 26 Oct 2012 12:31:25 +0400
Subject: [PATCH 2/3] tty: Fix tty inheritance in case if zero sid fetched
In case if at checkpoint time we've fetched zero sid
associated with tty peer it doesn't obligatory means
that we've met a hangig up terminal, in particular
zero sid may be obtained if the slave peer do not
belong to the session the task run in but inherited
from the parent. Thus if --shell-job passed we should
handle such situation gracefully.
[ https://bugzilla.openvz.org/show_bug.cgi?id=2405 ]
Reported-by: Andrey Vagin <avagin at openvz.org>
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
tty.c | 14 +++++++++++++-
1 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/tty.c b/tty.c
index 562952d..eaf920d 100644
--- a/tty.c
+++ b/tty.c
@@ -398,6 +398,11 @@ static bool pty_is_master(struct tty_info *info)
return info->major == TTYAUX_MAJOR;
}
+static bool pty_is_hanged(struct tty_info *info)
+{
+ return info->tie->sid == 0 && info->tie->termios == NULL;
+}
+
static void tty_show_pty_info(char *prefix, struct tty_info *info)
{
pr_info("%s type %s id %#x index %d (master %d sid %d pgrp %d)\n",
@@ -692,8 +697,15 @@ static int tty_find_restoring_task(struct tty_info *info)
item->rst,
info->tfe->id);
}
- } else
+ }
+
+ /*
+ * Hanged up terminals require a fake master peer.
+ */
+ if (pty_is_hanged(info)) {
+ pr_debug("Hanged up terminal id %x\n", info->tfe->id);
return 0;
+ }
if (opts.shell_job && !pty_is_master(info)) {
info->tie->sid = info->tie->pgrp = INHERIT_SID;
--
1.7.7.6
-------------- next part --------------
>From 5e2bde45d5f0f5e8d51e7fcb3699510fdc2f718c Mon Sep 17 00:00:00 2001
From: Cyrill Gorcunov <gorcunov at openvz.org>
Date: Fri, 26 Oct 2012 12:32:10 +0400
Subject: [PATCH 3/3] tty: Add some comments in tty_find_restoring_task
Signed-off-by: Cyrill Gorcunov <gorcunov at openvz.org>
---
tty.c | 4 ++++
1 files changed, 4 insertions(+), 0 deletions(-)
diff --git a/tty.c b/tty.c
index eaf920d..773c4c6 100644
--- a/tty.c
+++ b/tty.c
@@ -707,7 +707,11 @@ static int tty_find_restoring_task(struct tty_info *info)
return 0;
}
+ /*
+ * We can only inherit one slave peer.
+ */
if (opts.shell_job && !pty_is_master(info)) {
+ pr_info("Inherit terminal for id %x\n", info->tfe->id);
info->tie->sid = info->tie->pgrp = INHERIT_SID;
return 0;
}
--
1.7.7.6
More information about the CRIU
mailing list