Reverted to r39, mostly because I'm a idiot.
We can't read the config file before figuring out what to do on the command line.
This commit is contained in:
parent
2af137790b
commit
71bf645791
1 changed files with 28 additions and 30 deletions
|
@ -23,9 +23,9 @@ my @weekDays = qw(Sun Mon Tue Wed Thu Fri Sat Sun);
|
||||||
my $NO = 0;
|
my $NO = 0;
|
||||||
my $YES = 1;
|
my $YES = 1;
|
||||||
my @device_cfg;
|
my @device_cfg;
|
||||||
my $conf_file = $CONFIG_FILE;
|
my $conf_file = "";
|
||||||
my $make_daemon = $NO;
|
my $make_daemon = $NO;
|
||||||
my $output_to_logfile = $NO;
|
my $output_to_logfile = $YES;
|
||||||
my $write_pid = $YES;
|
my $write_pid = $YES;
|
||||||
my $n_rfcmd_calls;
|
my $n_rfcmd_calls;
|
||||||
my $current_time;
|
my $current_time;
|
||||||
|
@ -511,7 +511,6 @@ sub read_config
|
||||||
}
|
}
|
||||||
if ($param eq 'log_file') {
|
if ($param eq 'log_file') {
|
||||||
$LOG_FILE = $value;
|
$LOG_FILE = $value;
|
||||||
$output_to_logfile = $YES;
|
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
if ($param eq 'pid_file') {
|
if ($param eq 'pid_file') {
|
||||||
|
@ -544,30 +543,15 @@ sub usageprompt
|
||||||
|
|
||||||
|
|
||||||
# ############## Main section ######################
|
# ############## Main section ######################
|
||||||
my $i;
|
my $i = -1;
|
||||||
|
|
||||||
# Check if the command line specifies a config file
|
|
||||||
foreach $i (0 .. $#ARGV) {
|
|
||||||
if ($ARGV[$i] =~ /^--config$/ || $ARGV[$i] =~ /^-c$/) {
|
|
||||||
$conf_file = $ARGV[$i+1];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
# Read the configuration file
|
|
||||||
$number_of_devices = read_config($conf_file);
|
|
||||||
|
|
||||||
if ($number_of_devices < 1) {
|
|
||||||
die("$PROGRAM_NAME: Configuration file has no devices to control, exiting.\n");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
printf("$PROGRAM_NAME: Configurations for $number_of_devices device(s) read.\n\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
$i = -1;
|
|
||||||
|
|
||||||
while ($i < $#ARGV) {
|
while ($i < $#ARGV) {
|
||||||
if ($i+1 <= $#ARGV) {
|
if ($i+1 <= $#ARGV) {
|
||||||
if ($ARGV[$i+1] =~ /^-d$/ || $ARGV[$i+1] =~ /^--daemon$/) {
|
if ($ARGV[$i+1] =~ /^--config$/ || $ARGV[$i+1] =~ /^-c$/) {
|
||||||
|
$i++;
|
||||||
|
$conf_file = $ARGV[$i+1];
|
||||||
|
}
|
||||||
|
elsif ($ARGV[$i+1] =~ /^-d$/ || $ARGV[$i+1] =~ /^--daemon$/) {
|
||||||
$output_to_logfile = $YES;
|
$output_to_logfile = $YES;
|
||||||
$make_daemon = $YES;
|
$make_daemon = $YES;
|
||||||
}
|
}
|
||||||
|
@ -602,16 +586,30 @@ if ($output_to_logfile == $YES) {
|
||||||
|
|
||||||
if ($make_daemon == $YES) {
|
if ($make_daemon == $YES) {
|
||||||
&daemonize();
|
&daemonize();
|
||||||
# Create pidfile
|
}
|
||||||
if ($write_pid == $YES) {
|
|
||||||
open PIDFILE, ">$pidFile" or die "$PROGRAM_NAME: Can't open $pidFile: $!\n";
|
# Create pidfile
|
||||||
print PIDFILE $$ . "\n";
|
if ($write_pid == $YES) {
|
||||||
close PIDFILE;
|
open PIDFILE, ">$pidFile" or die "$PROGRAM_NAME: Can't open $pidFile: $!\n";
|
||||||
}
|
print PIDFILE $$ . "\n";
|
||||||
|
close PIDFILE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (length($conf_file) < 1) {
|
||||||
|
$conf_file = $CONFIG_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("$PROGRAM_NAME: Starting $PROGRAM_NAME version $VERSION\n");
|
printf("$PROGRAM_NAME: Starting $PROGRAM_NAME version $VERSION\n");
|
||||||
|
|
||||||
|
# Read the configuration file
|
||||||
|
$number_of_devices = read_config($conf_file);
|
||||||
|
|
||||||
|
if ($number_of_devices < 1) {
|
||||||
|
die("$PROGRAM_NAME: Configuration file has no devices to control, exiting.\n");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
printf("$PROGRAM_NAME: Configurations for $number_of_devices device(s) read.\n\n");
|
||||||
|
}
|
||||||
|
|
||||||
###################################################################################################
|
###################################################################################################
|
||||||
# Now to the eternal loop
|
# Now to the eternal loop
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue