Instead od adding it into __pidfd_prepare() place it where the actual file allocation happens and update the outdated comment.
Unified · Split
| @@ -696,6 +696,10 @@ struct file *pidfs_alloc_file(struct pid *pid, unsigned int flags) · 695 unmodified lines | |||
| 696 | return ERR_PTR(ret); | 696 | return ERR_PTR(ret); |
| 697 | 697 | ||
| 698 | pidfd_file = dentry_open(&path, flags, current_cred()); | 698 | pidfd_file = dentry_open(&path, flags, current_cred()); |
| 699 | /* Raise PIDFD_THREAD explicitly as do_dentry_open() strips it. */ | ||
| 700 | if (!IS_ERR(pidfd_file)) | ||
| 701 | pidfd_file->f_flags |= (flags & PIDFD_THREAD); | ||
| 702 | |||
| 699 | path_put(&path); | 703 | path_put(&path); |
| 700 | return pidfd_file; | 704 | return pidfd_file; |
| 701 | } | 705 | } |
| @@ -2042,11 +2042,6 @@ static int __pidfd_prepare(struct pid *pid, unsigned int flags, struct file **re · 2041 unmodified lines | |||
| 2042 | if (IS_ERR(pidfd_file)) | 2042 | if (IS_ERR(pidfd_file)) |
| 2043 | return PTR_ERR(pidfd_file); | 2043 | return PTR_ERR(pidfd_file); |
| 2044 | 2044 | ||
| 2045 | /* | ||
| 2046 | * anon_inode_getfile() ignores everything outside of the | ||
| 2047 | * O_ACCMODE | O_NONBLOCK mask, set PIDFD_THREAD manually. | ||
| 2048 | */ | ||
| 2049 | pidfd_file->f_flags |= (flags & PIDFD_THREAD); | ||
| 2050 | *ret = pidfd_file; | 2045 | *ret = pidfd_file; |
| 2051 | return take_fd(pidfd); | 2046 | return take_fd(pidfd); |
| 2052 | } | 2047 | } |