From 14fcafe431f4aaaf78b48f5a8c772f005eb58009 Mon Sep 17 00:00:00 2001 From: Jacob Bachmeyer Date: Sat, 29 Apr 2023 23:29:39 -0500 Subject: [PATCH] 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. --- gatekeeper.pl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) 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: $!"; -- 2.25.1