From 563efd3f25c6c3634dfcb2243379fbc5670ad2f5 Mon Sep 17 00:00:00 2001 From: Kirill Tkhai Date: Fri, 5 May 2017 19:13:04 +0300 Subject: [PATCH] pstree: Change type of init_pstree_helper() and check for parent This is refactoring, which will be used in next patches. BUG_ON() just to mention that parent must be set before call of this function. v5: New Signed-off-by: Kirill Tkhai Signed-off-by: Andrei Vagin --- criu/files-reg.c | 5 ++++- criu/include/pstree.h | 2 +- criu/pstree.c | 14 +++++++++++--- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/criu/files-reg.c b/criu/files-reg.c index 29a588ccd..10165d61d 100644 --- a/criu/files-reg.c +++ b/criu/files-reg.c @@ -532,13 +532,16 @@ static int collect_remap_dead_process(struct reg_file_info *rfi, return 0; } - init_pstree_helper(helper); helper->sid = root_item->sid; helper->pgid = root_item->pgid; helper->pid->ns[0].virt = rfe->remap_id; helper->parent = root_item; helper->ids = root_item->ids; + if (init_pstree_helper(helper)) { + pr_err("Can't init helper\n"); + return -1; + } list_add_tail(&helper->sibling, &root_item->children); pr_info("Added a helper for restoring /proc/%d\n", vpid(helper)); diff --git a/criu/include/pstree.h b/criu/include/pstree.h index b082e3586..34f9bbe6f 100644 --- a/criu/include/pstree.h +++ b/criu/include/pstree.h @@ -87,7 +87,7 @@ static inline bool task_alive(struct pstree_item *i) extern void free_pstree(struct pstree_item *root_item); extern struct pstree_item *__alloc_pstree_item(bool rst); #define alloc_pstree_item() __alloc_pstree_item(false) -extern void init_pstree_helper(struct pstree_item *ret); +extern int init_pstree_helper(struct pstree_item *ret); extern struct pstree_item *lookup_create_item(pid_t pid); extern void pstree_insert_pid(struct pid *pid_node); diff --git a/criu/pstree.c b/criu/pstree.c index a52ec553a..975412d85 100644 --- a/criu/pstree.c +++ b/criu/pstree.c @@ -229,11 +229,13 @@ struct pstree_item *__alloc_pstree_item(bool rst) return item; } -void init_pstree_helper(struct pstree_item *ret) +int init_pstree_helper(struct pstree_item *ret) { + BUG_ON(!ret->parent); ret->pid->state = TASK_HELPER; rsti(ret)->clone_flags = CLONE_FILES | CLONE_FS; task_entries->nr_helpers++; + return 0; } /* Deep first search on children */ @@ -675,7 +677,10 @@ static int prepare_pstree_ids(void) helper->ids = root_item->ids; list_add_tail(&helper->sibling, &helpers); } - init_pstree_helper(helper); + if (init_pstree_helper(helper)) { + pr_err("Can't init helper\n"); + return -1; + } pr_info("Add a helper %d for restoring SID %d\n", vpid(helper), helper->sid); @@ -763,13 +768,16 @@ static int prepare_pstree_ids(void) continue; helper = pid->item; - init_pstree_helper(helper); helper->sid = item->sid; helper->pgid = item->pgid; helper->pid->ns[0].virt = item->pgid; helper->parent = item; helper->ids = item->ids; + if (init_pstree_helper(helper)) { + pr_err("Can't init helper\n"); + return -1; + } list_add(&helper->sibling, &item->children); rsti(item)->pgrp_leader = helper;