]> git.ipfire.org Git - thirdparty/openssl.git/blame - util/wrap.pl
TEST: add util/wrap.pl and use it
[thirdparty/openssl.git] / util / wrap.pl
CommitLineData
285e2991
RL
1#! /usr/bin/env perl
2
3use strict;
4use warnings;
5
6use File::Basename;
7use File::Spec::Functions;
8
9my $there = canonpath(catdir(dirname($0), updir()));
10my $std_engines = catdir($there, 'engines');
11my $std_providers = catdir($there, 'providers');
12my $unix_shlib_wrap = catfile($there, 'util/shlib_wrap.sh');
13
14$ENV{OPENSSL_ENGINES} = $std_engines
15 if ($ENV{OPENSSL_ENGINES} // '') eq '' && -d $std_engines;
16$ENV{OPENSSL_MODULES} = $std_providers
17 if ($ENV{OPENSSL_MODULES} // '') eq '' && -d $std_providers;
18
19my $use_system = 0;
20my @cmd;
21
22if (($ENV{EXE_SHELL} // '') ne '') {
23 # We don't know what $ENV{EXE_SHELL} contains, so we must use the one
24 # string form to ensure that exec invokes a shell as needed.
25 @cmd = ( join(' ', $ENV{EXE_SHELL}, @ARGV) );
26} elsif (-x $unix_shlib_wrap) {
27 @cmd = ( $unix_shlib_wrap, @ARGV );
28} else {
29 # Hope for the best
30 @cmd = ( @ARGV );
31}
32
33# The exec() statement on MSWin32 doesn't seem to give back the exit code
34# from the call, so we resort to using system() instead.
35my $waitcode = system @cmd;
36
37# According to documentation, -1 means that system() couldn't run the command,
38# otherwise, the value is similar to the Unix wait() status value
39# (exitcode << 8 | signalcode)
40die "wrap.pl: Failed to execute '", join(' ', @cmd), "': $!\n"
41 if $waitcode == -1;
42exit($? & 255) if ($? & 255) != 0;
43exit($? >> 8);