diff options
author | Richard Levitte <levitte@openssl.org> | 2020-02-17 15:05:04 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-02-27 08:49:14 +0100 |
commit | 285e2991af23974761b9497f1e2a3396aa4bc440 (patch) | |
tree | f0f66fcc5e05381bb4fbfc965fad9a7ddb4f00d7 | |
parent | VMS: mitigate for the C++ compiler that doesn't understand certain pragmas (diff) | |
download | openssl-285e2991af23974761b9497f1e2a3396aa4bc440.tar.xz openssl-285e2991af23974761b9497f1e2a3396aa4bc440.zip |
TEST: add util/wrap.pl and use it
util/wrap.pl is a script that defines the environment variables
OPENSSL_ENGINES and OPENSSL_MODULES, then calls the command line
that's given as its arguments.
On a POSIX platform, the command line call is done via
util/shlib_wrap.sh to ensure that the shared library paths are
correct. For other platforms, util/wrap.pl currently assumes that
similar things are already in place through other means.
Reviewed-by: Matthias St. Pierre <Matthias.St.Pierre@ncp-e.com>
(Merged from https://github.com/openssl/openssl/pull/11110)
-rw-r--r-- | util/perl/OpenSSL/Test.pm | 30 | ||||
-rwxr-xr-x | util/wrap.pl | 43 |
2 files changed, 67 insertions, 6 deletions
diff --git a/util/perl/OpenSSL/Test.pm b/util/perl/OpenSSL/Test.pm index 4297106392..bb39854a4d 100644 --- a/util/perl/OpenSSL/Test.pm +++ b/util/perl/OpenSSL/Test.pm @@ -1178,13 +1178,31 @@ sub __wrap_cmd { my $cmd = shift; my $exe_shell = shift; - my @prefix = ( __bldtop_file("util", "shlib_wrap.sh") ); + my @prefix = (); - if(defined($exe_shell)) { - @prefix = ( $exe_shell ); - } elsif ($^O eq "VMS" || $^O eq "MSWin32") { - # VMS and Windows don't use any wrapper script for the moment - @prefix = (); + if (defined($exe_shell)) { + # If $exe_shell is defined, trust it + @prefix = ( $exe_shell ); + } else { + # Otherwise, use the standard wrapper + my $std_wrapper = __bldtop_file("util", "wrap.pl"); + + if ($^O eq "VMS") { + # On VMS, running random executables without having a command + # symbol means running them with the MCR command. This is an + # old PDP-11 command that stuck around. So we get a command + # running perl running the script. + @prefix = ( "MCR", $^X, $std_wrapper ); + } elsif ($^O eq "MSWin32") { + # In the Windows case, we run perl explicitly. We might not + # need it, but that depends on if the user has associated the + # '.pl' extension with a perl interpreter, so better be safe. + @prefix = ( $^X, $std_wrapper ); + } else { + # Otherwise, we assume Unix semantics, and trust that the #! + # line activates perl for us. + @prefix = ( $std_wrapper ); + } } return (@prefix, $cmd); diff --git a/util/wrap.pl b/util/wrap.pl new file mode 100755 index 0000000000..1c3b4e7c29 --- /dev/null +++ b/util/wrap.pl @@ -0,0 +1,43 @@ +#! /usr/bin/env perl + +use strict; +use warnings; + +use File::Basename; +use File::Spec::Functions; + +my $there = canonpath(catdir(dirname($0), updir())); +my $std_engines = catdir($there, 'engines'); +my $std_providers = catdir($there, 'providers'); +my $unix_shlib_wrap = catfile($there, 'util/shlib_wrap.sh'); + +$ENV{OPENSSL_ENGINES} = $std_engines + if ($ENV{OPENSSL_ENGINES} // '') eq '' && -d $std_engines; +$ENV{OPENSSL_MODULES} = $std_providers + if ($ENV{OPENSSL_MODULES} // '') eq '' && -d $std_providers; + +my $use_system = 0; +my @cmd; + +if (($ENV{EXE_SHELL} // '') ne '') { + # We don't know what $ENV{EXE_SHELL} contains, so we must use the one + # string form to ensure that exec invokes a shell as needed. + @cmd = ( join(' ', $ENV{EXE_SHELL}, @ARGV) ); +} elsif (-x $unix_shlib_wrap) { + @cmd = ( $unix_shlib_wrap, @ARGV ); +} else { + # Hope for the best + @cmd = ( @ARGV ); +} + +# The exec() statement on MSWin32 doesn't seem to give back the exit code +# from the call, so we resort to using system() instead. +my $waitcode = system @cmd; + +# According to documentation, -1 means that system() couldn't run the command, +# otherwise, the value is similar to the Unix wait() status value +# (exitcode << 8 | signalcode) +die "wrap.pl: Failed to execute '", join(' ', @cmd), "': $!\n" + if $waitcode == -1; +exit($? & 255) if ($? & 255) != 0; +exit($? >> 8); |