diff options
author | 2022-02-28 23:12:55 -0800 | |
---|---|---|
committer | 2022-02-28 23:12:55 -0800 | |
commit | 1136fa0c07de570dc17858745af8be169d1440ba (patch) | |
tree | 3221b003517dd3cb13df5ba4b85637cd9ed82692 /kernel/pid.c | |
parent | Input: samsung-keypad - properly state IOMEM dependency (diff) | |
parent | Linux 5.17-rc4 (diff) | |
download | wireguard-linux-1136fa0c07de570dc17858745af8be169d1440ba.tar.xz wireguard-linux-1136fa0c07de570dc17858745af8be169d1440ba.zip |
Merge tag 'v5.17-rc4' into for-linus
Merge with mainline to get the Intel ASoC generic helpers header and
other changes.
Diffstat (limited to 'kernel/pid.c')
-rw-r--r-- | kernel/pid.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/kernel/pid.c b/kernel/pid.c index efe87db44683..2fc0a16ec77b 100644 --- a/kernel/pid.c +++ b/kernel/pid.c @@ -540,6 +540,42 @@ struct pid *pidfd_get_pid(unsigned int fd, unsigned int *flags) } /** + * pidfd_get_task() - Get the task associated with a pidfd + * + * @pidfd: pidfd for which to get the task + * @flags: flags associated with this pidfd + * + * Return the task associated with @pidfd. The function takes a reference on + * the returned task. The caller is responsible for releasing that reference. + * + * Currently, the process identified by @pidfd is always a thread-group leader. + * This restriction currently exists for all aspects of pidfds including pidfd + * creation (CLONE_PIDFD cannot be used with CLONE_THREAD) and pidfd polling + * (only supports thread group leaders). + * + * Return: On success, the task_struct associated with the pidfd. + * On error, a negative errno number will be returned. + */ +struct task_struct *pidfd_get_task(int pidfd, unsigned int *flags) +{ + unsigned int f_flags; + struct pid *pid; + struct task_struct *task; + + pid = pidfd_get_pid(pidfd, &f_flags); + if (IS_ERR(pid)) + return ERR_CAST(pid); + + task = get_pid_task(pid, PIDTYPE_TGID); + put_pid(pid); + if (!task) + return ERR_PTR(-ESRCH); + + *flags = f_flags; + return task; +} + +/** * pidfd_create() - Create a new pid file descriptor. * * @pid: struct pid that the pidfd will reference |