Commit 4ed58303 authored by Aleksey Midenkov's avatar Aleksey Midenkov Committed by Daniel Black

MDEV-30836 MTR Cygwin subshell wrapper fix

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
parent 0815a3b6
...@@ -20,6 +20,7 @@ package My::Platform; ...@@ -20,6 +20,7 @@ package My::Platform;
use strict; use strict;
use File::Basename; use File::Basename;
use File::Path; use File::Path;
use Carp;
use base qw(Exporter); use base qw(Exporter);
our @EXPORT= qw(IS_CYGWIN IS_WINDOWS IS_WIN32PERL IS_AIX our @EXPORT= qw(IS_CYGWIN IS_WINDOWS IS_WIN32PERL IS_AIX
...@@ -219,4 +220,69 @@ sub open_for_append ...@@ -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; 1;
...@@ -1237,7 +1237,8 @@ sub command_line_setup { ...@@ -1237,7 +1237,8 @@ sub command_line_setup {
'xml-report=s' => \$opt_xml_report, 'xml-report=s' => \$opt_xml_report,
My::Debugger::options(), My::Debugger::options(),
My::CoreDump::options() My::CoreDump::options(),
My::Platform::options()
); );
# fix options (that take an optional argument and *only* after = sign # fix options (that take an optional argument and *only* after = sign
...@@ -1273,6 +1274,9 @@ sub command_line_setup { ...@@ -1273,6 +1274,9 @@ sub command_line_setup {
} }
if (IS_CYGWIN) 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/ # Use mixed path format i.e c:/path/to/
$glob_mysql_test_dir= mixed_path($glob_mysql_test_dir); $glob_mysql_test_dir= mixed_path($glob_mysql_test_dir);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment