Re: [PATCH v2 2/2] read-cache: make sure file handles are not inherited by child processes
- From
- Eric Wong <e@80x24.org>
- Date
- Oct 24, 2016, 18:39 UTC
- Message-ID
- <20161024183900.GA12769@starla>
- In-Reply-To
- <20161024180300.52359-3-larsxschneider@gmail.com>
larsxschneider@gmail.com wrote:
Show 11 quoted lines
> +++ b/read-cache.c
> @@ -156,7 +156,11 @@ void fill_stat_cache_info(struct cache_entry *ce, struct stat *st)
> static int ce_compare_data(const struct cache_entry *ce, struct stat *st)
> {
> int match = -1;
> - int fd = open(ce->name, O_RDONLY);
> + int fd = open(ce->name, O_RDONLY | O_CLOEXEC);
> +
> + if (O_CLOEXEC && fd < 0 && errno == EINVAL)
> + /* Try again w/o O_CLOEXEC: the kernel might not support it */
> + fd = open(ce->name, O_RDONLY);In the case of O_CLOEXEC != 0 and repeated EINVALs, it'd be good to use something like sha1_file_open_flag as in 1/2 so we don't repeatedly hit EINVAL. Thanks.