summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2011-05-30 19:19:16 +0000
committerPaul Buetow <paul@buetow.org>2011-05-30 19:19:16 +0000
commit5f5d8b12cec3d4c63a34a7f0fb0b0202a4c26244 (patch)
tree29ae3cc634b5b0857a302227d80721d70f2c5a2d /lib
parentccf10a048ad0ee7a2cd79d39d159698186f79351 (diff)
Passing of startup options work
Diffstat (limited to 'lib')
-rw-r--r--lib/PerlDaemon/PerlDaemon.pl24
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;