diff --git a/mysql-test/lib/My/SafeProcess/safe_process_win.cc b/mysql-test/lib/My/SafeProcess/safe_process_win.cc index 8a5bb60a3f5..6e1fd414287 100644 --- a/mysql-test/lib/My/SafeProcess/safe_process_win.cc +++ b/mysql-test/lib/My/SafeProcess/safe_process_win.cc @@ -152,6 +152,24 @@ void handle_signal (int signal) } } +/** + Sets the append flag (FILE_APPEND_DATA) so that the handle inherited by the + child process will be in append mode. + Workaround for perl bug https://github.com/Perl/perl5/issues/17570 +*/ +static void fix_file_append_flag_inheritance(DWORD std_handle) +{ + HANDLE old_handle = GetStdHandle(std_handle); + HANDLE new_handle = ReOpenFile(old_handle, FILE_APPEND_DATA, + FILE_SHARE_WRITE | FILE_SHARE_READ, 0); + if (new_handle != INVALID_HANDLE_VALUE) + { + SetHandleInformation(new_handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT); + SetStdHandle(std_handle, new_handle); + CloseHandle(old_handle); + } +} + int main(int argc, const char** argv ) { @@ -270,6 +288,9 @@ int main(int argc, const char** argv ) SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX | SEM_NOOPENFILEERRORBOX); + fix_file_append_flag_inheritance(STD_OUTPUT_HANDLE); + fix_file_append_flag_inheritance(STD_ERROR_HANDLE); + #if 0 /* Setup stdin, stdout and stderr redirect */ si.dwFlags= STARTF_USESTDHANDLES;