@@ -, +, @@ --- misc/migration_tools/rebuild_zebra.pl | 29 +++++++++++++++++++++++++---- 1 files changed, 25 insertions(+), 4 deletions(-) --- a/misc/migration_tools/rebuild_zebra.pl +++ a/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. --