# Re: \[PATCH\]\[RFC\] open\_tree(2) (was Re: \[PATCH 30/32\] vfs: Allow cloning of a mount tree with open(O\_PATH\|O\_CLONE\_MOUNT) \[ver \#8\])

- From: Matthew Wilcox \<willy@infradead.org\>
- Date: 2018-06-04 17:16:33 
- List: linux-api
- Page: https://ratatoskr.run/linux-api/2018/06/139187
- Thread: https://ratatoskr.run/linux-fsdevel/2018/05/135893/t.md

```text
On Sun, Jun 03, 2018 at 01:55:37AM +0100, Al Viro wrote:
> +SYSCALL_DEFINE3(open_tree, int, dfd, const char *, filename, unsigned, flags)
> +{
> +	struct file *file;
> +	struct path path;
> +	int lookup_flags = LOOKUP_AUTOMOUNT | LOOKUP_FOLLOW;
> +	bool detached = flags & OPEN_TREE_CLONE;
> +	int error;
> +	int fd;
> +
> +	BUILD_BUG_ON(OPEN_TREE_CLOEXEC != O_CLOEXEC);

Why do we need OPEN_TREE_CLOEXEC?  Wouldn't we be better off just making
the fd returned by open_tree implicitly close-on-exec?  I can think of
no good reason for these file descriptors to be inherited across exec()
and if someone comes up with such a reason, fcntl(F_SETFD) is not an
expensive call to make.
```
