fix barf on encountering an empty lockfile
[spider.git] / perl / cluster.pl
index a33e6da5f1a8e76b2907cf8547791702a146cdd9..5c3f0fb90a19c83fd59a4ffe5da2838fd90a9697 100755 (executable)
@@ -34,11 +34,14 @@ BEGIN {
        # try to create and lock a lockfile (this isn't atomic but
        # should do for now
        $lockfn = "$root/local/cluster.lck";       # lock file name
-       if (-e $lockfn) {
+       if (-w $lockfn) {
                open(CLLOCK, "$lockfn") or die "Can't open Lockfile ($lockfn) $!";
                my $pid = <CLLOCK>;
-               chomp $pid;
-               die "Lockfile ($lockfn) and process $pid exist, another cluster running?" if kill 0, $pid;
+               if ($pid) {
+                       chomp $pid;
+                       die "Lockfile ($lockfn) and process $pid exist, another cluster running?" if kill 0, $pid;
+               }
+               unlink $lockfn;
                close CLLOCK;
        }
        open(CLLOCK, ">$lockfn") or die "Can't open Lockfile ($lockfn) $!";