Raise an error on syscall failure in tls_retry_write_records
[openssl.git] / util / wrap.pl
1 #! /usr/bin/env perl
2
3 use strict;
4 use warnings;
5
6 use File::Basename;
7 use File::Spec::Functions;
8
9 my $there = canonpath(catdir(dirname($0), updir()));
10 my $std_engines = catdir($there, 'engines');
11 my $std_providers = catdir($there, 'providers');
12 my $std_openssl_conf = catdir($there, 'apps/openssl.cnf');
13 my $unix_shlib_wrap = catfile($there, 'util/shlib_wrap.sh');
14
15 $ENV{OPENSSL_ENGINES} = $std_engines
16     if ($ENV{OPENSSL_ENGINES} // '') eq '' && -d $std_engines;
17 $ENV{OPENSSL_MODULES} = $std_providers
18     if ($ENV{OPENSSL_MODULES} // '') eq '' && -d $std_providers;
19 $ENV{OPENSSL_CONF} = $std_openssl_conf
20     if ($ENV{OPENSSL_CONF} // '') eq '' && -f $std_openssl_conf;
21
22 my $use_system = 0;
23 my @cmd;
24
25 if (-x $unix_shlib_wrap) {
26     @cmd = ( $unix_shlib_wrap, @ARGV );
27 } else {
28     # Hope for the best
29     @cmd = ( @ARGV );
30 }
31
32 # The exec() statement on MSWin32 doesn't seem to give back the exit code
33 # from the call, so we resort to using system() instead.
34 my $waitcode = system @cmd;
35
36 # According to documentation, -1 means that system() couldn't run the command,
37 # otherwise, the value is similar to the Unix wait() status value
38 # (exitcode << 8 | signalcode)
39 die "wrap.pl: Failed to execute '", join(' ', @cmd), "': $!\n"
40     if $waitcode == -1;
41
42 # When the subprocess aborted on a signal, mimic what Unix shells do, by
43 # converting the signal code to an exit code by setting the high bit.
44 # This only happens on Unix flavored operating systems, the others don't
45 # have this sort of signaling to date, and simply leave the low byte zero.
46 exit(($? & 255) | 128) if ($? & 255) != 0;
47
48 # When not a signal, just shift down the subprocess exit code and use that.
49 exit($? >> 8);