MDEV-35891 mtr, Windows - fix multi-process append for stdout and stderr
This backports https://github.com/mysql/mysql-server/commit/e2f685972985, which works around perl issue https://github.com/Perl/perl5/issues/17570 MySQL fix ensures that FILE_APPEND_DATA is used in redirected stdout/stderr open flags, rather than FILE_GENERIC_WRITE. Only this gives lossless append behavior, if multiple processes use the same file.
This commit is contained in:
parent
d32ec7d48e
commit
b056ed6d98
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user