wrap.pl 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 $unix_shlib_wrap = catfile($there, 'util/shlib_wrap.sh');
  10. $ENV{OPENSSL_ENGINES} = $std_engines
  11. if ($ENV{OPENSSL_ENGINES} // '') eq '' && -d $std_engines;
  12. $ENV{OPENSSL_MODULES} = $std_providers
  13. if ($ENV{OPENSSL_MODULES} // '') eq '' && -d $std_providers;
  14. my $use_system = 0;
  15. my @cmd;
  16. if (-x $unix_shlib_wrap) {
  17. @cmd = ( $unix_shlib_wrap, @ARGV );
  18. } else {
  19. # Hope for the best
  20. @cmd = ( @ARGV );
  21. }
  22. # The exec() statement on MSWin32 doesn't seem to give back the exit code
  23. # from the call, so we resort to using system() instead.
  24. my $waitcode = system @cmd;
  25. # According to documentation, -1 means that system() couldn't run the command,
  26. # otherwise, the value is similar to the Unix wait() status value
  27. # (exitcode << 8 | signalcode)
  28. die "wrap.pl: Failed to execute '", join(' ', @cmd), "': $!\n"
  29. if $waitcode == -1;
  30. # When the subprocess aborted on a signal, mimic what Unix shells do, by
  31. # converting the signal code to an exit code by setting the high bit.
  32. # This only happens on Unix flavored operating systems, the others don't
  33. # have this sort of signaling to date, and simply leave the low byte zero.
  34. exit(($? & 255) | 128) if ($? & 255) != 0;
  35. # When not a signal, just shift down the subprocess exit code and use that.
  36. exit($? >> 8);