From 5f0dcac4e9fd26bee8134f971bb1605c83e71745 Mon Sep 17 00:00:00 2001 From: Stephen L Johnson Date: Tue, 14 Mar 2000 22:24:33 +0000 Subject: [PATCH] converted parm handling to use Getopt::long --- src/spong-network.pl | 47 +++++++++++++++++++++++++++++++++++++++----- 1 file changed, 42 insertions(+), 5 deletions(-) diff --git a/src/spong-network.pl b/src/spong-network.pl index a779901..ad46e81 100755 --- a/src/spong-network.pl +++ b/src/spong-network.pl @@ -26,17 +26,29 @@ use Sys::Hostname; use Net::Ping; use Socket; use POSIX; +use Getopt::Long; use Spong::Daemon; use Spong::Status qw(status); srand( time() ^ ($$ + ($$ << 15 )) ); -if( $ARGV[0] eq "--debug" ) { $debug = 1; shift; } -if( $ARGV[0] eq "--restart" ) { $restart = 1; shift; } -if( $ARGV[0] eq "--kill" ) { $kill = 1; shift; } -if( $ARGV[0] eq "--nosleep" ) { $nosleep = 1; shift; } -if( $ARGV[0] eq "--refresh" ) { $nosleep = 1; shift; } +$debug = $restart = $kill = 0; + +Getopt::Long::Configure('pass_through'); +if ( ! GetOptions("debug:i" => \$debuglevel, "restart" => \$restart, + "kill" => \$kill, "nosleep|refresh" => \$nosleep ) ) { + &usage(); + exit 1; +} + +$debug = $debuglevel; + +#if( $ARGV[0] eq "--debug" ) { $debug = 1; shift; } +#if( $ARGV[0] eq "--restart" ) { $restart = 1; shift; } +#if( $ARGV[0] eq "--kill" ) { $kill = 1; shift; } +#if( $ARGV[0] eq "--nosleep" ) { $nosleep = 1; shift; } +#if( $ARGV[0] eq "--refresh" ) { $nosleep = 1; shift; } $me = "@@BINDIR@@/spong-network"; $conf_file = $ARGV[0] || "@@ETCDIR@@/spong.conf"; @@ -216,6 +228,31 @@ _EOM_ # Utility functions, and signal handlers... # =========================================================================== +# Print out the usage for the program + +sub usage { + + print qq +(Usage: + $0 [--debug n] [--nosleep|--refresh] [config_file] + $0 --kill | --restart + + --debug n + Run in the foreround and print debugging output + --nosleep + --refresh + Run one cycle of checks in the foreground and exit + --restart + Signal a running spong-network to restart. + --kill + Signal a running spong-network to terminate. + config_file + Use the named file as the configuration file +); + +} + + # Load our configuration variables, including anything specific to the host # that we are running on. -- 2.30.2