criu/files: Add function to return unused FD by pid

Add a new global function to return unused FD based on the pid. This
function can be used in situations where we need a FD that will not
conflict with FDs used by target restore process, but
struct pstree_item is not available (e.g plugins)

Signed-off-by: David Yat Sin <david.yatsin@amd.com>
This commit is contained in:
David Yat Sin 2021-09-27 14:16:35 -04:00 committed by Andrei Vagin
parent 653eefea0c
commit e04db02411
2 changed files with 13 additions and 0 deletions

View file

@ -183,6 +183,18 @@ out:
return fd;
}
int find_unused_fd_pid(pid_t pid)
{
struct pstree_item *task;
task = pstree_item_by_virt(pid);
if (!task) {
pr_err("Invalid pid:%d\n", pid);
return -1;
}
return find_unused_fd(task, -1);
}
int set_fds_event(pid_t virt)
{
struct pstree_item *item;

View file

@ -195,4 +195,5 @@ extern int open_transport_socket(void);
extern int set_fds_event(pid_t virt);
extern void wait_fds_event(void);
int find_unused_fd_pid(pid_t pid);
#endif /* __CR_FILES_H__ */