From 75e6292d2dc1848c6b79d24891bfe02b47e7e5a0 Mon Sep 17 00:00:00 2001 From: Marcel de Rooy Date: Mon, 10 Feb 2014 14:55:05 +0100 Subject: [PATCH] Bug 11078: Follow-up for flock eval Content-Type: text/plain; charset=utf-8 This patch adds a subroutine where the flock is once tested in an eval. Just to be sure that flock has been implemented and prevent a fatal error. Signed-off-by: Marcel de Rooy --- misc/migration_tools/rebuild_zebra.pl | 29 +++++++++++++++++++++++++---- 1 files changed, 25 insertions(+), 4 deletions(-) diff --git a/misc/migration_tools/rebuild_zebra.pl b/misc/migration_tools/rebuild_zebra.pl index 28b858c..2f29301 100755 --- a/misc/migration_tools/rebuild_zebra.pl +++ b/misc/migration_tools/rebuild_zebra.pl @@ -43,6 +43,7 @@ my $where; my $offset; my $run_as_root; my $run_user = (getpwuid($<))[0]; +my $use_flock; my $verbose_logging = 0; my $zebraidx_log_opt = " -v none,fatal,warn "; @@ -185,17 +186,17 @@ open my $LockFH, q{>}, $lockfile or die "$lockfile: $!"; if ($daemon_mode) { while (1) { # For incremental updates, skip the update if the updates are locked - if (flock($LockFH, LOCK_EX|LOCK_NB)) { + if (_flock($LockFH, LOCK_EX|LOCK_NB)) { do_one_pass() if ( zebraqueue_not_empty() ); - flock($LockFH, LOCK_UN); + _flock($LockFH, LOCK_UN); } sleep $daemon_sleep; } } else { # all one-off invocations, wait for the lock to free - flock($LockFH, LOCK_EX); + _flock($LockFH, LOCK_EX); do_one_pass(); - flock($LockFH, LOCK_UN); + _flock($LockFH, LOCK_UN); } @@ -749,6 +750,26 @@ sub do_indexing { } +sub _flock { +# test if flock is present; if so, use it; if not, return true +# op refers to the official flock operations incl LOCK_EX, LOCK_UN, etc. +# combining LOCK_EX with LOCK_NB returns immediately + my ($fh, $op)= @_; + if( !defined($use_flock) ) { + #check if flock is present; if not, you will have a fatal error + my $i=eval('flock($fh, $op)'); + #assuming that $fh and $op are fine(..), an undef i means no flock + $use_flock= defined($i)? 1: 0; + print "Warning: flock could not be used!\n" if $verbose_logging && !$use_flock; + return 1 if !$use_flock; + return $i; + } + else { + return 1 if !$use_flock; + return flock($fh, $op); + } +} + sub print_usage { print <<_USAGE_; $0: reindex MARC bibs and/or authorities in Zebra. -- 1.7.7.6