From: Eric Wong Date: Wed, 07 Sep 2016 18:10:36 GMT Subject: Re: [PATCH v1 2/2] read-cache: make sure file handles are not inherited by child processes Message-ID: <20160907181036.GA14931@starla> In-Reply-To: <7B903664-0324-4375-A81C-1317020CBE9B@gmail.com> Lars Schneider wrote: > > On 06 Sep 2016, at 23:06, Eric Wong wrote: > > larsxschneider@gmail.com wrote: > >> 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 (fd >= 0) { > >> unsigned char sha1[20]; > > > > Also, this needs to check EINVAL when O_CLOEXEC != 0 the same > > way create_tempfile currently does. Somebody could be building > > with modern headers but running an old kernel that doesn't > > understand O_CLOEXEC. > > > > There should probably be a open() wrapper for handling this case > > since we're now up to 3 places where open(... O_CLOEXEC) is > > used. > > Right! Actually "sha1_file.c:git_open_noatime()" is already a wrapper, no? > Can't we use this here? The O_NOATIME flag shouldn't hurt, right? For ce_compare_data (and other O_RDONLY users), I guess git_open_noatime is fine; and probably preferable because of O_NOATIME. We probably should be using O_NOATIME for all O_RDONLY cases to get the last bit of performance out (especially since non-modern-Linux systems probably still lack relatime). However, create_tempfile needs O_RDWR|O_CREAT|O_EXCL but I guess we can clean that up in another series.