2
0
mirror of https://github.com/checkpoint-restore/criu synced 2025-08-22 01:51:51 +00:00

pstree: Add has_children function

Currently, parallel restore only focuses on the single-process
situation. Therefore, it needs an interface to know if there is only one
process to restore. This patch adds a `has_children` function in
`pstree.h` and replaces some existing implementations with this
function.

Signed-off-by: Yanning Yang <yangyanning@sjtu.edu.cn>
This commit is contained in:
Yanning Yang 2024-12-10 12:34:14 +00:00 committed by Andrei Vagin
parent 4ba058060c
commit 0a274b6afa
4 changed files with 10 additions and 4 deletions

View File

@ -1396,7 +1396,7 @@ static int dump_zombies(void)
item->sid = pps_buf.sid;
item->pgid = pps_buf.pgid;
BUG_ON(!list_empty(&item->children));
BUG_ON(has_children(item));
if (!item->sid) {
pr_err("A session leader of zombie process %d(%d) is outside of its pid namespace\n",

View File

@ -104,6 +104,7 @@ extern void pstree_insert_pid(struct pid *pid_node);
extern struct pid *pstree_pid_by_virt(pid_t pid);
extern struct pstree_item *root_item;
extern bool has_children(struct pstree_item *item);
extern struct pstree_item *pstree_item_next(struct pstree_item *item);
#define for_each_pstree_item(pi) for (pi = root_item; pi != NULL; pi = pstree_item_next(pi))

View File

@ -182,7 +182,7 @@ void free_pstree(struct pstree_item *root_item)
struct pstree_item *item = root_item, *parent;
while (item) {
if (!list_empty(&item->children)) {
if (has_children(item)) {
item = list_first_entry(&item->children, struct pstree_item, sibling);
continue;
}
@ -244,10 +244,15 @@ int init_pstree_helper(struct pstree_item *ret)
return 0;
}
bool has_children(struct pstree_item *item)
{
return !list_empty(&item->children);
}
/* Deep first search on children */
struct pstree_item *pstree_item_next(struct pstree_item *item)
{
if (!list_empty(&item->children))
if (has_children(item))
return list_first_entry(&item->children, struct pstree_item, sibling);
while (item->parent) {

View File

@ -1008,7 +1008,7 @@ static int collect_task(struct pstree_item *item)
if (ret < 0)
goto err_close;
if ((item->pid->state == TASK_DEAD) && !list_empty(&item->children)) {
if ((item->pid->state == TASK_DEAD) && has_children(item)) {
pr_err("Zombie with children?! O_o Run, run, run!\n");
goto err_close;
}