From d255e2d1c291915ca20e0f57f9d55bc0d7d8dd87 Mon Sep 17 00:00:00 2001 From: Leo-Andres Hofmann Date: Thu, 2 Dec 2021 16:39:52 +0100 Subject: [PATCH] pakfire.cgi: Extend the lockfile test This implements a function to determine if Pakfire is already running. It tests the PID and lockfile and can be expanded easily later. 'pidof' checks the full path to avoid confusion. Removes the unreachable function "refreshpage". Signed-off-by: Leo-Andres Hofmann --- html/cgi-bin/pakfire.cgi | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/html/cgi-bin/pakfire.cgi b/html/cgi-bin/pakfire.cgi index 4d6eee284c..7957bc1540 100644 --- a/html/cgi-bin/pakfire.cgi +++ b/html/cgi-bin/pakfire.cgi @@ -44,8 +44,6 @@ $cgiparams{'VALID'} = ''; $cgiparams{'INSPAKS'} = ''; $cgiparams{'DELPAKS'} = ''; -sub refreshpage{&Header::openbox( 'Waiting', 1, "" );print "

$Lang::tr{'pagerefresh'}
";&Header::closebox();} - &Header::getcgihash(\%cgiparams); &General::readhash("${General::swroot}/main/settings", \%mainsettings); @@ -54,7 +52,7 @@ sub refreshpage{&Header::openbox( 'Waiting', 1, "" ); print < @@ -203,7 +197,6 @@ END &Header::closebigbox(); &Header::closepage(); exit; - refreshpage(); } my $core_release = `cat /opt/pakfire/db/core/mine 2>/dev/null`; @@ -314,3 +307,16 @@ END &Header::closebox(); &Header::closebigbox(); &Header::closepage(); + +###--- Internal functions ---### + +# Check if pakfire is already running (extend test here if necessary) +sub _is_pakfire_busy { + # Get PID of a running pakfire instance + # (The system backpipe command is safe, because no user input is computed.) + my $pakfire_pid = `pidof -s /usr/local/bin/pakfire`; + chomp($pakfire_pid); + + # Test presence of PID or lockfile + return (($pakfire_pid) || (-e "$Pakfire::lockfile")); +} -- 2.39.2