mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-05 18:41:58 +09:00
fork: use pidfd_prepare()
commit ca7707f543 upstream.
Stop open-coding get_unused_fd_flags() and anon_inode_getfile(). That's
brittle just for keeping the flags between both calls in sync. Use the
dedicated helper.
Message-Id: <20230327-pidfd-file-api-v1-2-5c0e9a3158e4@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
committed by
Greg Kroah-Hartman
parent
1ced79b25f
commit
b2a5bf1cf4
@@ -2378,21 +2378,12 @@ static __latent_entropy struct task_struct *copy_process(
|
|||||||
* if the fd table isn't shared).
|
* if the fd table isn't shared).
|
||||||
*/
|
*/
|
||||||
if (clone_flags & CLONE_PIDFD) {
|
if (clone_flags & CLONE_PIDFD) {
|
||||||
retval = get_unused_fd_flags(O_RDWR | O_CLOEXEC);
|
/* Note that no task has been attached to @pid yet. */
|
||||||
|
retval = __pidfd_prepare(pid, O_RDWR | O_CLOEXEC, &pidfile);
|
||||||
if (retval < 0)
|
if (retval < 0)
|
||||||
goto bad_fork_free_pid;
|
goto bad_fork_free_pid;
|
||||||
|
|
||||||
pidfd = retval;
|
pidfd = retval;
|
||||||
|
|
||||||
pidfile = anon_inode_getfile("[pidfd]", &pidfd_fops, pid,
|
|
||||||
O_RDWR | O_CLOEXEC);
|
|
||||||
if (IS_ERR(pidfile)) {
|
|
||||||
put_unused_fd(pidfd);
|
|
||||||
retval = PTR_ERR(pidfile);
|
|
||||||
goto bad_fork_free_pid;
|
|
||||||
}
|
|
||||||
get_pid(pid); /* held by pidfile now */
|
|
||||||
|
|
||||||
retval = put_user(pidfd, args->pidfd);
|
retval = put_user(pidfd, args->pidfd);
|
||||||
if (retval)
|
if (retval)
|
||||||
goto bad_fork_put_pidfd;
|
goto bad_fork_put_pidfd;
|
||||||
|
|||||||
Reference in New Issue
Block a user