@@ -1750,14 +1750,40 @@ static pid_t mingw_spawnve_fd(const char *cmd, const char **argv, char **deltaen
1750
1750
* handle inheritance. This is still better than failing to create
1751
1751
* processes.
1752
1752
*/
1753
- if (!ret && GetLastError () == ERROR_NO_SYSTEM_RESOURCES &&
1754
- restrict_handle_inheritance && stdhandles_count ) {
1753
+ if (!ret && restrict_handle_inheritance && stdhandles_count ) {
1754
+ DWORD err = GetLastError ();
1755
+ if (err != ERROR_NO_SYSTEM_RESOURCES &&
1756
+ !getenv ("SUPPRESS_HANDLE_INHERITANCE_WARNING" )) {
1757
+ struct strbuf buf = STRBUF_INIT ;
1758
+ DWORD fl ;
1759
+ int i ;
1760
+
1761
+ setenv ("SUPPRESS_HANDLE_INHERITANCE_WARNING" , "1" , 1 );
1762
+
1763
+ for (i = 0 ; i < stdhandles_count ; i ++ ) {
1764
+ HANDLE h = stdhandles [i ];
1765
+ strbuf_addf (& buf , "handle #%d: %p (type %lx, "
1766
+ "handle info (%d) %lx\n" , i , h ,
1767
+ GetFileType (h ),
1768
+ GetHandleInformation (h , & fl ),
1769
+ fl );
1770
+ }
1771
+ strbuf_addstr (& buf , "\nThis is a bug; please report it "
1772
+ "at\nhttps://github.com/git-for-windows/"
1773
+ "git/issues/new\n\n"
1774
+ "To suppress this warning, please set "
1775
+ "the environment variable\n\n"
1776
+ "\tSUPPRESS_HANDLE_INHERITANCE_WARNING=1"
1777
+ "\n" );
1778
+ warning ("failed to restrict file handles (%ld)\n\n%s" ,
1779
+ err , buf .buf );
1780
+ strbuf_release (& buf );
1781
+ }
1755
1782
restrict_handle_inheritance = 0 ;
1756
1783
flags &= ~EXTENDED_STARTUPINFO_PRESENT ;
1757
1784
ret = CreateProcessW (* wcmd ? wcmd : NULL , wargs , NULL , NULL ,
1758
- stdhandles_count ? TRUE : FALSE,
1759
- flags , wenvblk , dir ? wdir : NULL ,
1760
- & si .StartupInfo , & pi );
1785
+ TRUE, flags , wenvblk , dir ? wdir : NULL ,
1786
+ & si .StartupInfo , & pi );
1761
1787
}
1762
1788
1763
1789
if (!ret )
0 commit comments