Skip to content

Commit

Permalink
Improve loading of configuration file
Browse files Browse the repository at this point in the history
If the configuration file was placed in the same directory as the script, the script would fail if launched from any other directory because the configuration file name was defined without a path.

This patch improves the script so that it will load the configuration file from either the same directory as the script, or from /etc.

I also moved the initialization of $pid and $cid to the top of the script because the fact that they were uninitialized was preventing the script from reporting the configuration file error properly.
  • Loading branch information
tievolu authored Sep 15, 2022
1 parent 475645b commit 5bbb134
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions sqm-autorate.pl
Original file line number Diff line number Diff line change
Expand Up @@ -208,12 +208,20 @@
my %reflector_offsets :shared; # Time offset for each ICMP reflector
my %reflector_minimum_rtts :shared; # Minimum RTT time seen for each ICMP reflector (used when calculating the offset)

# Initialise the process ID and cycle ID
$pid = "$$";
$cid = sprintf("%010d", 0);

#######################################################################################
# Configuration
#######################################################################################

# Read the configuration properties file and use them to populate global variables
my $config_file = "sqm-autorate.conf";
# Configuration file can be located in the same directory as the script, or /etc
my $config_file = substr($0, 0, rindex($0, "/")) . "/sqm-autorate.conf";
if (! -e $config_file) {
$config_file = "/etc/sqm-autorate.conf";
}
my %config_properties = &get_config_properties($config_file);

# Upload interfaces
Expand Down Expand Up @@ -386,14 +394,6 @@
STDOUT->autoflush(1);
STDERR->autoflush(1);

# Initialise the process ID and cycle ID
{
lock($pid);
lock($cid);
$pid = "$$";
$cid = sprintf("%010d", 0);
}

# Process command line arguments
&process_args();

Expand Down

0 comments on commit 5bbb134

Please sign in to comment.