diff options
Diffstat (limited to 'lib/PerlDaemon/PerlDaemon.pl')
| -rw-r--r-- | lib/PerlDaemon/PerlDaemon.pl | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/lib/PerlDaemon/PerlDaemon.pl b/lib/PerlDaemon/PerlDaemon.pl index 1bee431..58e9755 100644 --- a/lib/PerlDaemon/PerlDaemon.pl +++ b/lib/PerlDaemon/PerlDaemon.pl @@ -62,10 +62,11 @@ sub writepid ($) { } -sub readconf ($) { - my $conffile = shift; +sub readconf ($%) { + my ($confile, %opts) = @_; - open my $fh, $conffile or die "Can't read $conffile\n"; + open my $fh, $confile or + die "Can't read config file $confile (specify using config=filepath)\n"; my %conf; while (<$fh>) { @@ -88,6 +89,7 @@ sub readconf ($) { die "$msg $key\n" unless exists $conf{$key}; } + @conf{keys %opts} = values %opts; return \%conf; } @@ -153,7 +155,21 @@ sub daemonloop ($) { } } -my $conf = readconf shift; +sub getopts (@) { + my %opts; + + for my $opt (@_) { + next unless $opt =~ /=/; + my ($key, $val) = split '=', $opt, 2; + $opts{$key} = $val; + } + + return %opts; +} + +my %opts = getopts @ARGV; + +my $conf = readconf $opts{config}, %opts; $conf->{logger} = PerlDaemon::Logger->new($conf); prestartup $conf; |
