Skip to content

Commit

Permalink
MDEV-30836 MTR Cygwin subshell wrapper fix
Browse files Browse the repository at this point in the history
See "Path-style conflict" in "MDEV-30836 MTR Cygwin fix" for explanation.

To install subshell fix use --cygwin-subshell-fix=do
To uninstall use --cygwin-subshell-fix=remove

This works only from Cygwin environment. As long as perl on PATH is
from Cygwin you are on Cygwin environment. Check it with

     perl --version

     This is perl 5, version 36, subversion 1 (v5.36.1) built for
     x86_64-cygwin-threads-multi
  • Loading branch information
midenok authored and grooverdan committed Sep 5, 2023
1 parent 0815a3b commit 4ed5830
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
66 changes: 66 additions & 0 deletions mysql-test/lib/My/Platform.pm
Expand Up @@ -20,6 +20,7 @@ package My::Platform;
use strict;
use File::Basename;
use File::Path;
use Carp;

use base qw(Exporter);
our @EXPORT= qw(IS_CYGWIN IS_WINDOWS IS_WIN32PERL IS_AIX
Expand Down Expand Up @@ -219,4 +220,69 @@ sub open_for_append
}


sub check_cygwin_subshell
{
# Only pipe (or sh-expansion) is fed to /bin/sh
my $out= `echo %comspec%|cat`;
return ($out =~ /\bcmd.exe\b/) ? 0 : 1;
}

sub install_shell_wrapper()
{
system("rm -f /bin/sh.exe") and die $!;
my $wrapper= <<'EOF';
#!/bin/bash
if [[ -n "$MTR_PERL" && "$1" = "-c" ]]; then
shift
exec $(cygpath -m "$COMSPEC") /C "$@"
fi
exec /bin/bash "$@"
EOF
open(OUT, '>', "/bin/sh") or die "/bin/sh: $!\n";
print OUT $wrapper;
close(OUT);
system("chmod +x /bin/sh") and die $!;
print "Cygwin subshell wrapper /bin/sh was installed, please restart MTR!\n";
exit(0);
}

sub uninstall_shell_wrapper()
{
system("rm -f /bin/sh") and die $!;
system("cp /bin/bash.exe /bin/sh.exe") and die $!;
}

sub cygwin_subshell_fix
{
my ($opt_name, $opt_value)= @_;
if ($opt_name ne "cygwin-subshell-fix") {
confess "Wrong option name: ${opt_name}";
}
if ($opt_value eq "do") {
if (check_cygwin_subshell()) {
install_shell_wrapper();
} else {
print "Cygwin subshell fix was already installed, skipping...\n";
}
} elsif ($opt_value eq "remove") {
if (check_cygwin_subshell()) {
print "Cygwin subshell fix was already uninstalled, skipping...\n";
} else {
uninstall_shell_wrapper();
}
} else {
die "Wrong --cygwin-subshell-fix value: ${opt_value} (expected do/remove)";
}
}

sub options
{
if (IS_CYGWIN) {
return ('cygwin-subshell-fix=s' => \&cygwin_subshell_fix);
} else {
return ();
}
}


1;
6 changes: 5 additions & 1 deletion mysql-test/mysql-test-run.pl
Expand Up @@ -1237,7 +1237,8 @@ sub command_line_setup {
'xml-report=s' => \$opt_xml_report,

My::Debugger::options(),
My::CoreDump::options()
My::CoreDump::options(),
My::Platform::options()
);

# fix options (that take an optional argument and *only* after = sign
Expand Down Expand Up @@ -1273,6 +1274,9 @@ sub command_line_setup {
}
if (IS_CYGWIN)
{
if (My::Platform::check_cygwin_subshell()) {
die("Cygwin /bin/sh subshell requires fix with --cygwin-subshell-fix=do\n");
}
# Use mixed path format i.e c:/path/to/
$glob_mysql_test_dir= mixed_path($glob_mysql_test_dir);
}
Expand Down

0 comments on commit 4ed5830

Please sign in to comment.