Commit 65b799d9 authored by Alexander Gall's avatar Alexander Gall

Improve detection of changed shmem segments

Always check for a change of the shmem segment at startup
and don't die when the shmem directory doesn't exist.
parent c791471a
...@@ -130,7 +130,7 @@ my %class_map = ( INTEGER => 'Snabb::SNMP::Tie::INTEGER', ...@@ -130,7 +130,7 @@ my %class_map = ( INTEGER => 'Snabb::SNMP::Tie::INTEGER',
); );
my $rebuild_mib = 1; my $rebuild_mib = 0;
### Mappings of types provided by SNMP::getType() to those ### Mappings of types provided by SNMP::getType() to those
### used by NetSNMP::ASN ### used by NetSNMP::ASN
...@@ -147,7 +147,7 @@ my %type_tr = ...@@ -147,7 +147,7 @@ my %type_tr =
); );
## ##
my $snabb_shmem_dir_ctime; my $snabb_shmem_dir_ctime = 0;
my %shmem; my %shmem;
our %compound_scalar_handlers = our %compound_scalar_handlers =
( accumulator => sub { ( accumulator => sub {
...@@ -505,13 +505,12 @@ sub agentx_handler { ...@@ -505,13 +505,12 @@ sub agentx_handler {
sub idx_watcher() { sub idx_watcher() {
unless ($rebuild_mib) { unless ($rebuild_mib) {
opendir(SHMEMD, $config{shmem_dir}) or die if (opendir(SHMEMD, $config{shmem_dir})) {
"open of directory $config{shmem_dir} failed: $!";
my $ctime = (stat(SHMEMD))[9] or die my $ctime = (stat(SHMEMD))[9] or die
"stat of directory $config{shmem_dir} failed: $!"; "stat of directory $config{shmem_dir} failed: $!";
close(SHMEMD); close(SHMEMD);
if ($ctime != $snabb_shmem_dir_ctime) { if ($ctime != $snabb_shmem_dir_ctime) {
print("idx_watcher: data directory change detected.\n"); print("idx_watcher: data directory $config{shmem_dir} change detected\n");
$rebuild_mib = 1; $rebuild_mib = 1;
} else { } else {
for my $segment (keys(%shmem)) { for my $segment (keys(%shmem)) {
...@@ -528,6 +527,9 @@ sub idx_watcher() { ...@@ -528,6 +527,9 @@ sub idx_watcher() {
} }
} }
} }
} else {
warn "open of directory $config{shmem_dir} failed: $!";
}
} }
alarm $config{check_interval}; alarm $config{check_interval};
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment