Don't use Getopt::Long in safe_process.pl

parent d930e9bb
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
use strict; use strict;
use warnings; use warnings;
use Time::localtime;
use lib 'lib'; use lib 'lib';
use My::SafeProcess::Base; use My::SafeProcess::Base;
use POSIX qw(WNOHANG); use POSIX qw(WNOHANG);
...@@ -19,6 +18,7 @@ use POSIX qw(WNOHANG); ...@@ -19,6 +18,7 @@ use POSIX qw(WNOHANG);
my $verbose= 0; my $verbose= 0;
sub message { sub message {
if ($verbose > 0){ if ($verbose > 0){
use Time::localtime;
my $tm= localtime(); my $tm= localtime();
my $timestamp= sprintf("%02d%02d%02d %2d:%02d:%02d", my $timestamp= sprintf("%02d%02d%02d %2d:%02d:%02d",
$tm->year % 100, $tm->mon+1, $tm->mday, $tm->year % 100, $tm->mon+1, $tm->mday,
...@@ -43,16 +43,26 @@ $SIG{INT}= sub { message("!Got signal @_"); $terminated= 1; }; ...@@ -43,16 +43,26 @@ $SIG{INT}= sub { message("!Got signal @_"); $terminated= 1; };
my $parent_pid= getppid(); my $parent_pid= getppid();
use Getopt::Long; my $found_double_dash= 0;
GetOptions( while (my $arg= shift(@ARGV)){
'verbose' => \$verbose,
) or die "GetOptions failed"; if ($arg =~ /^--$/){
shift(@ARGV) if defined($ARGV[0]) and $ARGV[0] eq "--"; $found_double_dash= 1;
last;
}
elsif ($arg =~ /^--verbose$/){
$verbose= 1;
}
else {
die "Unknown option: $arg";
}
}
my $path= shift(@ARGV); # Executable my $path= shift(@ARGV); # Executable
die "usage:\n" . die "usage:\n" .
" safe_process.pl [opts] -- <path> [<args> [...<args_n>]]" " safe_process.pl [opts] -- <path> [<args> [...<args_n>]]"
unless defined $path; unless defined $path || $found_double_dash;
message("started"); message("started");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment