mirror of
https://github.com/tbsdtv/linux_media.git
synced 2025-07-23 04:33:26 +02:00
pid: add pidfd_prepare()
Add a new helper that allows to reserve a pidfd and allocates a new pidfd file that stashes the provided struct pid. This will allow us to remove places that either open code this function or that call pidfd_create() but then have to call close_fd() because there are still failure points after pidfd_create() has been called. Reviewed-by: Jan Kara <jack@suse.cz> Message-Id: <20230327-pidfd-file-api-v1-1-5c0e9a3158e4@kernel.org> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
19
kernel/pid.c
19
kernel/pid.c
@@ -594,20 +594,15 @@ struct task_struct *pidfd_get_task(int pidfd, unsigned int *flags)
|
||||
*/
|
||||
int pidfd_create(struct pid *pid, unsigned int flags)
|
||||
{
|
||||
int fd;
|
||||
int pidfd;
|
||||
struct file *pidfd_file;
|
||||
|
||||
if (!pid || !pid_has_task(pid, PIDTYPE_TGID))
|
||||
return -EINVAL;
|
||||
pidfd = pidfd_prepare(pid, flags, &pidfd_file);
|
||||
if (pidfd < 0)
|
||||
return pidfd;
|
||||
|
||||
if (flags & ~(O_NONBLOCK | O_RDWR | O_CLOEXEC))
|
||||
return -EINVAL;
|
||||
|
||||
fd = anon_inode_getfd("[pidfd]", &pidfd_fops, get_pid(pid),
|
||||
flags | O_RDWR | O_CLOEXEC);
|
||||
if (fd < 0)
|
||||
put_pid(pid);
|
||||
|
||||
return fd;
|
||||
fd_install(pidfd, pidfd_file);
|
||||
return pidfd;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user