From 58fb68044f44824f3fb96386158f62b2f8a82fd5 Mon Sep 17 00:00:00 2001 From: Peter Oberndorfer Date: Mon, 10 Oct 2011 20:17:46 +0200 Subject: [PATCH] Reset inheritable flag of debug log file git_shell_ext_debug.txt FILE * handles opened by _wfopen are inherited to child processes by default. This behavior can be changed by adding "N" as mode to _wfopen. But msvcrt used by GCC does not implement/honor this. So just reset the inheritable flag after opening the file. This replaces d61e9f6c do not inherit handles into child processes Signed-off-by: Peter Oberndorfer --- common/debug.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/common/debug.c b/common/debug.c index 9bd6da1..2d567fc 100644 --- a/common/debug.c +++ b/common/debug.c @@ -4,6 +4,19 @@ static FILE *debug_git_fp = NULL; +#ifdef _WIN32 +static void reset_inherit_flag(FILE *file) +{ + HANDLE handle; + + if(!file) + return; + + handle = (HANDLE)_get_osfhandle(_fileno(file)); + SetHandleInformation(handle, HANDLE_FLAG_INHERIT, 0); +} +#endif + void debug_git(char * format, ...) { if (!debug_git_fp) { @@ -12,6 +25,7 @@ void debug_git(char * format, ...) GetTempPathW(MAX_PATH, path); wcsncat(path, L"git_shell_ext_debug.txt", MAX_PATH); debug_git_fp = _wfopen(path, L"a+"); + reset_inherit_flag(debug_git_fp); #else debug_git_fp = fopen("/tmp/git-cheetah-plugin.log", "a+"); #endif -- 2.11.4.GIT