Skip to content

Commit

Permalink
Unlock file while waiting for the DB
Browse files Browse the repository at this point in the history
Otherwise the server might block forever waiting for our lock
to be released
  • Loading branch information
alandekok committed Mar 31, 2015
1 parent 2c55705 commit 3f028f8
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions scripts/sql/radsqlrelay
Expand Up @@ -69,6 +69,18 @@ sub setlock($;$$)
else { return 0 }
}

sub unlock($;$$)
{
my ($fh, $start, $len) = @_;
$start = 0 unless defined $start;
$len = 0 unless defined $len;

#type whence start till pid
my $packed = pack($FLOCK_STRUCT, F_WRLCK, SEEK_SET, $start, $len, 0);
if (fcntl($fh, F_UNLCK, $packed)) { return 1 }
else { return 0 }
}

sub usage()
{
print STDERR <<HERE;
Expand Down Expand Up @@ -127,7 +139,9 @@ sub process_file($$)
} else {
print "error: Lost connection to database\n";
$dbinfo->{handle}->disconnect;
unlock(\*FILE);
connect_wait($dbinfo);
setlock(\*FILE);
}
}
}
Expand Down

0 comments on commit 3f028f8

Please sign in to comment.