]> git.ipfire.org Git - people/stevee/ipfire-2.x.git/commitdiff
update-ids-ruleset: Always drop the lock file if it has been created during runtime.
authorStefan Schantl <stefan.schantl@ipfire.org>
Thu, 3 Mar 2022 04:49:43 +0000 (05:49 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Mon, 7 Mar 2022 18:49:59 +0000 (18:49 +0000)
In some situations or if an error happened, the lock file could be
keep on the system. In such a case the IDS page would be locked forever
until user interaction or reboot of the system.

Now the script checks if it has created such a lock and release it when
the script exists.

Signed-off-by: Stefan Schantl <stefan.schantl@ipfire.org>
Reviewed-by: Michael Tremer <michael.tremer@ipfire.org>
Acked-by: Peter Müller <peter.mueller@ipfire.org>
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/scripts/update-ids-ruleset

index 10a2709074dfecc3575834d9a7970269b6501b65..c2970d20b49ce886a1c6b42457894936f058e738 100644 (file)
@@ -26,6 +26,9 @@ require '/var/ipfire/general-functions.pl';
 require "${General::swroot}/ids-functions.pl";
 require "${General::swroot}/lang.pl";
 
+# Variable to store if the process has written a lockfile.
+my $locked;
+
 # Hash to store the configured providers.
 my %providers = ();
 
@@ -77,6 +80,9 @@ if(&IDS::checkdiskspace()) {
 # Lock the IDS page.
 &IDS::lock_ids_page();
 
+# The script has requested a lock, so set locket to "1".
+$locked = "1";
+
 # Grab the configured providers.
 &General::readhasharray("$IDS::providers_settings_file", \%providers);
 
@@ -114,13 +120,20 @@ foreach my $id (keys %providers) {
 # Set correct ownership for the rulesdir and files.
 &IDS::set_ownership("$IDS::rulespath");
 
-# Unlock the IDS page.
-&IDS::unlock_ids_page();
-
 # Check if the IDS is running.
 if(&IDS::ids_is_running()) {
        # Call suricatactrl to perform a reload.
        &IDS::call_suricatactrl("reload");
 }
 
+# Custom END declaration to release a IDS page lock
+# when the script has created one.
+END {
+       # Check if a lock has been requested.
+       if ($locked) {
+               # Unlock the IDS page.
+               &IDS::unlock_ids_page();
+       }
+}
+
 1;