@@ -244,7 +244,6 @@ enum hide_dotfiles_type {
244244 HIDE_DOTFILES_DOTGITONLY
245245};
246246
247- static int core_restrict_inherited_handles = -1 ;
248247static enum hide_dotfiles_type hide_dotfiles = HIDE_DOTFILES_DOTGITONLY ;
249248static char * unset_environment_variables ;
250249
@@ -268,15 +267,6 @@ int mingw_core_config(const char *var, const char *value,
268267 return 0 ;
269268 }
270269
271- if (!strcmp (var , "core.restrictinheritedhandles" )) {
272- if (value && !strcasecmp (value , "auto" ))
273- core_restrict_inherited_handles = -1 ;
274- else
275- core_restrict_inherited_handles =
276- git_config_bool (var , value );
277- return 0 ;
278- }
279-
280270 return 0 ;
281271}
282272
@@ -588,13 +578,24 @@ static int mingw_open_existing(const wchar_t *filename, int oflags, ...)
588578 & security_attributes , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL , NULL );
589579 if (handle == INVALID_HANDLE_VALUE ) {
590580 DWORD err = GetLastError ();
581+ if (err == ERROR_ACCESS_DENIED ) {
582+ DWORD attrs = GetFileAttributesW (filename );
583+ if (attrs != INVALID_FILE_ATTRIBUTES && (attrs & FILE_ATTRIBUTE_DIRECTORY ))
584+ handle = CreateFileW (filename , access ,
585+ FILE_SHARE_WRITE | FILE_SHARE_READ | FILE_SHARE_DELETE ,
586+ & security_attributes , OPEN_EXISTING , FILE_ATTRIBUTE_NORMAL | FILE_FLAG_BACKUP_SEMANTICS , NULL );
587+ }
591588
592- /* See `mingw_open_append()` for why we have this conversion. */
593- if (err == ERROR_INVALID_PARAMETER )
594- err = ERROR_PATH_NOT_FOUND ;
589+ if (handle == INVALID_HANDLE_VALUE ) {
590+ err = GetLastError ();
595591
596- errno = err_win_to_posix (err );
597- return -1 ;
592+ /* See `mingw_open_append()` for why we have this conversion. */
593+ if (err == ERROR_INVALID_PARAMETER )
594+ err = ERROR_PATH_NOT_FOUND ;
595+
596+ errno = err_win_to_posix (err );
597+ return -1 ;
598+ }
598599 }
599600
600601 fd = _open_osfhandle ((intptr_t )handle , oflags | O_BINARY );
@@ -1656,7 +1657,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
16561657 const char * dir ,
16571658 int prepend_cmd , int fhin , int fhout , int fherr )
16581659{
1659- static int restrict_handle_inheritance = -1 ;
16601660 STARTUPINFOEXW si ;
16611661 PROCESS_INFORMATION pi ;
16621662 LPPROC_THREAD_ATTRIBUTE_LIST attr_list = NULL ;
@@ -1676,16 +1676,6 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
16761676 /* Make sure to override previous errors, if any */
16771677 errno = 0 ;
16781678
1679- if (restrict_handle_inheritance < 0 )
1680- restrict_handle_inheritance = core_restrict_inherited_handles ;
1681- /*
1682- * The following code to restrict which handles are inherited seems
1683- * to work properly only on Windows 7 and later, so let's disable it
1684- * on Windows Vista and 2008.
1685- */
1686- if (restrict_handle_inheritance < 0 )
1687- restrict_handle_inheritance = GetVersion () >> 16 >= 7601 ;
1688-
16891679 do_unset_environment_variables ();
16901680
16911681 /* Determine whether or not we are associated to a console */
@@ -1787,7 +1777,7 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
17871777 wenvblk = make_environment_block (deltaenv );
17881778
17891779 memset (& pi , 0 , sizeof (pi ));
1790- if (restrict_handle_inheritance && stdhandles_count &&
1780+ if (stdhandles_count &&
17911781 (InitializeProcThreadAttributeList (NULL , 1 , 0 , & size ) ||
17921782 GetLastError () == ERROR_INSUFFICIENT_BUFFER ) &&
17931783 (attr_list = (LPPROC_THREAD_ATTRIBUTE_LIST )
@@ -1808,52 +1798,13 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
18081798 & si .StartupInfo , & pi );
18091799
18101800 /*
1811- * On Windows 2008 R2, it seems that specifying certain types of handles
1812- * (such as FILE_TYPE_CHAR or FILE_TYPE_PIPE) will always produce an
1813- * error. Rather than playing finicky and fragile games, let's just try
1814- * to detect this situation and simply try again without restricting any
1815- * handle inheritance. This is still better than failing to create
1816- * processes.
1801+ * On the off-chance that something with the file handle restriction
1802+ * went wrong, silently fall back to trying without it.
18171803 */
1818- if (!ret && restrict_handle_inheritance && stdhandles_count ) {
1804+ if (!ret && stdhandles_count ) {
18191805 DWORD err = GetLastError ();
18201806 struct strbuf buf = STRBUF_INIT ;
18211807
1822- if (err != ERROR_NO_SYSTEM_RESOURCES &&
1823- /*
1824- * On Windows 7 and earlier, handles on pipes and character
1825- * devices are inherited automatically, and cannot be
1826- * specified in the thread handle list. Rather than trying
1827- * to catch each and every corner case (and running the
1828- * chance of *still* forgetting a few), let's just fall
1829- * back to creating the process without trying to limit the
1830- * handle inheritance.
1831- */
1832- !(err == ERROR_INVALID_PARAMETER &&
1833- GetVersion () >> 16 < 9200 ) &&
1834- !getenv ("SUPPRESS_HANDLE_INHERITANCE_WARNING" )) {
1835- DWORD fl = 0 ;
1836- int i ;
1837-
1838- setenv ("SUPPRESS_HANDLE_INHERITANCE_WARNING" , "1" , 1 );
1839-
1840- for (i = 0 ; i < stdhandles_count ; i ++ ) {
1841- HANDLE h = stdhandles [i ];
1842- strbuf_addf (& buf , "handle #%d: %p (type %lx, "
1843- "handle info (%d) %lx\n" , i , h ,
1844- GetFileType (h ),
1845- GetHandleInformation (h , & fl ),
1846- fl );
1847- }
1848- strbuf_addstr (& buf , "\nThis is a bug; please report it "
1849- "at\nhttps://github.com/git-for-windows/"
1850- "git/issues/new\n\n"
1851- "To suppress this warning, please set "
1852- "the environment variable\n\n"
1853- "\tSUPPRESS_HANDLE_INHERITANCE_WARNING=1"
1854- "\n" );
1855- }
1856- restrict_handle_inheritance = 0 ;
18571808 flags &= ~EXTENDED_STARTUPINFO_PRESENT ;
18581809 ret = CreateProcessW (* wcmd ? wcmd : NULL , wargs , NULL , NULL ,
18591810 TRUE, flags , wenvblk , dir ? wdir : NULL ,
0 commit comments