Merge branch 'bw/mingw-avoid-inheriting-fd-to-lockfile' into maint
authorJunio C Hamano <gitster@pobox.com>
Fri, 9 Sep 2016 04:35:56 +0000 (21:35 -0700)
committerJunio C Hamano <gitster@pobox.com>
Fri, 9 Sep 2016 04:35:56 +0000 (21:35 -0700)
The tempfile (hence its user lockfile) API lets the caller to open
a file descriptor to a temporary file, write into it and then
finalize it by first closing the filehandle and then either
removing or renaming the temporary file. When the process spawns a
subprocess after obtaining the file descriptor, and if the
subprocess has not exited when the attempt to remove or rename is
made, the last step fails on Windows, because the subprocess has
the file descriptor still open. Open tempfile with O_CLOEXEC flag
to avoid this (on Windows, this is mapped to O_NOINHERIT).

* bw/mingw-avoid-inheriting-fd-to-lockfile:
mingw: ensure temporary file handles are not inherited by child processes
t6026-merge-attr: child processes must not inherit index.lock handles

1  2 
compat/mingw.h
git-compat-util.h
diff --combined compat/mingw.h
index 2cadb816eebf305e84181379f48aec061ea158f7,6090e83947f82312463e1fabba6b93a4d6b52f16..034fff9479d03d2a2e3c7017a4fe4131461f0ec6
@@@ -67,6 -67,10 +67,10 @@@ typedef int pid_t
  #define F_SETFD 2
  #define FD_CLOEXEC 0x1
  
+ #if !defined O_CLOEXEC && defined O_NOINHERIT
+ #define O_CLOEXEC     O_NOINHERIT
+ #endif
  #ifndef EAFNOSUPPORT
  #define EAFNOSUPPORT WSAEAFNOSUPPORT
  #endif
@@@ -417,6 -421,9 +421,6 @@@ int mingw_offset_1st_component(const ch
  #include <inttypes.h>
  #endif
  
 -void mingw_open_html(const char *path);
 -#define open_html mingw_open_html
 -
  /**
   * Converts UTF-8 encoded string to UTF-16LE.
   *
@@@ -535,7 -542,7 +539,7 @@@ extern CRITICAL_SECTION pinfo_cs
  void mingw_startup(void);
  #define main(c,v) dummy_decl_mingw_main(void); \
  static int mingw_main(c,v); \
 -int main(int argc, char **argv) \
 +int main(int argc, const char **argv) \
  { \
        mingw_startup(); \
        return mingw_main(__argc, (void *)__argv); \
diff --combined git-compat-util.h
index 1930444ef092f2b5834d12b73b4d2d0c050f3551,f1f98b50d7e3453c66b492e7763f3640198f803f..9eab471264ab6a22af3e5eb4a0a97f510de19a7e
@@@ -650,6 -650,10 +650,10 @@@ void *gitmemmem(const void *haystack, s
  #define getpagesize() sysconf(_SC_PAGESIZE)
  #endif
  
+ #ifndef O_CLOEXEC
+ #define O_CLOEXEC 0
+ #endif
  #ifdef FREAD_READS_DIRECTORIES
  #ifdef fopen
  #undef fopen
@@@ -1045,5 -1049,3 +1049,5 @@@ struct tm *git_gmtime_r(const time_t *
  #endif
  
  #endif
 +
 +extern int cmd_main(int, const char **);