[CRIU] [PATCH 02/15] pstree: more pstree-related helpers

Stanislav Kinsburskiy skinsbursky at virtuozzo.com
Thu Dec 3 05:28:47 PST 2015


This patch introduces three helpers:
1) pstree_item_by_real() - search for pstree item by real pid.
2) pstree_item_by_virt() - search for pstree item by virtual pid.
3) pid_to_virt() - return virtual pis by real one.

Signed-off-by: Stanislav Kinsburskiy <skinsbursky at virtuozzo.com>
---
 include/pstree.h |    5 +++++
 pstree.c         |   33 +++++++++++++++++++++++++++++----
 2 files changed, 34 insertions(+), 4 deletions(-)

diff --git a/include/pstree.h b/include/pstree.h
index 0c91471..47ce676 100644
--- a/include/pstree.h
+++ b/include/pstree.h
@@ -78,6 +78,11 @@ extern bool restore_before_setsid(struct pstree_item *child);
 extern int prepare_pstree(void);
 
 extern int dump_pstree(struct pstree_item *root_item);
+
+struct pstree_item *pstree_item_by_real(pid_t virt);
+struct pstree_item *pstree_item_by_virt(pid_t virt);
+
+extern int pid_to_virt(pid_t pid);
 extern bool pid_in_pstree(pid_t pid);
 
 struct task_entries;
diff --git a/pstree.c b/pstree.c
index 116b5e7..d6b6794 100644
--- a/pstree.c
+++ b/pstree.c
@@ -778,14 +778,39 @@ bool restore_before_setsid(struct pstree_item *child)
 	return false;
 }
 
-bool pid_in_pstree(pid_t pid)
+struct pstree_item *pstree_item_by_virt(pid_t virt)
 {
 	struct pstree_item *item;
 
 	for_each_pstree_item(item) {
-		if (item->pid.real == pid)
-			return true;
+		if (item->pid.virt == virt)
+			return item;
 	}
+	return NULL;
+}
 
-	return false;
+struct pstree_item *pstree_item_by_real(pid_t real)
+{
+	struct pstree_item *item;
+
+	for_each_pstree_item(item) {
+		if (item->pid.real == real)
+			return item;
+	}
+	return NULL;
+}
+
+int pid_to_virt(pid_t real)
+{
+	struct pstree_item *item;
+
+	item = pstree_item_by_real(real);
+	if (item)
+		return item->pid.virt;
+	return 0;
+}
+
+bool pid_in_pstree(pid_t pid)
+{
+	return pstree_item_by_real(pid) != NULL;
 }



More information about the CRIU mailing list