Merge pull request #166 from jasonblewis/fixps

check for emtpy lockfile
This commit is contained in:
Jim Salter 2018-06-28 16:15:28 -04:00 committed by GitHub
commit d3355912a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 10 additions and 2 deletions

12
sanoid
View File

@ -1108,13 +1108,22 @@ sub checklock {
# no lockfile
return 1;
}
# make sure lockfile contains something
if ( -z $lockfile) {
# zero size lockfile, something is wrong
die "ERROR: something is wrong! $lockfile is empty\n";
}
# lockfile exists. read pid and mutex from it. see if it's our pid. if not, see if
# there's still a process running with that pid and with the same mutex.
open FH, "< $lockfile";
open FH, "< $lockfile" or die "ERROR: unable to open $lockfile";
my @lock = <FH>;
close FH;
# if we didn't get exactly 2 items from the lock file there is a problem
if (scalar(@lock) != 2) {
die "ERROR: $lockfile is invalid.\n"
}
my $lockmutex = pop(@lock);
my $lockpid = pop(@lock);
@ -1126,7 +1135,6 @@ sub checklock {
# we own the lockfile. no need to check any further.
return 2;
}
open PL, "$pscmd -p $lockpid -o args= |";
my @processlist = <PL>;
close PL;