wrap.pl.in 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #! {- $config{HASHBANGPERL} -}
  2. use strict;
  3. use warnings;
  4. use File::Basename;
  5. use File::Spec::Functions;
  6. BEGIN {
  7. # This method corresponds exactly to 'use OpenSSL::Util',
  8. # but allows us to use a platform specific file spec.
  9. require {-
  10. use Cwd qw(abs_path);
  11. "'" . abs_path(catfile($config{sourcedir},
  12. 'util', 'perl', 'OpenSSL', 'Util.pm')) . "'";
  13. -};
  14. OpenSSL::Util->import();
  15. }
  16. my $there = canonpath(catdir(dirname($0), updir()));
  17. my $std_engines = catdir($there, 'engines');
  18. my $std_providers = catdir($there, 'providers');
  19. my $std_openssl_conf = catdir($there, 'apps/openssl.cnf');
  20. my $unix_shlib_wrap = catfile($there, 'util/shlib_wrap.sh');
  21. if ($ARGV[0] eq '-fips') {
  22. $std_openssl_conf = {-
  23. use Cwd qw(abs_path);
  24. "'" . abs_path(catfile($config{sourcedir}, 'test/fips-and-base.cnf')) . "'";
  25. -};
  26. shift;
  27. my $std_openssl_conf_include = catdir($there, 'providers');
  28. $ENV{OPENSSL_CONF_INCLUDE} = $std_openssl_conf_include
  29. if ($ENV{OPENSSL_CONF_INCLUDE} // '') eq ''
  30. && -d $std_openssl_conf_include;
  31. }
  32. $ENV{OPENSSL_ENGINES} = $std_engines
  33. if ($ENV{OPENSSL_ENGINES} // '') eq '' && -d $std_engines;
  34. $ENV{OPENSSL_MODULES} = $std_providers
  35. if ($ENV{OPENSSL_MODULES} // '') eq '' && -d $std_providers;
  36. $ENV{OPENSSL_CONF} = $std_openssl_conf
  37. if ($ENV{OPENSSL_CONF} // '') eq '' && -f $std_openssl_conf;
  38. my $use_system = 0;
  39. my @cmd;
  40. if ($^O eq 'VMS') {
  41. # VMS needs the command to be appropriately quotified
  42. @cmd = fixup_cmd(@ARGV);
  43. } elsif (-x $unix_shlib_wrap) {
  44. @cmd = ( $unix_shlib_wrap, @ARGV );
  45. } else {
  46. # Hope for the best
  47. @cmd = ( @ARGV );
  48. }
  49. # The exec() statement on MSWin32 doesn't seem to give back the exit code
  50. # from the call, so we resort to using system() instead.
  51. my $waitcode = system @cmd;
  52. # According to documentation, -1 means that system() couldn't run the command,
  53. # otherwise, the value is similar to the Unix wait() status value
  54. # (exitcode << 8 | signalcode)
  55. die "wrap.pl: Failed to execute '", join(' ', @cmd), "': $!\n"
  56. if $waitcode == -1;
  57. # When the subprocess aborted on a signal, we simply raise the same signal.
  58. kill(($? & 255) => $$) if ($? & 255) != 0;
  59. # If that didn't stop this script, mimic what Unix shells do, by
  60. # converting the signal code to an exit code by setting the high bit.
  61. # This only happens on Unix flavored operating systems, the others don't
  62. # have this sort of signaling to date, and simply leave the low byte zero.
  63. exit(($? & 255) | 128) if ($? & 255) != 0;
  64. # When not a signal, just shift down the subprocess exit code and use that.
  65. my $exitcode = $? >> 8;
  66. # For VMS, perl recommendations is to emulate what the C library exit() does
  67. # for all non-zero exit codes, except we set the error severity rather than
  68. # success.
  69. # Ref: https://perldoc.perl.org/perlport#exit
  70. # https://perldoc.perl.org/perlvms#$?
  71. if ($^O eq 'VMS' && $exitcode != 0) {
  72. $exitcode =
  73. 0x35a000 # C facility code
  74. + ($exitcode * 8) # shift up to make space for the 3 severity bits
  75. + 2 # Severity: E(rror)
  76. + 0x10000000; # bit 28 set => the shell stays silent
  77. }
  78. exit($exitcode);