From: Jacob Bachmeyer Date: Sun, 30 Apr 2023 04:29:39 +0000 (-0500) Subject: Replace magic numbers in flock calls with symbolic constants X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=14fcafe431f4aaaf78b48f5a8c772f005eb58009;p=gatekeeper.git Replace magic numbers in flock calls with symbolic constants This also fixes a long-standing bug where the serials file was never actually unlocked until it was closed, at which time the kernel will implicitly release the lock. The cause of the bug, simply, was the use of the wrong number in place of LOCK_UN. Using the constant fixes this. --- diff --git a/gatekeeper.pl b/gatekeeper.pl index f69470d..d918953 100755 --- a/gatekeeper.pl +++ b/gatekeeper.pl @@ -2450,10 +2450,10 @@ sub advance_timestamp_ratchet { if (!-e $serials_path) { open(SERIALS,">$serials_path"); - flock(SERIALS,2); # Take exclusive lock + flock(SERIALS,LOCK_EX); # Take exclusive lock } else { open(SERIALS,"+<$serials_path"); - flock(SERIALS,2); # Take exclusive lock + flock(SERIALS,LOCK_EX); # Take exclusive lock local *_; while () { s/\s+//g; @@ -2469,7 +2469,7 @@ sub advance_timestamp_ratchet { # Verify that this is really a new version of the file! if (exists($serials{$full_filename}) && ($serials{$full_filename} >= $new_epoch)) { - flock(SERIALS,4); # Release lock + flock(SERIALS,LOCK_UN); # Release lock throw signature_replay => previous_timestamp => $old_epoch, new_timestamp => $new_epoch } @@ -2480,7 +2480,7 @@ sub advance_timestamp_ratchet { print SERIALS "$key:$serials{$key}\n"; } - flock(SERIALS,4); # Release lock + flock(SERIALS,LOCK_UN); # Release lock close(SERIALS); flock $serials_flag, LOCK_UN or die "unlock serials flag: $!"; close $serials_flag or die "close serials flag: $!";