From 2d522aed78edeaa25f8640698812d651ca0dd411 Mon Sep 17 00:00:00 2001 From: Peter Palfrader Date: Sat, 6 Jul 2002 21:35:04 +0000 Subject: Find config file automagically --- Echolot/Config.pm | 46 ++++++++++++++++++++++++++++++++++++++++++++-- pingd | 29 +++++++++++++++++++++-------- 2 files changed, 65 insertions(+), 10 deletions(-) diff --git a/Echolot/Config.pm b/Echolot/Config.pm index f764ffe..8c62451 100644 --- a/Echolot/Config.pm +++ b/Echolot/Config.pm @@ -1,7 +1,7 @@ package Echolot::Config; # (c) 2002 Peter Palfrader -# $Id: Config.pm,v 1.14 2002/07/06 20:15:12 weasel Exp $ +# $Id: Config.pm,v 1.15 2002/07/06 21:35:04 weasel Exp $ # =pod @@ -12,6 +12,29 @@ Echolot::Config - echolot configuration =head1 DESCRIPTION +Sets default configuration options and +reads configuration from the config file. + +=head1 FILES + +The configuration file is searched in those places in that order: + +=over + +=item the file pointed to by the B environment variable + +=item `pwd`/pingd.conf + +=item $HOME/echolot/pingd.conf + +=item $HOME/pingd.conf + +=item $HOME/.pingd.conf + +=item /etc/pingd.conf + +=back + =cut use strict; @@ -22,6 +45,14 @@ use Carp; my $CONFIG; +my @CONFIG_FILES = + ( $ENV{'ECHOLOT_CONF'}, + 'pingd.conf', + $ENV{'HOME'}.'/echolot/pingd.conf', + $ENV{'HOME'}.'/pingd.conf', + $ENV{'HOME'}.'/.pingd.conf', + '/etc/pingd.conf' ); + sub init($) { my ($params) = @_; @@ -92,9 +123,20 @@ sub init($) { verbose => 0 }; + + my $configfile = undef; + for my $filename ( @CONFIG_FILES ) { + if ( defined $filename && -e $filename ) { + $configfile = $filename; + last; + }; + }; + + die ("no Configuration file found\n") unless defined $configfile; + { my $parser = new XML::Parser(Style => 'Tree'); - my $tree = $parser->parsefile('pingd.conf'); + my $tree = $parser->parsefile($configfile); my $dump = new XML::Dumper; $CONFIG = $dump->xml2pl($tree); } diff --git a/pingd b/pingd index dac0562..efc5c04 100755 --- a/pingd +++ b/pingd @@ -1,7 +1,7 @@ #!/usr/bin/perl -wT # (c) 2002 Peter Palfrader -# $Id: pingd,v 1.18 2002/07/06 01:31:39 weasel Exp $ +# $Id: pingd,v 1.19 2002/07/06 21:35:04 weasel Exp $ # =pod @@ -160,7 +160,23 @@ Tell B to detach. =head1 FILES -F +The configuration file is searched in those places in that order: + +=over + +=item the file pointed to by the B environment variable + +=item `pwd`/pingd.conf + +=item $HOME/echolot/pingd.conf + +=item $HOME/pingd.conf + +=item $HOME/.pingd.conf + +=item /etc/pingd.conf + +=back =head1 SIGNALS @@ -178,10 +194,6 @@ This can be used if you want to rotate that file. Peter Palfrader Epeter@palfrader.orgE -=head1 SEE ALSO - -echolot Documentation - =head1 BUGS Please report them at EURL:http://savannah.gnu.org/bugs/?group=echolotE @@ -214,7 +226,7 @@ my $redirected_stdio = 0; sub setSigHandlers() { $SIG{'HUP'} = sub { - print "Got SIGINT. scheduling readcommands\n"; + print "Got SIGHUP. scheduling readcommands\n"; Echolot::Globals::get()->{'scheduler'}->schedule('readcommands', time() ); if ($redirected_stdio) { close STDOUT; @@ -436,7 +448,8 @@ if (!GetOptions ( die ("$PROGRAM_NAME: Usage: $PROGRAM_NAME [-fwhv]\n"); }; if ($params->{'help'}) { - print ("Usage: $PROGRAM_NAME [options]\n"); #FIXME + print ("Usage: $PROGRAM_NAME [options] command\n"); + print ("See man pingd or perldoc pingd for more info.\n"); exit 0; }; -- cgit v1.2.3