mirror of
https://github.com/checkpoint-restore/criu.git
synced 2026-07-20 16:51:37 +00:00
pstree: more pstree-related helpers
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. Note: pstree_item_by_virt() and pid_to_virt() will be used to migrate AutoFS. Signed-off-by: Stanislav Kinsburskiy <skinsbursky@virtuozzo.com> Signed-off-by: Pavel Emelyanov <xemul@parallels.com>
This commit is contained in:
parent
bde6d0dbf9
commit
1617579a27
2 changed files with 35 additions and 5 deletions
|
|
@ -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;
|
||||
|
|
|
|||
35
pstree.c
35
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 false;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue