Revision: 6466 http://ipcop.svn.sourceforge.net/ipcop/?rev=6466&view=rev Author: owes Date: 2012-03-10 22:12:22 +0000 (Sat, 10 Mar 2012) Log Message: ----------- lockfile during blacklist download and update to avoid reentrancy problems. Inform user about update in progress with box in urlfilter.cgi.
Modified Paths: -------------- ipcop/trunk/html/cgi-bin/urlfilter.cgi ipcop/trunk/src/scripts/blacklistupdate.pl Modified: ipcop/trunk/html/cgi-bin/urlfilter.cgi =================================================================== --- ipcop/trunk/html/cgi-bin/urlfilter.cgi 2012-03-10 10:17:18 UTC (rev 6465) +++ ipcop/trunk/html/cgi-bin/urlfilter.cgi 2012-03-10 22:12:22 UTC (rev 6466) @@ -1015,8 +1015,9 @@ $errormessage .= "$Lang::tr{'custom blacklist url required'}<br />"; } else { - $updatemessage = $Lang::tr{'blacklist upload information'}; + # lockfile will trigger display of box with update message `/usr/local/bin/blacklistupdate.pl --force < /dev/null > /dev/null &`; + sleep(1); } } @@ -1168,6 +1169,17 @@ print "</form>\n"; } +if (-e "${dbdir}/.lock") { + # Blacklist update in progress. Show box and exit. + &Header::openbox('100%', 'left', "$Lang::tr{'information messages'}:", 'warning'); + print "<class name='base'>$Lang::tr{'blacklist upload information'} </class>\n"; + &Header::closebox(); + &Header::closebigbox(); + &Header::closepage(); + + exit 0; +} + if ($updatemessage) { &Header::openbox('100%', 'left', "$Lang::tr{'urlfilter update results'}:", 'warning'); print "<class name='base'>$updatemessage\n"; Modified: ipcop/trunk/src/scripts/blacklistupdate.pl =================================================================== --- ipcop/trunk/src/scripts/blacklistupdate.pl 2012-03-10 10:17:18 UTC (rev 6465) +++ ipcop/trunk/src/scripts/blacklistupdate.pl 2012-03-10 22:12:22 UTC (rev 6466) @@ -24,6 +24,7 @@ use warnings; require '/usr/lib/ipcop/general-functions.pl'; +use Fcntl qw(:flock); # import LOCK_* constants # Debug level: # 0 - no print @@ -132,8 +133,17 @@ my $source_url = ''; my $source_name = ''; my @source_urllist = (); + my $seconds = time(); - # If enough space available, download and prepare in /tmp (uses tmpfs) to increase speed + unless (open(LOCKFILE, ">${dbdir}/.lock")) { + die "Could not open lockfile"; + } + unless (flock(LOCKFILE, LOCK_EX | LOCK_NB)) { + die "Could not lock lockfile"; + } + + # If enough space available, download and prepare in /tmp (uses tmpfs) + # to decrease time needed for update $target = '/tmp/blacklistu' if (&General::getavailabledisk('/tmp') > 128); my $tempdb = "$target/blacklists"; @@ -240,11 +250,9 @@ system("/usr/local/bin/restartsquid"); print "Update from $blacklist_src completed\n" if ($debugLevel > 0); - - system("logger -t installpackage[urlfilter] \"URL filter blacklist - Update from $blacklist_src completed\""); - + my $elapsed = time() - $seconds; + &General::log("installpackage[urlfilter]", "URL filter blacklist - Update from $blacklist_src completed in $elapsed seconds."); $exitcode = 0; - } else { print "ERROR: Not a valid URL filter blacklist\n" if ($debugLevel > 0); @@ -266,6 +274,9 @@ if ((-d $target) && ($make_clean)) { system("rm -rf $target"); } + + close(LOCKFILE); + unlink("${dbdir}/.lock"); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Virtualization & Cloud Management Using Capacity Planning Cloud computing makes use of virtualization - but cloud computing also focuses on allowing computing to be delivered as a service. http://www.accelacomm.com/jaw/sfnl/114/51521223/ _______________________________________________ Ipcop-svn mailing list Ipcop-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/ipcop-svn