criu restore: mismatched pid debug

Submitted by Kir Kolyshkin on April 25, 2017, 10:19 p.m.

Details

Message ID 20170425221913.19674-1-kir@openvz.org
State New
Series "criu restore: mismatched pid debug"
Headers show

Commit Message

Kir Kolyshkin April 25, 2017, 10:19 p.m.
[This sender failed our fraud detection checks and may not be who they appear to be. Learn about spoofing at http://aka.ms/LearnAboutSpoofing]

Sometimes we fail to restore because of PID mismatch. In this case,
we would like to know who the hell has taken our PID. Let's print
a process tree, which looks something like this (this example is
obviously from the host):

1 /usr/lib/systemd/systemd --switched-root --system --deserialize 24
\_482 /usr/lib/systemd/systemd-journald
\_746 /sbin/auditd
  \_748 /sbin/audispd
    \_751 /usr/sbin/sedispatch
\_769 /usr/lib/systemd/systemd-logind

This is debug for https://github.com/xemul/criu/issues/282.

Signed-off-by: Kir Kolyshkin <kir@openvz.org>
---
 criu/cr-restore.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 45 insertions(+)

--
2.9.3

Patch hide | download patch | download mbox

diff --git a/criu/cr-restore.c b/criu/cr-restore.c
index e78b72e..91874c0 100644
--- a/criu/cr-restore.c
+++ b/criu/cr-restore.c
@@ -1323,6 +1323,50 @@  static int create_children_and_session(void)
        return 0;
 }

+static int show_pstree(pid_t p, int level)
+{
+       pid_t *ch;
+       int i, nr_ch, ret;
+       char cmd[80];
+       int fd, len, llen;
+
+       /* limit output to a single line on a terminal */
+       llen = 79 - printf("%*s%d ", level*2, level ? "\\_" : "", p);
+
+       fd = open_proc(p, "cmdline");
+       if (fd < 0)
+               return -1;
+       len = read(fd, cmd, sizeof(cmd) - 1);
+       close(fd);
+
+       if (len > 0) {
+               if (len > llen) {
+                       len = llen;
+                       // ellipsis
+                       cmd[len - 1] = '.';
+                       cmd[len - 2] = '.';
+               }
+               for (i = 0; i < len; i++)
+                       if (cmd[i] == '\0')
+                               cmd[i] = ' ';
+               cmd[len] = '\0';
+               puts(cmd);
+       } else {
+               puts("???");
+       }
+
+       ret = parse_children(p, &ch, &nr_ch);
+       if (ret < 0)
+               return ret;
+
+       for (i = 0; i < nr_ch; i++) {
+               show_pstree(ch[i], level+1);
+       }
+
+       xfree(ch);
+       return 0;
+}
+
 static int restore_task_with_children(void *_arg)
 {
        struct cr_clone_arg *ca = _arg;
@@ -1351,6 +1395,7 @@  static int restore_task_with_children(void *_arg)
        pid = getpid();
        if (vpid(current) != pid) {
                pr_err("Pid %d do not match expected %d\n", pid, vpid(current));
+               show_pstree(1, 0);
                set_task_cr_err(EEXIST);
                goto err;
        }

Comments

Kir Kolyshkin April 28, 2017, 2:48 a.m.
It says "patch does not apply" and I am not sure why -- I have just 
rechecked it works for current tip of criu-dev.


On 04/25/2017 03:43 PM, Patchwork wrote:
> == Series Details ==
>
> Series: criu restore: mismatched pid debug
> URL   : https://patchwork.criu.org/series/1493/
> State : failure
>
> == Logs ==
>
> For more details see: https://ci.openvz.org/job/CRIU/job/criu-patchwork/1314//console