| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package IPC::System::Simple; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # ABSTRACT: Run commands simply, with detailed diagnostics | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 31 |  |  | 31 |  | 931648 | use 5.006; | 
|  | 31 |  |  |  |  | 276 |  | 
| 6 | 31 |  |  | 31 |  | 177 | use strict; | 
|  | 31 |  |  |  |  | 44 |  | 
|  | 31 |  |  |  |  | 667 |  | 
| 7 | 31 |  |  | 31 |  | 148 | use warnings; | 
|  | 31 |  |  |  |  | 63 |  | 
|  | 31 |  |  |  |  | 1114 |  | 
| 8 | 31 |  |  | 31 |  | 206 | use re 'taint'; | 
|  | 31 |  |  |  |  | 71 |  | 
|  | 31 |  |  |  |  | 1952 |  | 
| 9 | 31 |  |  | 31 |  | 217 | use Carp; | 
|  | 31 |  |  |  |  | 56 |  | 
|  | 31 |  |  |  |  | 2309 |  | 
| 10 | 31 |  |  | 31 |  | 201 | use List::Util qw(first); | 
|  | 31 |  |  |  |  | 69 |  | 
|  | 31 |  |  |  |  | 3790 |  | 
| 11 | 31 |  |  | 31 |  | 215 | use Scalar::Util qw(tainted); | 
|  | 31 |  |  |  |  | 71 |  | 
|  | 31 |  |  |  |  | 2035 |  | 
| 12 | 31 |  |  | 31 |  | 227 | use Config; | 
|  | 31 |  |  |  |  | 56 |  | 
|  | 31 |  |  |  |  | 1758 |  | 
| 13 | 31 |  |  | 31 |  | 241 | use constant WINDOWS => ($^O eq 'MSWin32'); | 
|  | 31 |  |  |  |  | 69 |  | 
|  | 31 |  |  |  |  | 3418 |  | 
| 14 | 31 |  |  | 31 |  | 221 | use constant VMS     => ($^O eq 'VMS'); | 
|  | 31 |  |  |  |  | 60 |  | 
|  | 31 |  |  |  |  | 2835 |  | 
| 15 |  |  |  |  |  |  |  | 
| 16 |  |  |  |  |  |  | BEGIN { | 
| 17 |  |  |  |  |  |  |  | 
| 18 |  |  |  |  |  |  | # It would be lovely to use the 'if' module here, but it didn't | 
| 19 |  |  |  |  |  |  | # enter core until 5.6.2, and we want to keep 5.6.0 compatibility. | 
| 20 |  |  |  |  |  |  |  | 
| 21 |  |  |  |  |  |  |  | 
| 22 | 31 |  |  | 31 |  | 910 | if (WINDOWS) { | 
| 23 |  |  |  |  |  |  |  | 
| 24 |  |  |  |  |  |  | ## no critic (ProhibitStringyEval) | 
| 25 |  |  |  |  |  |  |  | 
| 26 |  |  |  |  |  |  | eval q{ | 
| 27 |  |  |  |  |  |  | use Win32::Process qw(INFINITE NORMAL_PRIORITY_CLASS); | 
| 28 |  |  |  |  |  |  | use File::Spec; | 
| 29 |  |  |  |  |  |  | use Win32; | 
| 30 |  |  |  |  |  |  | use Win32::ShellQuote; | 
| 31 |  |  |  |  |  |  |  | 
| 32 |  |  |  |  |  |  | # This uses the same rules as the core win32.c/get_shell() call. | 
| 33 |  |  |  |  |  |  | use constant WINDOWS_SHELL => eval { Win32::IsWinNT() } | 
| 34 |  |  |  |  |  |  | ? [ File::Spec->catfile(Win32::GetFolderPath(Win32::CSIDL_SYSTEM), 'cmd.exe'), '/x/d/c' ] | 
| 35 |  |  |  |  |  |  | : [ File::Spec->catfile(Win32::GetFolderPath(Win32::CSIDL_SYSTEM), 'command.com'), '/c' ]; | 
| 36 |  |  |  |  |  |  |  | 
| 37 |  |  |  |  |  |  | # These are used when invoking _win32_capture | 
| 38 |  |  |  |  |  |  | use constant NO_SHELL  => 0; | 
| 39 |  |  |  |  |  |  | use constant USE_SHELL => 1; | 
| 40 |  |  |  |  |  |  |  | 
| 41 |  |  |  |  |  |  | }; | 
| 42 |  |  |  |  |  |  |  | 
| 43 |  |  |  |  |  |  | ## use critic | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | # Die nosily if any of the above broke. | 
| 46 |  |  |  |  |  |  | die $@ if $@; | 
| 47 |  |  |  |  |  |  | } | 
| 48 |  |  |  |  |  |  | } | 
| 49 |  |  |  |  |  |  |  | 
| 50 |  |  |  |  |  |  | # Note that we don't use WIFSTOPPED because perl never uses | 
| 51 |  |  |  |  |  |  | # the WUNTRACED flag, and hence will never return early from | 
| 52 |  |  |  |  |  |  | # system() if the child processes is suspended with a SIGSTOP. | 
| 53 |  |  |  |  |  |  |  | 
| 54 | 31 |  |  | 31 |  | 16369 | use POSIX qw(WIFEXITED WEXITSTATUS WIFSIGNALED WTERMSIG); | 
|  | 31 |  |  |  |  | 211637 |  | 
|  | 31 |  |  |  |  | 226 |  | 
| 55 |  |  |  |  |  |  |  | 
| 56 | 31 |  |  | 31 |  | 45874 | use constant FAIL_START     => q{"%s" failed to start: "%s"}; | 
|  | 31 |  |  |  |  | 64 |  | 
|  | 31 |  |  |  |  | 2132 |  | 
| 57 | 31 |  |  | 31 |  | 492 | use constant FAIL_PLUMBING  => q{Error in IPC::System::Simple plumbing: "%s" - "%s"}; | 
|  | 31 |  |  |  |  | 74 |  | 
|  | 31 |  |  |  |  | 1818 |  | 
| 58 | 31 |  |  | 31 |  | 200 | use constant FAIL_CMD_BLANK => q{Entirely blank command passed: "%s"}; | 
|  | 31 |  |  |  |  | 91 |  | 
|  | 31 |  |  |  |  | 1665 |  | 
| 59 | 31 |  |  | 31 |  | 188 | use constant FAIL_INTERNAL  => q{Internal error in IPC::System::Simple: "%s"}; | 
|  | 31 |  |  |  |  | 59 |  | 
|  | 31 |  |  |  |  | 1564 |  | 
| 60 | 31 |  |  | 31 |  | 194 | use constant FAIL_TAINT     => q{%s called with tainted argument "%s"}; | 
|  | 31 |  |  |  |  | 52 |  | 
|  | 31 |  |  |  |  | 1536 |  | 
| 61 | 31 |  |  | 31 |  | 174 | use constant FAIL_TAINT_ENV => q{%s called with tainted environment $ENV{%s}}; | 
|  | 31 |  |  |  |  | 106 |  | 
|  | 31 |  |  |  |  | 1650 |  | 
| 62 | 31 |  |  | 31 |  | 246 | use constant FAIL_SIGNAL    => q{"%s" died to signal "%s" (%d)%s}; | 
|  | 31 |  |  |  |  | 74 |  | 
|  | 31 |  |  |  |  | 1578 |  | 
| 63 | 31 |  |  | 31 |  | 188 | use constant FAIL_BADEXIT   => q{"%s" unexpectedly returned exit value %d}; | 
|  | 31 |  |  |  |  | 58 |  | 
|  | 31 |  |  |  |  | 1658 |  | 
| 64 |  |  |  |  |  |  |  | 
| 65 | 31 |  |  | 31 |  | 190 | use constant FAIL_UNDEF     => q{%s called with undefined command}; | 
|  | 31 |  |  |  |  | 72 |  | 
|  | 31 |  |  |  |  | 1745 |  | 
| 66 |  |  |  |  |  |  |  | 
| 67 |  |  |  |  |  |  |  | 
| 68 | 31 |  |  | 31 |  | 195 | use constant FAIL_POSIX     => q{IPC::System::Simple does not understand the POSIX error '%s'.  Please check https://metacpan.org/pod/IPC::System::Simple to see if there is an updated version.  If not please report this as a bug to https://github.com/pjf/ipc-system-simple/issues}; | 
|  | 31 |  |  |  |  | 61 |  | 
|  | 31 |  |  |  |  | 1699 |  | 
| 69 |  |  |  |  |  |  |  | 
| 70 |  |  |  |  |  |  | # On Perl's older than 5.8.x we can't assume that there'll be a | 
| 71 |  |  |  |  |  |  | # $^{TAINT} for us to check, so we assume that our args may always | 
| 72 |  |  |  |  |  |  | # be tainted. | 
| 73 | 31 |  |  | 31 |  | 186 | use constant ASSUME_TAINTED => ($] < 5.008); | 
|  | 31 |  |  |  |  | 364 |  | 
|  | 31 |  |  |  |  | 2172 |  | 
| 74 |  |  |  |  |  |  |  | 
| 75 | 31 |  |  | 31 |  | 340 | use constant EXIT_ANY_CONST => -1;			# Used internally | 
|  | 31 |  |  |  |  | 53 |  | 
|  | 31 |  |  |  |  | 1699 |  | 
| 76 | 31 |  |  | 31 |  | 185 | use constant EXIT_ANY       => [ EXIT_ANY_CONST ];	# Exported | 
|  | 31 |  |  |  |  | 71 |  | 
|  | 31 |  |  |  |  | 3810 |  | 
| 77 |  |  |  |  |  |  |  | 
| 78 | 31 |  |  | 31 |  | 235 | use constant UNDEFINED_POSIX_RE => qr{not (?:defined|a valid) POSIX macro|not implemented on this architecture}; | 
|  | 31 |  |  |  |  | 52 |  | 
|  | 31 |  |  |  |  | 7563 |  | 
| 79 |  |  |  |  |  |  |  | 
| 80 |  |  |  |  |  |  | require Exporter; | 
| 81 |  |  |  |  |  |  | our @ISA = qw(Exporter); | 
| 82 |  |  |  |  |  |  |  | 
| 83 |  |  |  |  |  |  | our @EXPORT_OK = qw( | 
| 84 |  |  |  |  |  |  | capture  capturex | 
| 85 |  |  |  |  |  |  | run      runx | 
| 86 |  |  |  |  |  |  | system   systemx | 
| 87 |  |  |  |  |  |  | $EXITVAL EXIT_ANY | 
| 88 |  |  |  |  |  |  | ); | 
| 89 |  |  |  |  |  |  |  | 
| 90 |  |  |  |  |  |  | our $VERSION = '1.29'; | 
| 91 |  |  |  |  |  |  | $VERSION =~ tr/_//d; | 
| 92 |  |  |  |  |  |  |  | 
| 93 |  |  |  |  |  |  | our $EXITVAL = -1; | 
| 94 |  |  |  |  |  |  |  | 
| 95 |  |  |  |  |  |  | my @Signal_from_number = split(' ', $Config{sig_name}); | 
| 96 |  |  |  |  |  |  |  | 
| 97 |  |  |  |  |  |  | # Environment variables we don't want to see tainted. | 
| 98 |  |  |  |  |  |  | my @Check_tainted_env = qw(PATH IFS CDPATH ENV BASH_ENV); | 
| 99 |  |  |  |  |  |  | if (WINDOWS) { | 
| 100 |  |  |  |  |  |  | push(@Check_tainted_env, 'PERL5SHELL'); | 
| 101 |  |  |  |  |  |  | } | 
| 102 |  |  |  |  |  |  | if (VMS) { | 
| 103 |  |  |  |  |  |  | push(@Check_tainted_env, 'DCL$PATH'); | 
| 104 |  |  |  |  |  |  | } | 
| 105 |  |  |  |  |  |  |  | 
| 106 |  |  |  |  |  |  | # Not all systems implement the WIFEXITED calls, but POSIX | 
| 107 |  |  |  |  |  |  | # will always export them (even if they're just stubs that | 
| 108 |  |  |  |  |  |  | # die with an error).  Test for the presence of a working | 
| 109 |  |  |  |  |  |  | # WIFEXITED and friends, or define our own. | 
| 110 |  |  |  |  |  |  |  | 
| 111 |  |  |  |  |  |  | eval { WIFEXITED(0); }; | 
| 112 |  |  |  |  |  |  |  | 
| 113 |  |  |  |  |  |  | if ($@ =~ UNDEFINED_POSIX_RE) { | 
| 114 | 31 |  |  | 31 |  | 233 | no warnings 'redefine';  ## no critic | 
|  | 31 |  |  |  |  | 73 |  | 
|  | 31 |  |  |  |  | 9188 |  | 
| 115 |  |  |  |  |  |  | *WIFEXITED   = sub { not $_[0] & 0xff }; | 
| 116 |  |  |  |  |  |  | *WEXITSTATUS = sub { $_[0] >> 8  }; | 
| 117 |  |  |  |  |  |  | *WIFSIGNALED = sub { $_[0] & 127 }; | 
| 118 |  |  |  |  |  |  | *WTERMSIG    = sub { $_[0] & 127 }; | 
| 119 |  |  |  |  |  |  | } elsif ($@) { | 
| 120 |  |  |  |  |  |  | croak sprintf FAIL_POSIX, $@; | 
| 121 |  |  |  |  |  |  | } | 
| 122 |  |  |  |  |  |  |  | 
| 123 |  |  |  |  |  |  | # None of the POSIX modules I've found define WCOREDUMP, although | 
| 124 |  |  |  |  |  |  | # many systems define it.  Check the POSIX module in the hope that | 
| 125 |  |  |  |  |  |  | # it may actually be there. | 
| 126 |  |  |  |  |  |  |  | 
| 127 |  |  |  |  |  |  |  | 
| 128 |  |  |  |  |  |  | # TODO: Ideally, $NATIVE_WCOREDUMP should be a constant. | 
| 129 |  |  |  |  |  |  |  | 
| 130 |  |  |  |  |  |  | my $NATIVE_WCOREDUMP; | 
| 131 |  |  |  |  |  |  |  | 
| 132 |  |  |  |  |  |  | eval { POSIX::WCOREDUMP(1); }; | 
| 133 |  |  |  |  |  |  |  | 
| 134 |  |  |  |  |  |  | if ($@ =~ UNDEFINED_POSIX_RE) { | 
| 135 | 360 |  |  | 360 |  | 3988 | *WCOREDUMP = sub { $_[0] & 128 }; | 
| 136 |  |  |  |  |  |  | $NATIVE_WCOREDUMP = 0; | 
| 137 |  |  |  |  |  |  | } elsif ($@) { | 
| 138 |  |  |  |  |  |  | croak sprintf FAIL_POSIX, $@; | 
| 139 |  |  |  |  |  |  | } else { | 
| 140 |  |  |  |  |  |  | # POSIX actually has it defined!  Huzzah! | 
| 141 |  |  |  |  |  |  | *WCOREDUMP = \&POSIX::WCOREDUMP; | 
| 142 |  |  |  |  |  |  | $NATIVE_WCOREDUMP = 1; | 
| 143 |  |  |  |  |  |  | } | 
| 144 |  |  |  |  |  |  |  | 
| 145 |  |  |  |  |  |  | sub _native_wcoredump { | 
| 146 | 0 |  |  | 0 |  | 0 | return $NATIVE_WCOREDUMP; | 
| 147 |  |  |  |  |  |  | } | 
| 148 |  |  |  |  |  |  |  | 
| 149 |  |  |  |  |  |  | # system simply calls run | 
| 150 |  |  |  |  |  |  |  | 
| 151 | 31 |  |  | 31 |  | 237 | no warnings 'once'; ## no critic | 
|  | 31 |  |  |  |  | 60 |  | 
|  | 31 |  |  |  |  | 2000 |  | 
| 152 |  |  |  |  |  |  | *system  = \&run; | 
| 153 |  |  |  |  |  |  | *systemx = \&runx; | 
| 154 | 31 |  |  | 31 |  | 205 | use warnings; | 
|  | 31 |  |  |  |  | 54 |  | 
|  | 31 |  |  |  |  | 5296 |  | 
| 155 |  |  |  |  |  |  |  | 
| 156 |  |  |  |  |  |  | # run is our way of running a process with system() semantics | 
| 157 |  |  |  |  |  |  |  | 
| 158 |  |  |  |  |  |  | sub run { | 
| 159 |  |  |  |  |  |  |  | 
| 160 | 114 |  |  | 114 | 1 | 159593 | _check_taint(@_); | 
| 161 |  |  |  |  |  |  |  | 
| 162 | 104 |  |  |  |  | 470 | my ($valid_returns, $command, @args) = _process_args(@_); | 
| 163 |  |  |  |  |  |  |  | 
| 164 |  |  |  |  |  |  | # If we have arguments, we really want to call systemx, | 
| 165 |  |  |  |  |  |  | # so we do so. | 
| 166 |  |  |  |  |  |  |  | 
| 167 | 98 | 100 |  |  |  | 487 | if (@args) { | 
| 168 | 60 |  |  |  |  | 277 | return systemx($valid_returns, $command, @args); | 
| 169 |  |  |  |  |  |  | } | 
| 170 |  |  |  |  |  |  |  | 
| 171 | 38 |  |  |  |  | 101 | if (WINDOWS) { | 
| 172 |  |  |  |  |  |  | my $pid = _spawn_or_die(&WINDOWS_SHELL->[0], join ' ', @{&WINDOWS_SHELL}, $command); | 
| 173 |  |  |  |  |  |  | $pid->Wait(INFINITE);	# Wait for process exit. | 
| 174 |  |  |  |  |  |  | $pid->GetExitCode($EXITVAL); | 
| 175 |  |  |  |  |  |  | return _check_exit($command,$EXITVAL,$valid_returns); | 
| 176 |  |  |  |  |  |  | } | 
| 177 |  |  |  |  |  |  |  | 
| 178 |  |  |  |  |  |  | # Without arguments, we're calling system, and checking | 
| 179 |  |  |  |  |  |  | # the results. | 
| 180 |  |  |  |  |  |  |  | 
| 181 |  |  |  |  |  |  | # We're throwing our own exception on command not found, so | 
| 182 |  |  |  |  |  |  | # we don't need a warning from Perl. | 
| 183 |  |  |  |  |  |  |  | 
| 184 |  |  |  |  |  |  | { | 
| 185 |  |  |  |  |  |  | # silence 'Statement unlikely to be reached' warning | 
| 186 | 31 |  |  | 31 |  | 215 | no warnings 'exec';             ## no critic | 
|  | 31 |  |  |  |  | 58 |  | 
|  | 31 |  |  |  |  | 6485 |  | 
|  | 38 |  |  |  |  | 93 |  | 
| 187 | 38 |  |  |  |  | 281271 | CORE::system($command,@args); | 
| 188 |  |  |  |  |  |  | } | 
| 189 |  |  |  |  |  |  |  | 
| 190 | 38 |  |  |  |  | 1990 | return _process_child_error($?,$command,$valid_returns); | 
| 191 |  |  |  |  |  |  | } | 
| 192 |  |  |  |  |  |  |  | 
| 193 |  |  |  |  |  |  | # runx is just like system/run, but *never* invokes the shell. | 
| 194 |  |  |  |  |  |  |  | 
| 195 |  |  |  |  |  |  | sub runx { | 
| 196 | 96 |  |  | 96 | 1 | 96171 | _check_taint(@_); | 
| 197 |  |  |  |  |  |  |  | 
| 198 | 96 |  |  |  |  | 354 | my ($valid_returns, $command, @args) = _process_args(@_); | 
| 199 |  |  |  |  |  |  |  | 
| 200 | 96 |  |  |  |  | 195 | if (WINDOWS) { | 
| 201 |  |  |  |  |  |  | our $EXITVAL = -1; | 
| 202 |  |  |  |  |  |  |  | 
| 203 |  |  |  |  |  |  | my $pid = _spawn_or_die($command, Win32::ShellQuote::quote_native($command, @args)); | 
| 204 |  |  |  |  |  |  |  | 
| 205 |  |  |  |  |  |  | $pid->Wait(INFINITE);	# Wait for process exit. | 
| 206 |  |  |  |  |  |  | $pid->GetExitCode($EXITVAL); | 
| 207 |  |  |  |  |  |  | return _check_exit($command,$EXITVAL,$valid_returns); | 
| 208 |  |  |  |  |  |  | } | 
| 209 |  |  |  |  |  |  |  | 
| 210 |  |  |  |  |  |  | # If system() fails, we throw our own exception.  We don't | 
| 211 |  |  |  |  |  |  | # need to have perl complain about it too. | 
| 212 |  |  |  |  |  |  |  | 
| 213 | 31 |  |  | 31 |  | 226 | no warnings; ## no critic | 
|  | 31 |  |  |  |  | 65 |  | 
|  | 31 |  |  |  |  | 5439 |  | 
| 214 |  |  |  |  |  |  |  | 
| 215 | 96 |  |  |  |  | 157 | CORE::system { $command } $command, @args; | 
|  | 96 |  |  |  |  | 527758 |  | 
| 216 |  |  |  |  |  |  |  | 
| 217 | 96 |  |  |  |  | 6779 | return _process_child_error($?, $command, $valid_returns); | 
| 218 |  |  |  |  |  |  | } | 
| 219 |  |  |  |  |  |  |  | 
| 220 |  |  |  |  |  |  | # capture is our way of running a process with backticks/qx semantics | 
| 221 |  |  |  |  |  |  |  | 
| 222 |  |  |  |  |  |  | sub capture { | 
| 223 | 57 |  |  | 57 | 1 | 122304 | _check_taint(@_); | 
| 224 |  |  |  |  |  |  |  | 
| 225 | 57 |  |  |  |  | 430 | my ($valid_returns, $command, @args) = _process_args(@_); | 
| 226 |  |  |  |  |  |  |  | 
| 227 | 53 | 100 |  |  |  | 395 | if (@args) { | 
| 228 | 39 |  |  |  |  | 370 | return capturex($valid_returns, $command, @args); | 
| 229 |  |  |  |  |  |  | } | 
| 230 |  |  |  |  |  |  |  | 
| 231 | 14 |  |  |  |  | 91 | if (WINDOWS) { | 
| 232 |  |  |  |  |  |  | # USE_SHELL really means "You may use the shell if you need it." | 
| 233 |  |  |  |  |  |  | return _win32_capture(USE_SHELL, $valid_returns, $command); | 
| 234 |  |  |  |  |  |  | } | 
| 235 |  |  |  |  |  |  |  | 
| 236 | 14 |  |  |  |  | 67 | our $EXITVAL = -1; | 
| 237 |  |  |  |  |  |  |  | 
| 238 | 14 |  |  |  |  | 113 | my $wantarray = wantarray(); | 
| 239 |  |  |  |  |  |  |  | 
| 240 |  |  |  |  |  |  | # We'll produce our own warnings on failure to execute. | 
| 241 | 31 |  |  | 31 |  | 231 | no warnings 'exec';	## no critic | 
|  | 31 |  |  |  |  | 65 |  | 
|  | 31 |  |  |  |  | 22568 |  | 
| 242 |  |  |  |  |  |  |  | 
| 243 | 14 | 100 |  |  |  | 96 | if ($wantarray) { | 
| 244 | 1 |  |  |  |  | 4909 | my @results = qx($command); | 
| 245 | 1 |  |  |  |  | 39 | _process_child_error($?,$command,$valid_returns); | 
| 246 | 1 |  |  |  |  | 30 | return @results; | 
| 247 |  |  |  |  |  |  | } | 
| 248 |  |  |  |  |  |  |  | 
| 249 | 13 |  |  |  |  | 50240 | my $results = qx($command); | 
| 250 | 13 |  |  |  |  | 958 | _process_child_error($?,$command,$valid_returns); | 
| 251 | 10 |  |  |  |  | 324 | return $results; | 
| 252 |  |  |  |  |  |  | } | 
| 253 |  |  |  |  |  |  |  | 
| 254 |  |  |  |  |  |  | # _win32_capture implements the capture and capurex commands on Win32. | 
| 255 |  |  |  |  |  |  | # We need to wrap the whole internals of this sub into | 
| 256 |  |  |  |  |  |  | # an if (WINDOWS) block to avoid it being compiled on non-Win32 systems. | 
| 257 |  |  |  |  |  |  |  | 
| 258 |  |  |  |  |  |  | sub _win32_capture { | 
| 259 | 0 |  |  | 0 |  | 0 | if (not WINDOWS) { | 
| 260 | 0 |  |  |  |  | 0 | croak sprintf(FAIL_INTERNAL, "_win32_capture called when not under Win32"); | 
| 261 |  |  |  |  |  |  | } else { | 
| 262 |  |  |  |  |  |  |  | 
| 263 |  |  |  |  |  |  | my ($use_shell, $valid_returns, $command, @args) = @_; | 
| 264 |  |  |  |  |  |  |  | 
| 265 |  |  |  |  |  |  | my $wantarray = wantarray(); | 
| 266 |  |  |  |  |  |  |  | 
| 267 |  |  |  |  |  |  | # Perl doesn't support multi-arg open under | 
| 268 |  |  |  |  |  |  | # Windows.  Perl also doesn't provide very good | 
| 269 |  |  |  |  |  |  | # feedback when normal backtails fail, either; | 
| 270 |  |  |  |  |  |  | # it returns exit status from the shell | 
| 271 |  |  |  |  |  |  | # (which is indistinguishable from the command | 
| 272 |  |  |  |  |  |  | # running and producing the same exit status). | 
| 273 |  |  |  |  |  |  |  | 
| 274 |  |  |  |  |  |  | # As such, we essentially have to write our own | 
| 275 |  |  |  |  |  |  | # backticks. | 
| 276 |  |  |  |  |  |  |  | 
| 277 |  |  |  |  |  |  | # We start by dup'ing STDOUT. | 
| 278 |  |  |  |  |  |  |  | 
| 279 |  |  |  |  |  |  | open(my $saved_stdout, '>&', \*STDOUT)  ## no critic | 
| 280 |  |  |  |  |  |  | or croak sprintf(FAIL_PLUMBING, "Can't dup STDOUT", $!); | 
| 281 |  |  |  |  |  |  |  | 
| 282 |  |  |  |  |  |  | # We now open up a pipe that will allow us to | 
| 283 |  |  |  |  |  |  | # communicate with the new process. | 
| 284 |  |  |  |  |  |  |  | 
| 285 |  |  |  |  |  |  | pipe(my ($read_fh, $write_fh)) | 
| 286 |  |  |  |  |  |  | or croak sprintf(FAIL_PLUMBING, "Can't create pipe", $!); | 
| 287 |  |  |  |  |  |  |  | 
| 288 |  |  |  |  |  |  | # Allow CRLF sequences to become "\n", since | 
| 289 |  |  |  |  |  |  | # this is what Perl backticks do. | 
| 290 |  |  |  |  |  |  |  | 
| 291 |  |  |  |  |  |  | binmode($read_fh, ':crlf'); | 
| 292 |  |  |  |  |  |  |  | 
| 293 |  |  |  |  |  |  | # Now we re-open our STDOUT to $write_fh... | 
| 294 |  |  |  |  |  |  |  | 
| 295 |  |  |  |  |  |  | open(STDOUT, '>&', $write_fh)  ## no critic | 
| 296 |  |  |  |  |  |  | or croak sprintf(FAIL_PLUMBING, "Can't redirect STDOUT", $!); | 
| 297 |  |  |  |  |  |  |  | 
| 298 |  |  |  |  |  |  | # If we have args, or we're told not to use the shell, then | 
| 299 |  |  |  |  |  |  | # we treat $command as our shell.  Otherwise we grub around | 
| 300 |  |  |  |  |  |  | # in our command to look for a command to run. | 
| 301 |  |  |  |  |  |  | # | 
| 302 |  |  |  |  |  |  | # Note that we don't actually *use* the shell (although in | 
| 303 |  |  |  |  |  |  | # a future version we might).  Being told not to use the shell | 
| 304 |  |  |  |  |  |  | # (capturex) means we treat our command as really being a command, | 
| 305 |  |  |  |  |  |  | # and not a command line. | 
| 306 |  |  |  |  |  |  |  | 
| 307 |  |  |  |  |  |  | my $exe =   @args                      ? $command : | 
| 308 |  |  |  |  |  |  | (! $use_shell)             ? $command : | 
| 309 |  |  |  |  |  |  | $command =~ m{^"([^"]+)"}x ? $1       : | 
| 310 |  |  |  |  |  |  | $command =~ m{(\S+)     }x ? $1       : | 
| 311 |  |  |  |  |  |  | croak sprintf(FAIL_CMD_BLANK, $command); | 
| 312 |  |  |  |  |  |  |  | 
| 313 |  |  |  |  |  |  | # And now we spawn our new process with inherited | 
| 314 |  |  |  |  |  |  | # filehandles. | 
| 315 |  |  |  |  |  |  |  | 
| 316 |  |  |  |  |  |  | my $err; | 
| 317 |  |  |  |  |  |  | my $pid = eval { | 
| 318 |  |  |  |  |  |  | _spawn_or_die($exe, @args ? Win32::ShellQuote::quote_native($command, @args) : $command); | 
| 319 |  |  |  |  |  |  | } | 
| 320 |  |  |  |  |  |  | or do { | 
| 321 |  |  |  |  |  |  | $err = $@; | 
| 322 |  |  |  |  |  |  | }; | 
| 323 |  |  |  |  |  |  |  | 
| 324 |  |  |  |  |  |  | # Regardless of whether our command ran, we must restore STDOUT. | 
| 325 |  |  |  |  |  |  | # RT #48319 | 
| 326 |  |  |  |  |  |  | open(STDOUT, '>&', $saved_stdout)  ## no critic | 
| 327 |  |  |  |  |  |  | or croak sprintf(FAIL_PLUMBING,"Can't restore STDOUT", $!); | 
| 328 |  |  |  |  |  |  |  | 
| 329 |  |  |  |  |  |  | # And now, if there was an actual error , propagate it. | 
| 330 |  |  |  |  |  |  | die $err if defined $err;   # If there's an error from _spawn_or_die | 
| 331 |  |  |  |  |  |  |  | 
| 332 |  |  |  |  |  |  | # Clean-up the filehandles we no longer need... | 
| 333 |  |  |  |  |  |  |  | 
| 334 |  |  |  |  |  |  | close($write_fh) | 
| 335 |  |  |  |  |  |  | or croak sprintf(FAIL_PLUMBING,q{Can't close write end of pipe}, $!); | 
| 336 |  |  |  |  |  |  | close($saved_stdout) | 
| 337 |  |  |  |  |  |  | or croak sprintf(FAIL_PLUMBING,q{Can't close saved STDOUT}, $!); | 
| 338 |  |  |  |  |  |  |  | 
| 339 |  |  |  |  |  |  | # Read the data from our child... | 
| 340 |  |  |  |  |  |  |  | 
| 341 |  |  |  |  |  |  | my (@results, $result); | 
| 342 |  |  |  |  |  |  |  | 
| 343 |  |  |  |  |  |  | if ($wantarray) { | 
| 344 |  |  |  |  |  |  | @results = <$read_fh>; | 
| 345 |  |  |  |  |  |  | } else { | 
| 346 |  |  |  |  |  |  | $result = join("",<$read_fh>); | 
| 347 |  |  |  |  |  |  | } | 
| 348 |  |  |  |  |  |  |  | 
| 349 |  |  |  |  |  |  | # Tidy up our windows process and we're done! | 
| 350 |  |  |  |  |  |  |  | 
| 351 |  |  |  |  |  |  | $pid->Wait(INFINITE);	# Wait for process exit. | 
| 352 |  |  |  |  |  |  | $pid->GetExitCode($EXITVAL); | 
| 353 |  |  |  |  |  |  |  | 
| 354 |  |  |  |  |  |  | _check_exit($command,$EXITVAL,$valid_returns); | 
| 355 |  |  |  |  |  |  |  | 
| 356 |  |  |  |  |  |  | return $wantarray ? @results : $result; | 
| 357 |  |  |  |  |  |  |  | 
| 358 |  |  |  |  |  |  | } | 
| 359 |  |  |  |  |  |  | } | 
| 360 |  |  |  |  |  |  |  | 
| 361 |  |  |  |  |  |  | # capturex() is just like backticks/qx, but never invokes the shell. | 
| 362 |  |  |  |  |  |  |  | 
| 363 |  |  |  |  |  |  | sub capturex { | 
| 364 | 56 |  |  | 56 | 1 | 37920 | _check_taint(@_); | 
| 365 |  |  |  |  |  |  |  | 
| 366 | 56 |  |  |  |  | 327 | my ($valid_returns, $command, @args) = _process_args(@_); | 
| 367 |  |  |  |  |  |  |  | 
| 368 | 56 |  |  |  |  | 203 | our $EXITVAL = -1; | 
| 369 |  |  |  |  |  |  |  | 
| 370 | 56 |  |  |  |  | 143 | my $wantarray = wantarray(); | 
| 371 |  |  |  |  |  |  |  | 
| 372 | 56 |  |  |  |  | 179 | if (WINDOWS) { | 
| 373 |  |  |  |  |  |  | return _win32_capture(NO_SHELL, $valid_returns, $command, @args); | 
| 374 |  |  |  |  |  |  | } | 
| 375 |  |  |  |  |  |  |  | 
| 376 |  |  |  |  |  |  | # We can't use a multi-arg piped open here, since 5.6.x | 
| 377 |  |  |  |  |  |  | # doesn't like them.  Instead we emulate what 5.8.x does, | 
| 378 |  |  |  |  |  |  | # which is to create a pipe(), set the close-on-exec flag | 
| 379 |  |  |  |  |  |  | # on the child, and the fork/exec.  If the exec fails, the | 
| 380 |  |  |  |  |  |  | # child writes to the pipe.  If the exec succeeds, then | 
| 381 |  |  |  |  |  |  | # the pipe closes without data. | 
| 382 |  |  |  |  |  |  |  | 
| 383 | 56 | 50 |  |  |  | 3537 | pipe(my ($read_fh, $write_fh)) | 
| 384 |  |  |  |  |  |  | or croak sprintf(FAIL_PLUMBING, "Can't create pipe", $!); | 
| 385 |  |  |  |  |  |  |  | 
| 386 |  |  |  |  |  |  | # This next line also does an implicit fork. | 
| 387 | 56 |  |  |  |  | 45924 | my $pid = open(my $pipe, '-|');	 ## no critic | 
| 388 |  |  |  |  |  |  |  | 
| 389 | 56 | 50 |  |  |  | 5356 | if (not defined $pid) { | 
|  |  | 100 |  |  |  |  |  | 
| 390 | 0 |  |  |  |  | 0 | croak sprintf(FAIL_START, $command, $!); | 
| 391 |  |  |  |  |  |  | } elsif (not $pid) { | 
| 392 |  |  |  |  |  |  | # Child process, execs command. | 
| 393 |  |  |  |  |  |  |  | 
| 394 | 15 |  |  |  |  | 1174 | close($read_fh); | 
| 395 |  |  |  |  |  |  |  | 
| 396 |  |  |  |  |  |  | # TODO: 'no warnings exec' doesn't get rid | 
| 397 |  |  |  |  |  |  | # of the 'unlikely to be reached' warnings. | 
| 398 |  |  |  |  |  |  | # This is a bug in perl / perldiag / perllexwarn / warnings. | 
| 399 |  |  |  |  |  |  |  | 
| 400 | 31 |  |  | 31 |  | 248 | no warnings;   ## no critic | 
|  | 31 |  |  |  |  | 60 |  | 
|  | 31 |  |  |  |  | 34060 |  | 
| 401 |  |  |  |  |  |  |  | 
| 402 | 15 |  |  |  |  | 299 | CORE::exec { $command } $command, @args; | 
|  | 15 |  |  |  |  | 0 |  | 
| 403 |  |  |  |  |  |  |  | 
| 404 |  |  |  |  |  |  | # Oh no, exec fails!  Send the reason why to | 
| 405 |  |  |  |  |  |  | # the parent. | 
| 406 |  |  |  |  |  |  |  | 
| 407 | 0 |  |  |  |  | 0 | print {$write_fh} int($!); | 
|  | 0 |  |  |  |  | 0 |  | 
| 408 | 0 |  |  |  |  | 0 | exit(-1); | 
| 409 |  |  |  |  |  |  | } | 
| 410 |  |  |  |  |  |  |  | 
| 411 |  |  |  |  |  |  | { | 
| 412 |  |  |  |  |  |  | # In parent process. | 
| 413 |  |  |  |  |  |  |  | 
| 414 | 41 |  |  |  |  | 1252 | close($write_fh); | 
|  | 41 |  |  |  |  | 743 |  | 
| 415 |  |  |  |  |  |  |  | 
| 416 |  |  |  |  |  |  | # Parent process, check for child error. | 
| 417 | 41 |  |  |  |  | 11060003 | my $error = <$read_fh>; | 
| 418 |  |  |  |  |  |  |  | 
| 419 |  |  |  |  |  |  | # Tidy up our pipes. | 
| 420 | 41 |  |  |  |  | 2159 | close($read_fh); | 
| 421 |  |  |  |  |  |  |  | 
| 422 |  |  |  |  |  |  | # Check for error. | 
| 423 | 41 | 100 |  |  |  | 831 | if ($error) { | 
| 424 |  |  |  |  |  |  | # Setting $! to our child error number gives | 
| 425 |  |  |  |  |  |  | # us nice looking strings when printed. | 
| 426 | 5 |  |  |  |  | 189 | local $! = $error; | 
| 427 | 5 |  |  |  |  | 19010 | croak sprintf(FAIL_START, $command, $!); | 
| 428 |  |  |  |  |  |  | } | 
| 429 |  |  |  |  |  |  | } | 
| 430 |  |  |  |  |  |  |  | 
| 431 |  |  |  |  |  |  | # Parent process, we don't care about our pid, but we | 
| 432 |  |  |  |  |  |  | # do go and read our pipe. | 
| 433 |  |  |  |  |  |  |  | 
| 434 | 36 | 100 |  |  |  | 345 | if ($wantarray) { | 
| 435 | 7 |  |  |  |  | 21873 | my @results = <$pipe>; | 
| 436 | 7 |  |  |  |  | 452 | close($pipe); | 
| 437 | 7 |  |  |  |  | 284 | _process_child_error($?,$command,$valid_returns); | 
| 438 | 7 |  |  |  |  | 683 | return @results; | 
| 439 |  |  |  |  |  |  | } | 
| 440 |  |  |  |  |  |  |  | 
| 441 |  |  |  |  |  |  | # NB: We don't check the return status on close(), since | 
| 442 |  |  |  |  |  |  | # on failure it sets $?, which we then inspect for more | 
| 443 |  |  |  |  |  |  | # useful information. | 
| 444 |  |  |  |  |  |  |  | 
| 445 | 29 |  |  |  |  | 85305 | my $results = join("",<$pipe>); | 
| 446 | 29 |  |  |  |  | 1673 | close($pipe); | 
| 447 | 29 |  |  |  |  | 1001 | _process_child_error($?,$command,$valid_returns); | 
| 448 |  |  |  |  |  |  |  | 
| 449 | 29 |  |  |  |  | 2279 | return $results; | 
| 450 |  |  |  |  |  |  |  | 
| 451 |  |  |  |  |  |  | } | 
| 452 |  |  |  |  |  |  |  | 
| 453 |  |  |  |  |  |  | # Tries really hard to spawn a process under Windows.  Returns | 
| 454 |  |  |  |  |  |  | # the pid on success, or undef on error. | 
| 455 |  |  |  |  |  |  |  | 
| 456 |  |  |  |  |  |  | sub _spawn_or_die { | 
| 457 |  |  |  |  |  |  |  | 
| 458 |  |  |  |  |  |  | # We need to wrap practically the entire sub in an | 
| 459 |  |  |  |  |  |  | # if block to ensure it doesn't get compiled under non-Win32 | 
| 460 |  |  |  |  |  |  | # systems.  Compiling on these systems would not only be a | 
| 461 |  |  |  |  |  |  | # waste of time, but also results in complaints about | 
| 462 |  |  |  |  |  |  | # the NORMAL_PRIORITY_CLASS constant. | 
| 463 |  |  |  |  |  |  |  | 
| 464 | 1 |  |  | 1 |  | 841 | if (not WINDOWS) { | 
| 465 | 1 |  |  |  |  | 89 | croak sprintf(FAIL_INTERNAL, "_spawn_or_die called when not under Win32"); | 
| 466 |  |  |  |  |  |  | } else { | 
| 467 |  |  |  |  |  |  | my ($orig_exe, $cmdline) = @_; | 
| 468 |  |  |  |  |  |  | my $pid; | 
| 469 |  |  |  |  |  |  |  | 
| 470 |  |  |  |  |  |  | my $exe = $orig_exe; | 
| 471 |  |  |  |  |  |  |  | 
| 472 |  |  |  |  |  |  | # If our command doesn't have an extension, add one. | 
| 473 |  |  |  |  |  |  | $exe .= $Config{_exe} if ($exe !~ m{\.}); | 
| 474 |  |  |  |  |  |  |  | 
| 475 |  |  |  |  |  |  | Win32::Process::Create( | 
| 476 |  |  |  |  |  |  | $pid, $exe, $cmdline, 1, NORMAL_PRIORITY_CLASS, "." | 
| 477 |  |  |  |  |  |  | ) and return $pid; | 
| 478 |  |  |  |  |  |  |  | 
| 479 |  |  |  |  |  |  | my @path = split(/;/,$ENV{PATH}); | 
| 480 |  |  |  |  |  |  |  | 
| 481 |  |  |  |  |  |  | foreach my $dir (@path) { | 
| 482 |  |  |  |  |  |  | my $fullpath = File::Spec->catfile($dir,$exe); | 
| 483 |  |  |  |  |  |  |  | 
| 484 |  |  |  |  |  |  | # We're using -x here on the assumption that stat() | 
| 485 |  |  |  |  |  |  | # is faster than spawn, so trying to spawn a process | 
| 486 |  |  |  |  |  |  | # for each path element will be unacceptably | 
| 487 |  |  |  |  |  |  | # inefficient. | 
| 488 |  |  |  |  |  |  |  | 
| 489 |  |  |  |  |  |  | if (-x $fullpath) { | 
| 490 |  |  |  |  |  |  | Win32::Process::Create( | 
| 491 |  |  |  |  |  |  | $pid, $fullpath, $cmdline, 1, | 
| 492 |  |  |  |  |  |  | NORMAL_PRIORITY_CLASS, "." | 
| 493 |  |  |  |  |  |  | ) and return $pid; | 
| 494 |  |  |  |  |  |  | } | 
| 495 |  |  |  |  |  |  | } | 
| 496 |  |  |  |  |  |  |  | 
| 497 |  |  |  |  |  |  | croak sprintf(FAIL_START, $orig_exe, $^E); | 
| 498 |  |  |  |  |  |  | } | 
| 499 |  |  |  |  |  |  | } | 
| 500 |  |  |  |  |  |  |  | 
| 501 |  |  |  |  |  |  | # Complain on tainted arguments or environment. | 
| 502 |  |  |  |  |  |  | # ASSUME_TAINTED is true for 5.6.x, since it's missing ${^TAINT} | 
| 503 |  |  |  |  |  |  |  | 
| 504 |  |  |  |  |  |  | sub _check_taint { | 
| 505 | 323 | 100 |  | 323 |  | 3616 | return if not (ASSUME_TAINTED or ${^TAINT}); | 
| 506 | 23 |  |  |  |  | 212 | my $caller = (caller(1))[3]; | 
| 507 | 23 |  |  |  |  | 149 | foreach my $var (@_) { | 
| 508 | 50 | 100 |  |  |  | 182 | if (tainted $var) { | 
| 509 | 5 |  |  |  |  | 683 | croak sprintf(FAIL_TAINT, $caller, $var); | 
| 510 |  |  |  |  |  |  | } | 
| 511 |  |  |  |  |  |  | } | 
| 512 | 18 |  |  |  |  | 62 | foreach my $var (@Check_tainted_env) { | 
| 513 | 70 | 100 |  |  |  | 330 | if (tainted $ENV{$var} ) { | 
| 514 | 5 |  |  |  |  | 699 | croak sprintf(FAIL_TAINT_ENV, $caller, $var); | 
| 515 |  |  |  |  |  |  | } | 
| 516 |  |  |  |  |  |  | } | 
| 517 |  |  |  |  |  |  |  | 
| 518 | 13 |  |  |  |  | 49 | return; | 
| 519 |  |  |  |  |  |  |  | 
| 520 |  |  |  |  |  |  | } | 
| 521 |  |  |  |  |  |  |  | 
| 522 |  |  |  |  |  |  | # This subroutine performs the difficult task of interpreting | 
| 523 |  |  |  |  |  |  | # $?.  It's not intended to be called directly, as it will | 
| 524 |  |  |  |  |  |  | # croak on errors, and its implementation and interface may | 
| 525 |  |  |  |  |  |  | # change in the future. | 
| 526 |  |  |  |  |  |  |  | 
| 527 |  |  |  |  |  |  | sub _process_child_error { | 
| 528 | 184 |  |  | 184 |  | 4431 | my ($child_error, $command, $valid_returns) = @_; | 
| 529 |  |  |  |  |  |  |  | 
| 530 | 184 |  |  |  |  | 1560 | $EXITVAL = -1; | 
| 531 |  |  |  |  |  |  |  | 
| 532 | 184 |  |  |  |  | 3791 | my $coredump = WCOREDUMP($child_error); | 
| 533 |  |  |  |  |  |  |  | 
| 534 |  |  |  |  |  |  | # There's a bug in perl 5.8.9 and 5.10.0 where if the system | 
| 535 |  |  |  |  |  |  | # does not provide a native WCOREDUMP, then $? will | 
| 536 |  |  |  |  |  |  | # never contain coredump information.  This code | 
| 537 |  |  |  |  |  |  | # checks to see if we have the bug, and works around | 
| 538 |  |  |  |  |  |  | # it if needed. | 
| 539 |  |  |  |  |  |  |  | 
| 540 | 184 | 50 | 33 |  |  | 4305 | if ($] >= 5.008009 and not $NATIVE_WCOREDUMP) { | 
| 541 | 184 |  | 66 |  |  | 2279 | $coredump ||= WCOREDUMP( ${^CHILD_ERROR_NATIVE} ); | 
| 542 |  |  |  |  |  |  | } | 
| 543 |  |  |  |  |  |  |  | 
| 544 | 184 | 100 |  |  |  | 2570 | if ($child_error == -1) { | 
|  |  | 100 |  |  |  |  |  | 
|  |  | 50 |  |  |  |  |  | 
| 545 | 8 |  |  |  |  | 4282 | croak sprintf(FAIL_START, $command, $!); | 
| 546 |  |  |  |  |  |  |  | 
| 547 |  |  |  |  |  |  | } elsif ( WIFEXITED( $child_error ) ) { | 
| 548 | 175 |  |  |  |  | 893 | $EXITVAL = WEXITSTATUS( $child_error ); | 
| 549 |  |  |  |  |  |  |  | 
| 550 | 175 |  |  |  |  | 1715 | return _check_exit($command,$EXITVAL,$valid_returns); | 
| 551 |  |  |  |  |  |  |  | 
| 552 |  |  |  |  |  |  | } elsif ( WIFSIGNALED( $child_error ) ) { | 
| 553 | 1 |  |  |  |  | 23 | my $signal_no   = WTERMSIG( $child_error ); | 
| 554 | 1 |  | 50 |  |  | 21 | my $signal_name = $Signal_from_number[$signal_no] || "UNKNOWN"; | 
| 555 |  |  |  |  |  |  |  | 
| 556 | 1 | 50 |  |  |  | 547 | croak sprintf FAIL_SIGNAL, $command, $signal_name, $signal_no, ($coredump ? " and dumped core" : ""); | 
| 557 |  |  |  |  |  |  |  | 
| 558 |  |  |  |  |  |  |  | 
| 559 |  |  |  |  |  |  | } | 
| 560 |  |  |  |  |  |  |  | 
| 561 | 0 |  |  |  |  | 0 | croak sprintf(FAIL_INTERNAL, qq{'$command' ran without exit value or signal}); | 
| 562 |  |  |  |  |  |  |  | 
| 563 |  |  |  |  |  |  | } | 
| 564 |  |  |  |  |  |  |  | 
| 565 |  |  |  |  |  |  | # A simple subroutine for checking exit values.  Results in better | 
| 566 |  |  |  |  |  |  | # assurance of consistent error messages, and better forward support | 
| 567 |  |  |  |  |  |  | # for new features in I::S::S. | 
| 568 |  |  |  |  |  |  |  | 
| 569 |  |  |  |  |  |  | sub _check_exit { | 
| 570 | 177 |  |  | 177 |  | 854 | my ($command, $exitval, $valid_returns) = @_; | 
| 571 |  |  |  |  |  |  |  | 
| 572 |  |  |  |  |  |  | # If we have a single-value list consisting of the EXIT_ANY | 
| 573 |  |  |  |  |  |  | # value, then we're happy with whatever exit value we're given. | 
| 574 | 177 | 100 | 100 |  |  | 2497 | if (@$valid_returns == 1 and $valid_returns->[0] == EXIT_ANY_CONST) { | 
| 575 | 2 |  |  |  |  | 54 | return $exitval; | 
| 576 |  |  |  |  |  |  | } | 
| 577 |  |  |  |  |  |  |  | 
| 578 | 175 | 100 |  | 181 |  | 6626 | if (not defined first { $_ == $exitval } @$valid_returns) { | 
|  | 181 |  |  |  |  | 1865 |  | 
| 579 | 45 |  |  |  |  | 19538 | croak sprintf FAIL_BADEXIT, $command, $exitval; | 
| 580 |  |  |  |  |  |  | } | 
| 581 | 130 |  |  |  |  | 4230 | return $exitval; | 
| 582 |  |  |  |  |  |  | } | 
| 583 |  |  |  |  |  |  |  | 
| 584 |  |  |  |  |  |  |  | 
| 585 |  |  |  |  |  |  | # This subroutine simply determines a list of valid returns, the command | 
| 586 |  |  |  |  |  |  | # name, and any arguments that we need to pass to it. | 
| 587 |  |  |  |  |  |  |  | 
| 588 |  |  |  |  |  |  | sub _process_args { | 
| 589 | 313 |  |  | 313 |  | 1020 | my $valid_returns = [ 0 ]; | 
| 590 | 313 |  |  |  |  | 4126 | my $caller = (caller(1))[3]; | 
| 591 |  |  |  |  |  |  |  | 
| 592 | 313 | 100 |  |  |  | 1461 | if (not @_) { | 
| 593 | 5 |  |  |  |  | 482 | croak "$caller called with no arguments"; | 
| 594 |  |  |  |  |  |  | } | 
| 595 |  |  |  |  |  |  |  | 
| 596 | 308 | 100 |  |  |  | 1137 | if (ref $_[0] eq "ARRAY") { | 
| 597 | 116 |  |  |  |  | 306 | $valid_returns = shift(@_); | 
| 598 |  |  |  |  |  |  | } | 
| 599 |  |  |  |  |  |  |  | 
| 600 | 308 | 100 |  |  |  | 1670 | if (not @_) { | 
| 601 | 5 |  |  |  |  | 530 | croak "$caller called with no command"; | 
| 602 |  |  |  |  |  |  | } | 
| 603 |  |  |  |  |  |  |  | 
| 604 | 303 |  |  |  |  | 869 | my $command = shift(@_); | 
| 605 |  |  |  |  |  |  |  | 
| 606 | 303 | 50 |  |  |  | 1080 | if (not defined $command) { | 
| 607 | 0 |  |  |  |  | 0 | croak sprintf( FAIL_UNDEF, $caller ); | 
| 608 |  |  |  |  |  |  | } | 
| 609 |  |  |  |  |  |  |  | 
| 610 | 303 |  |  |  |  | 1749 | return ($valid_returns,$command,@_); | 
| 611 |  |  |  |  |  |  |  | 
| 612 |  |  |  |  |  |  | } | 
| 613 |  |  |  |  |  |  |  | 
| 614 |  |  |  |  |  |  | 1; | 
| 615 |  |  |  |  |  |  |  | 
| 616 |  |  |  |  |  |  | __END__ |