[CRIU] [PATCH 2/9] restore: get real pid for each task
Andrey Vagin
avagin at openvz.org
Thu Sep 12 09:24:34 EDT 2013
I remember that we decided to not add a new service fd here,
I'm going to fix that.
Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
cr-restore.c | 33 +++++++++++++++++++++++++++++++--
files.c | 1 +
include/crtools.h | 1 +
3 files changed, 33 insertions(+), 2 deletions(-)
diff --git a/cr-restore.c b/cr-restore.c
index 801425d..8517672 100644
--- a/cr-restore.c
+++ b/cr-restore.c
@@ -968,7 +968,7 @@ static inline int fork_with_pid(struct pstree_item *item)
if (ret < 0)
pr_perror("Can't fork for %d", pid);
- if (ca.clone_flags & CLONE_NEWPID)
+ if (item == root_item)
item->pid.real = ret;
if (opts.pidfile && root_item == item)
@@ -1161,6 +1161,24 @@ static int restore_task_with_children(void *_arg)
current = ca->item;
+ if (current != root_item) {
+ char buf[PATH_MAX];
+ int fd;
+
+ /* Determine PID in CRIU's namespace */
+ fd = get_service_fd(CR_PROC_FD_OFF);
+ if (fd < 0)
+ exit(1);
+
+ if (readlinkat(fd, "self", buf, sizeof(buf)) < 0) {
+ pr_perror("Unable to read the /proc/self link");
+ exit(1);
+ }
+ current->pid.real = atoi(buf);
+ pr_debug("PID: real %d virt %d\n",
+ current->pid.real, current->pid.virt);
+ }
+
if ( !(ca->clone_flags & CLONE_FILES))
close_safe(&ca->fd);
@@ -1305,9 +1323,20 @@ static int restore_switch_stage(int next_stage)
static int restore_root_task(struct pstree_item *init)
{
- int ret;
+ int ret, fd;
struct sigaction act, old_act;
+ fd = open("/proc", O_DIRECTORY | O_RDONLY);
+ if (fd < 0) {
+ pr_perror("Unable to open /proc");
+ return -1;
+ }
+
+ ret = install_service_fd(CR_PROC_FD_OFF, fd);
+ close(fd);
+ if (ret < 0)
+ return -1;
+
ret = sigaction(SIGCHLD, NULL, &act);
if (ret < 0) {
pr_perror("sigaction() failed");
diff --git a/files.c b/files.c
index 8193d59..e194a22 100644
--- a/files.c
+++ b/files.c
@@ -933,6 +933,7 @@ int prepare_fds(struct pstree_item *me)
if (me->rst->fdt)
futex_inc_and_wake(&me->rst->fdt->fdt_lock);
out:
+ close_service_fd(CR_PROC_FD_OFF);
tty_fini_fds();
return ret;
}
diff --git a/include/crtools.h b/include/crtools.h
index 3c90b29..31d411e 100644
--- a/include/crtools.h
+++ b/include/crtools.h
@@ -59,6 +59,7 @@ enum sfd_type {
CTL_TTY_OFF,
SELF_STDIN_OFF,
PARENT_FD_OFF,
+ CR_PROC_FD_OFF,
SERVICE_FD_MAX
};
--
1.8.3.1
More information about the CRIU
mailing list