Skip to content

Commit b056ed6

Browse files
committed
MDEV-35891 mtr, Windows - fix multi-process append for stdout and stderr
This backports mysql/mysql-server@e2f685972985, which works around perl issue Perl/perl5#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.
1 parent d32ec7d commit b056ed6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

mysql-test/lib/My/SafeProcess/safe_process_win.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,24 @@ void handle_signal (int signal)
152152
}
153153
}
154154

155+
/**
156+
Sets the append flag (FILE_APPEND_DATA) so that the handle inherited by the
157+
child process will be in append mode.
158+
Workaround for perl bug https://github.com/Perl/perl5/issues/17570
159+
*/
160+
static void fix_file_append_flag_inheritance(DWORD std_handle)
161+
{
162+
HANDLE old_handle = GetStdHandle(std_handle);
163+
HANDLE new_handle = ReOpenFile(old_handle, FILE_APPEND_DATA,
164+
FILE_SHARE_WRITE | FILE_SHARE_READ, 0);
165+
if (new_handle != INVALID_HANDLE_VALUE)
166+
{
167+
SetHandleInformation(new_handle, HANDLE_FLAG_INHERIT, HANDLE_FLAG_INHERIT);
168+
SetStdHandle(std_handle, new_handle);
169+
CloseHandle(old_handle);
170+
}
171+
}
172+
155173

156174
int main(int argc, const char** argv )
157175
{
@@ -270,6 +288,9 @@ int main(int argc, const char** argv )
270288
SetErrorMode(SEM_FAILCRITICALERRORS | SEM_NOGPFAULTERRORBOX
271289
| SEM_NOOPENFILEERRORBOX);
272290

291+
fix_file_append_flag_inheritance(STD_OUTPUT_HANDLE);
292+
fix_file_append_flag_inheritance(STD_ERROR_HANDLE);
293+
273294
#if 0
274295
/* Setup stdin, stdout and stderr redirect */
275296
si.dwFlags= STARTF_USESTDHANDLES;

0 commit comments

Comments
 (0)