All of lore.kernel.org
 help / color / mirror / Atom feed
From: Leonid Snegirev <leo-n4oKp6kCDthKyFCjRbgQbg@public.gmane.org>
To: containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org
Cc: "Nikita V. Youshchenko" <yoush-/llMDZXAvAOHXe+LvDLADg@public.gmane.org>
Subject: [PATCH] c/r: restore tty pgrp properly
Date: Thu, 08 Apr 2010 15:50:56 +0000	[thread overview]
Message-ID: <4BBDFB60.2080505@lvk.cs.msu.su> (raw)

When restoring without keeping old PIDs, it is incorrect to set tty pgrp
to same numeric value as it was at checkpoint time. This pgrp may not
exist at restore time, and do_tiocspgrp() call from restore_signal()
returns -ESRCH.

This patch tries to solve this by searching process with pgid equal to 
tty->pgrp
at checkpoint time, save index of that process in checkpoint, and at use 
restore-time
pgid of that process to set tty->pgrp at restore.

Signed-off-by: Leonid Snegirev <leo-n4oKp6kCDthKyFCjRbgQbg@public.gmane.org>
---
 checkpoint/signal.c            |   16 +++++++++++++---
 include/linux/checkpoint_hdr.h |    2 +-
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/checkpoint/signal.c b/checkpoint/signal.c
index 9d0e9c3..9c90e96 100644
--- a/checkpoint/signal.c
+++ b/checkpoint/signal.c
@@ -323,6 +323,7 @@ static int checkpoint_signal(struct ckpt_ctx *ctx, 
struct task_struct *t)
     cputime_t cputime;
     unsigned long flags;
     int i, ret = 0;
+    pid_t tty_pgrp, prgp_i;
 
     h = ckpt_hdr_get_type(ctx, sizeof(*h), CKPT_HDR_SIGNAL);
     if (!h)
@@ -411,7 +412,16 @@ static int checkpoint_signal(struct ckpt_ctx *ctx, 
struct task_struct *t)
         if (tty) {
             /* irq is already disabled */
             spin_lock(&tty->ctrl_lock);
-            h->tty_pgrp = ckpt_pid_nr(ctx, tty->pgrp);
+            h->tty_pgrp_owner = -1;
+            tty_pgrp = ckpt_pid_nr(ctx, tty->pgrp);
+            for (i = 0; i < ctx->nr_tasks; i++) {
+                pgrp_i = task_pgrp_nr_ns(ctx->tasks_arr[i],
+                        ctx->root_nsproxy->pid_ns);
+                if (tty_pgrp == pgrp_i) {
+                    h->tty_pgrp_owner = i;
+                    break;
+                }
+            }    
             spin_unlock(&tty->ctrl_lock);
             tty_kref_put(tty);
         }
@@ -537,13 +547,13 @@ static int restore_signal(struct ckpt_ctx *ctx)
         if (ret < 0)
             goto out;
         /* now restore the foreground group (job control) */
-        if (h->tty_pgrp) {
+        if (h->tty_pgrp_owner != -1) {
             /*
              * If tty_pgrp == CKPT_PID_NULL, below will
              * fail, so no need for explicit test
              */
             ret = do_tiocspgrp(tty, tty_pair_get_tty(tty),
-                       h->tty_pgrp);
+                    ctx->pids_arr[h->tty_pgrp_owner].vpgid);
             if (ret < 0)
                 goto out;
         }
diff --git a/include/linux/checkpoint_hdr.h b/include/linux/checkpoint_hdr.h
index 41412d1..535e138 100644
--- a/include/linux/checkpoint_hdr.h
+++ b/include/linux/checkpoint_hdr.h
@@ -898,7 +898,7 @@ struct ckpt_hdr_signal {
     __u64 it_prof_incr;
     /* tty */
     __s32 tty_objref;
-    __s32 tty_pgrp;
+    __u32 tty_pgrp_owner;
     __s32 tty_old_pgrp;
 } __attribute__((aligned(8)));
 
-- 
1.5.6.5

             reply	other threads:[~2010-04-08 15:50 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-08 15:50 Leonid Snegirev [this message]
     [not found] ` <4BBDFB60.2080505-n4oKp6kCDthKyFCjRbgQbg@public.gmane.org>
2010-04-08 21:00   ` [PATCH] c/r: restore tty pgrp properly Matt Helsley
     [not found]     ` <20100408210008.GF3345-52DBMbEzqgQ/wnmkkaCWp/UQ3DHhIser@public.gmane.org>
2010-04-09  3:23       ` Oren Laadan
2010-04-09  7:47       ` Nikita V. Youshchenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BBDFB60.2080505@lvk.cs.msu.su \
    --to=leo-n4okp6kcdthkyfcjrbgqbg@public.gmane.org \
    --cc=containers-cunTk1MwBs9QetFLy7KEm3xJsTq8ys+cHZ5vskTnxNA@public.gmane.org \
    --cc=yoush-/llMDZXAvAOHXe+LvDLADg@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.