make getpeername() return the original socket address which before it was intercepted
[hband-tools.git] / user-tools / reportcmdstatus
blobb6d60c0c6dee60fe24764fb11385b1f61da555f0
1 #!/usr/bin/env perl
3 use POSIX;
4 use Getopt::Long qw/:config no_ignore_case permute/;
5 use Pod::Usage;
7 $0 = "reportcmdstatus";
9 $clone_status = 0;
11 GetOptions(
12 'c|clone!' => \$clone_status,
13 'help|?' => sub{ pod2usage(-exitval=>0, -verbose=>99); },
14 '<>' => sub{ unshift @ARGV, @_; die '!FINISH'; },
15 ) or pod2usage(-exitval=>2, -verbose=>99);
17 system @ARGV;
18 $status = ${^CHILD_ERROR_NATIVE};
20 if(WIFSIGNALED($status))
22 printf STDERR "command terminated by signal %d.\n", WTERMSIG($status);
23 $mystatus = 128 + WTERMSIG($status);
25 else
27 printf STDERR "command exited with status %d.\n", WEXITSTATUS($status);
28 $mystatus = WEXITSTATUS($status);
31 exit $mystatus if $clone_status;
32 exit 0;
35 __END__
37 =pod
39 =head1 NAME
41 reportcmdstatus - Textually show how the given command finished (exit status/signal)
43 =head1 SYNOPSIS
45 reportcmdstatus [-c] [--] <COMMAND> [<ARGS>]
47 =head1 OPTIONS
49 =over 4
51 =item -c, --clone
53 Take COMMAND's status and itself exits with it.
54 Default is to exit 0.
56 =back
58 =cut