summaryrefslogtreecommitdiff
path: root/mysql-test/lib/My/Platform.pm
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@mariadb.com>2016-09-27 12:34:15 +0000
committerVladislav Vaintroub <wlad@mariadb.com>2016-09-27 12:34:15 +0000
commitb38d3c3d8afea7183f2a595f0c8d8dd7efaa801f (patch)
treeea54078b43ef77501eb523f5fbe421ca26bc7bbd /mysql-test/lib/My/Platform.pm
parentd61e5260fb9983ea8dff539b23a6d0a150c2065c (diff)
downloadmariadb-git-b38d3c3d8afea7183f2a595f0c8d8dd7efaa801f.tar.gz
MDEV-10907 MTR and server writes can interleave in the error log
Ensure atomic appends to the error log by using CreateFile with FILE_APPEND_DATA flag to open error log file (both MTR and server)
Diffstat (limited to 'mysql-test/lib/My/Platform.pm')
-rw-r--r--mysql-test/lib/My/Platform.pm49
1 files changed, 48 insertions, 1 deletions
diff --git a/mysql-test/lib/My/Platform.pm b/mysql-test/lib/My/Platform.pm
index 1776f1008da..110cf8a20e0 100644
--- a/mysql-test/lib/My/Platform.pm
+++ b/mysql-test/lib/My/Platform.pm
@@ -24,7 +24,7 @@ use File::Path;
use base qw(Exporter);
our @EXPORT= qw(IS_CYGWIN IS_WINDOWS IS_WIN32PERL
native_path posix_path mixed_path
- check_socket_path_length process_alive);
+ check_socket_path_length process_alive open_for_append);
BEGIN {
if ($^O eq "cygwin") {
@@ -161,4 +161,51 @@ sub process_alive {
}
+
+use Symbol qw( gensym );
+
+use if $^O eq 'MSWin32', 'Win32API::File', qw( CloseHandle CreateFile GetOsFHandle OsFHandleOpen OPEN_ALWAYS FILE_APPEND_DATA
+ FILE_SHARE_READ FILE_SHARE_WRITE FILE_SHARE_DELETE );
+use if $^O eq 'MSWin32', 'Win32::API';
+
+use constant WIN32API_FILE_NULL => [];
+
+# Open a file for append
+# On Windows we use CreateFile with FILE_APPEND_DATA
+# to insure that writes are atomic, not interleaved
+# with writes by another processes.
+sub open_for_append
+{
+ my ($file) = @_;
+ my $fh = gensym();
+
+ if (IS_WIN32PERL)
+ {
+ my $handle;
+ if (!($handle = CreateFile(
+ $file,
+ FILE_APPEND_DATA(),
+ FILE_SHARE_READ()|FILE_SHARE_WRITE()|FILE_SHARE_DELETE(),
+ WIN32API_FILE_NULL,
+ OPEN_ALWAYS(),# Create if doesn't exist.
+ 0,
+ WIN32API_FILE_NULL,
+ )))
+ {
+ return undef;
+ }
+
+ if (!OsFHandleOpen($fh, $handle, 'wat'))
+ {
+ CloseHandle($handle);
+ return undef;
+ }
+ return $fh;
+ }
+
+ open($fh,">>",$file) or return undef;
+ return $fh;
+}
+
+
1;