[CRIU] [PATCH cr 02/13] parasite: add ability to get pid and tid

Andrey Vagin avagin at openvz.org
Tue Jun 19 07:53:06 EDT 2012


If we try to dump a process from another pid ns,
we have not another way to get its pid.

Signed-off-by: Andrey Vagin <avagin at openvz.org>
---
 cr-dump.c                  |    2 +-
 include/parasite-syscall.h |    4 ++--
 include/parasite.h         |    7 ++++++-
 parasite-syscall.c         |    4 +++-
 parasite.c                 |    6 ++++++
 5 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/cr-dump.c b/cr-dump.c
index 065c80e..2bebe95 100644
--- a/cr-dump.c
+++ b/cr-dump.c
@@ -1480,7 +1480,7 @@ static int dump_task_thread(struct parasite_ctl *parasite_ctl, struct pid *tid)
 	if (ret)
 		goto err_free;
 
-	ret = parasite_dump_tid_addr_seized(parasite_ctl, pid, &taddr);
+	ret = parasite_dump_thread_seized(parasite_ctl, pid, &taddr, &tid->pid);
 	if (ret) {
 		pr_err("Can't dump tid address for pid %d", pid);
 		goto err_free;
diff --git a/include/parasite-syscall.h b/include/parasite-syscall.h
index 6cf844e..4e91bd8 100644
--- a/include/parasite-syscall.h
+++ b/include/parasite-syscall.h
@@ -33,8 +33,8 @@ extern int parasite_dump_pages_seized(struct parasite_ctl *ctl,
 				      struct list_head *vma_area_list,
 				      struct cr_fdset *cr_fdset);
 struct parasite_dump_tid_addr;
-extern int parasite_dump_tid_addr_seized(struct parasite_ctl *ctl,
-					 pid_t pid, unsigned int **tid_add);
+extern int parasite_dump_thread_seized(struct parasite_ctl *ctl, pid_t pid,
+					unsigned int **tid_add, u32 *tid);
 
 extern int parasite_drain_fds_seized(struct parasite_ctl *ctl, int *fds, int *lfds, int nr_fds, char *flags);
 
diff --git a/include/parasite.h b/include/parasite.h
index 3796505..143f35c 100644
--- a/include/parasite.h
+++ b/include/parasite.h
@@ -73,12 +73,17 @@ struct parasite_dump_misc {
 	unsigned int		secbits;
 	unsigned long		brk;
 	k_rtsigset_t		blocked;
+
+	u32 pid;
+	u32 sid;
+	u32 pgid;
 };
 
 struct parasite_dump_tid_addr {
 	parasite_status_t	status;
 
-	unsigned int *tid_addr;
+	unsigned int		*tid_addr;
+	int			tid;
 };
 
 #define PARASITE_MAX_FDS	(PAGE_SIZE / sizeof(int))
diff --git a/parasite-syscall.c b/parasite-syscall.c
index 72a5a62..2abfeb8 100644
--- a/parasite-syscall.c
+++ b/parasite-syscall.c
@@ -416,7 +416,8 @@ static int parasite_set_logfd(struct parasite_ctl *ctl, pid_t pid)
 	return 0;
 }
 
-int parasite_dump_tid_addr_seized(struct parasite_ctl *ctl, pid_t pid, unsigned int **tid_addr)
+int parasite_dump_thread_seized(struct parasite_ctl *ctl, pid_t pid,
+					unsigned int **tid_addr, u32 *tid)
 {
 	struct parasite_dump_tid_addr args = { };
 	int ret;
@@ -425,6 +426,7 @@ int parasite_dump_tid_addr_seized(struct parasite_ctl *ctl, pid_t pid, unsigned
 			(parasite_status_t *)&args, sizeof(args));
 
 	*tid_addr = args.tid_addr;
+	*tid = args.tid;
 
 	return ret;
 }
diff --git a/parasite.c b/parasite.c
index 9aa68bd..1d550af 100644
--- a/parasite.c
+++ b/parasite.c
@@ -363,6 +363,10 @@ static int dump_misc(struct parasite_dump_misc *args)
 	args->brk = sys_brk(0);
 	args->blocked = old_blocked;
 
+	args->pid = sys_getpid();
+	args->sid = sys_getsid();
+	args->pgid = sys_getpgid();
+
 	return 0;
 }
 
@@ -377,6 +381,8 @@ static int dump_tid_addr(struct parasite_dump_tid_addr *args)
 		return ret;
 	}
 
+	args->tid = sys_gettid();
+
 	return 0;
 }
 
-- 
1.7.1



More information about the CRIU mailing list