From dbf0b358b9362fdf634b47569b1777d7034b17a9 Mon Sep 17 00:00:00 2001 From: Jacek Ablewicz Date: Tue, 30 Dec 2014 10:30:30 +0100 Subject: [PATCH] Bug 13431 [QA Follow-up]: Shared FastMmap file causes issues 1) Removed 'use C4::Context;' because it can lead to introduction of circular reference in the near future 2) Put fastmmap initialization code into an eval {} block, to catch various kinds of errors which can still occur during it's init in some [less usual] Koha setups and/or more unusual circumstances 3) Do not include UID in the sharefile name (it will be constructed using namespace + database name + database host instead). Test plan addendum: s/and UID// Signed-off-by: Katrin Fischer Signed-off-by: Jonathan Druart Signed-off-by: Tomas Cohen Arazi --- Koha/Cache.pm | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/Koha/Cache.pm b/Koha/Cache.pm index 5611c5224b..f4765b28c6 100644 --- a/Koha/Cache.pm +++ b/Koha/Cache.pm @@ -40,7 +40,6 @@ use warnings; use Carp; use Module::Load::Conditional qw(can_load); use Koha::Cache::Object; -use C4::Context; use base qw(Class::Accessor); @@ -161,16 +160,28 @@ sub _initialize_memcached { sub _initialize_fastmmap { my ($self) = @_; - my $share_file = join( '-', - "/tmp/sharefile-koha", $self->{'namespace'}, - C4::Context->config('hostname'), C4::Context->config('database'), - "" . getpwuid($>) ); - - $self->{'fastmmap_cache'} = Cache::FastMmap->new( - 'share_file' => $share_file, - 'expire_time' => $self->{'timeout'}, - 'unlink_on_exit' => 0, - ); + my ($cache, $share_file); + + # Temporary workaround to catch fatal errors when: C4::Context module + # is not loaded beforehand, or Cache::FastMmap init fails for whatever + # other reason (e.g. due to permission issues - see Bug 13431) + eval { + $share_file = join( '-', + "/tmp/sharefile-koha", $self->{'namespace'}, + C4::Context->config('hostname'), C4::Context->config('database') ); + + $cache = Cache::FastMmap->new( + 'share_file' => $share_file, + 'expire_time' => $self->{'timeout'}, + 'unlink_on_exit' => 0, + ); + }; + if ( $@ ) { + warn "FastMmap cache initialization failed: $@"; + return; + } + return unless defined $cache; + $self->{'fastmmap_cache'} = $cache; return $self; } -- 2.39.5