2
0

wrap.pl.in 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. my $std_openssl_conf_include;
  22. if ($ARGV[0] eq '-fips') {
  23. $std_openssl_conf = {-
  24. use Cwd qw(abs_path);
  25. "'" . abs_path(catfile($config{sourcedir}, 'test/fips-and-base.cnf')) . "'";
  26. -};
  27. shift;
  28. $std_openssl_conf_include = catdir($there, 'providers');
  29. }
  30. local $ENV{OPENSSL_CONF_INCLUDE} = $std_openssl_conf_include
  31. if defined $std_openssl_conf_include
  32. &&($ENV{OPENSSL_CONF_INCLUDE} // '') eq ''
  33. && -d $std_openssl_conf_include;
  34. local $ENV{OPENSSL_ENGINES} = $std_engines
  35. if ($ENV{OPENSSL_ENGINES} // '') eq '' && -d $std_engines;
  36. local $ENV{OPENSSL_MODULES} = $std_providers
  37. if ($ENV{OPENSSL_MODULES} // '') eq '' && -d $std_providers;
  38. local $ENV{OPENSSL_CONF} = $std_openssl_conf
  39. if ($ENV{OPENSSL_CONF} // '') eq '' && -f $std_openssl_conf;
  40. {-
  41. # For VMS, we define logical names to get the libraries properly
  42. # defined.
  43. use File::Spec::Functions qw(rel2abs);
  44. if ($^O eq "VMS") {
  45. my $bldtop = rel2abs($config{builddir});
  46. my %names =
  47. map { platform->sharedname($_) => $bldtop.platform->sharedlib($_) }
  48. grep { !$unified_info{attributes}->{libraries}->{$_}->{noinst} }
  49. @{$unified_info{libraries}};
  50. foreach (sort keys %names) {
  51. $OUT .= "local \$ENV\{'$_'\} = '$names{$_}';\n";
  52. }
  53. }
  54. -}
  55. my $use_system = 0;
  56. my @cmd;
  57. if ($^O eq 'VMS') {
  58. # VMS needs the command to be appropriately quotified
  59. @cmd = fixup_cmd(@ARGV);
  60. } elsif (-x $unix_shlib_wrap) {
  61. @cmd = ( $unix_shlib_wrap, @ARGV );
  62. } else {
  63. # Hope for the best
  64. @cmd = ( @ARGV );
  65. }
  66. # The exec() statement on MSWin32 doesn't seem to give back the exit code
  67. # from the call, so we resort to using system() instead.
  68. my $waitcode = system @cmd;
  69. # According to documentation, -1 means that system() couldn't run the command,
  70. # otherwise, the value is similar to the Unix wait() status value
  71. # (exitcode << 8 | signalcode)
  72. die "wrap.pl: Failed to execute '", join(' ', @cmd), "': $!\n"
  73. if $waitcode == -1;
  74. # When the subprocess aborted on a signal, we simply raise the same signal.
  75. kill(($? & 255) => $$) if ($? & 255) != 0;
  76. # If that didn't stop this script, mimic what Unix shells do, by
  77. # converting the signal code to an exit code by setting the high bit.
  78. # This only happens on Unix flavored operating systems, the others don't
  79. # have this sort of signaling to date, and simply leave the low byte zero.
  80. exit(($? & 255) | 128) if ($? & 255) != 0;
  81. # When not a signal, just shift down the subprocess exit code and use that.
  82. my $exitcode = $? >> 8;
  83. # For VMS, perl recommendations is to emulate what the C library exit() does
  84. # for all non-zero exit codes, except we set the error severity rather than
  85. # success.
  86. # Ref: https://perldoc.perl.org/perlport#exit
  87. # https://perldoc.perl.org/perlvms#$?
  88. if ($^O eq 'VMS' && $exitcode != 0) {
  89. $exitcode =
  90. 0x35a000 # C facility code
  91. + ($exitcode * 8) # shift up to make space for the 3 severity bits
  92. + 2 # Severity: E(rror)
  93. + 0x10000000; # bit 28 set => the shell stays silent
  94. }
  95. exit($exitcode);