> On 29 Aug 2016, at 21:45, Junio C Hamano <gitster@xxxxxxxxx> wrote: > > Lars Schneider <larsxschneider@xxxxxxxxx> writes: > >> I see. Thanks for the explanation. > > I expect the updated log message to explain the issue correctly > then. Sure! >>> The parent is >>> very likely to have pack windows open into .pack files and they need >>> to be closed on the child side after fork(2) starts the child >>> process but before execve(2) runs the helper, if we want to avoid >>> file descriptor leaks. >> >> I think I understand what you are saying. However, during my tests >> .pack file fd's were never a problem. > > I do not expect during the lifetime of your long-running helper > anybody would try to unlink an existing packfile, so it is unlikely > that "cannot unlink an open file on Windows" issue to come up. And > the cross-platform problem I pointed out is a fd leak; leaks would > not show up until you run out of the resource, just like you > wouldn't notice small memory leak here and there UNLESS you actively > look for them. I would be surprised if your "tests" found anything. > >> How would I find the open .pack file fd's? Should I go through >> /proc/PID/fd? Why is this no problem for other longer running >> commands such as the git-credential-cache--daemon or git-daemon? > > Nobody said this is "no problem for others". While discussing the > patch that started this thread, we noticed that any open file > descriptor the main process has when the long-running clean/smudge > helper is spawned _is_ a problem. Other helpers may share the same > problem, and if they do, that is all the more reason that fixing the > file descriptor leak is a good thing. > > The primary thing I was wondering was if we should open the window > into packfiles with CLOEXEC, just like we recently started opening > the tempfiles and lockfiles with the flag. The reason why I asked > if the site that spawns (i.e. run_command API) has an easy access to > the list of file descriptors that we opened ONLY for ourselves is > because that would make it possible to consider an alternative > approach close them before execve(2) in run_commands API. That > would save us from having to sprinkle existing calls to open(2) with > CLOEXEC. But if that is not the case, opening them with CLOEXEC is > a much better solution than going outside the program to "find" them > in non-portable ways. The pack files are opened before the filter process is forked. Therefore, I think CLOEXEC makes sense for them. Should this change be part of this series? If yes, would it look like below? Should I adjust the function name? Thanks, Lars diff --git a/sha1_file.c b/sha1_file.c index d5e1121..759991e 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1485,7 +1485,7 @@ int check_sha1_signature(const unsigned char *sha1, void *map, int git_open_noatime(const char *name) { - static int sha1_file_open_flag = O_NOATIME; + static int sha1_file_open_flag = O_NOATIME | O_CLOEXEC; for (;;) { int fd;