From 7f7f546e4ae25d75738d6c326149476d7def615a Mon Sep 17 00:00:00 2001 From: Stefan Schantl Date: Mon, 18 Oct 2021 21:09:58 +0200 Subject: [PATCH] pakfire.cgi: Implement logic to lock the page until pakfire has been fully launched. When performing any action which requires pakfire, the page gets locked with an message informing the user that pakfire is working. The page will be reloaded when pakfire has been launched and is doing the requested operation - showing the well known log output. This also happens when pakfire has been launched via any kind of terminal or SSH session and the CGI gets accessed. Internally before pakfire gets started a variable called page_lock will be set to lock the page. An while loop will keep the page locked until pakfire is launched fully and has written it's lock_file. This approach will prevent us from any kind of required time intervall or race conditions. Signed-off-by: Stefan Schantl Signed-off-by: Arne Fitzenreiter --- html/cgi-bin/pakfire.cgi | 49 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/html/cgi-bin/pakfire.cgi b/html/cgi-bin/pakfire.cgi index 0cf522ba13..f2381f0312 100644 --- a/html/cgi-bin/pakfire.cgi +++ b/html/cgi-bin/pakfire.cgi @@ -44,6 +44,8 @@ $cgiparams{'VALID'} = ''; $cgiparams{'INSPAKS'} = ''; $cgiparams{'DELPAKS'} = ''; +my $page_lock; + sub refreshpage{&Header::openbox( 'Waiting', 1, "" );print "

$Lang::tr{'pagerefresh'}
";&Header::closebox();} &Header::getcgihash(\%cgiparams); @@ -57,8 +59,9 @@ sub refreshpage{&Header::openbox( 'Waiting', 1, " + + + $Lang::tr{ + + + + $Lang::tr{'pakfire working'} + + + +END + &Header::closebox(); + + # Infinite loop to lock the page until pakfire lockfile is present. + while($page_lock) { + unless (-e $Pakfire::lockfile) { + sleep(1); + } else { + # Release page lock. + undef($page_lock); + + # Break loop. + last; + } + } + + # Perform page reload. + print "\n"; + exit; +} + +# Check if pakfire is already running. In this case a lockfile is present. if (-e $Pakfire::lockfile) { &Header::openbox( 'Waiting', 1, "" ); print <