wrap.pl 2.2 KB

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