mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-23 01:59:04 +00:00
pstree: add helper for_each_pssubtree_item to walk item's subtree
Need it to lookup adoptive children of pidns init. Also add skip_descendants flag to be able to skip unneeded subtrees. Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com> Signed-off-by: Andrei Vagin <avagin@virtuozzo.com>
This commit is contained in:
parent
f39d203588
commit
59ad51932c
2 changed files with 15 additions and 4 deletions
|
|
@ -106,8 +106,12 @@ static inline struct pid *pstree_pid_by_virt(pid_t pid)
|
|||
|
||||
extern struct pstree_item *root_item;
|
||||
extern struct pstree_item *pstree_item_next(struct pstree_item *item);
|
||||
extern struct pstree_item *pssubtree_item_next(struct pstree_item *item,
|
||||
struct pstree_item *root, bool skip_descendants);
|
||||
#define for_each_pstree_item(pi) \
|
||||
for (pi = root_item; pi != NULL; pi = pstree_item_next(pi))
|
||||
#define for_each_pssubtree_item(pi, root) \
|
||||
for (pi = root; pi != NULL; pi = pssubtree_item_next(pi, root, false))
|
||||
|
||||
extern bool restore_before_setsid(struct pstree_item *child);
|
||||
extern int prepare_pstree(void);
|
||||
|
|
|
|||
|
|
@ -290,13 +290,14 @@ int init_pstree_helper(struct pstree_item *ret)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* Deep first search on children */
|
||||
struct pstree_item *pstree_item_next(struct pstree_item *item)
|
||||
/* Search only root's subtree, possibly skipping descendants */
|
||||
struct pstree_item *pssubtree_item_next(struct pstree_item *item,
|
||||
struct pstree_item *root, bool skip_descendants)
|
||||
{
|
||||
if (!list_empty(&item->children))
|
||||
if (!skip_descendants && !list_empty(&item->children))
|
||||
return list_first_entry(&item->children, struct pstree_item, sibling);
|
||||
|
||||
while (item->parent) {
|
||||
while (item->parent && item != root) {
|
||||
if (item->sibling.next != &item->parent->children)
|
||||
return list_entry(item->sibling.next, struct pstree_item, sibling);
|
||||
item = item->parent;
|
||||
|
|
@ -305,6 +306,12 @@ struct pstree_item *pstree_item_next(struct pstree_item *item)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/* Deep first search on children */
|
||||
struct pstree_item *pstree_item_next(struct pstree_item *item)
|
||||
{
|
||||
return pssubtree_item_next(item, NULL, false);
|
||||
}
|
||||
|
||||
/* Preorder traversal of pstree item */
|
||||
int preorder_pstree_traversal(struct pstree_item *item, int (*f)(struct pstree_item *))
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue