]> git.proxmox.com Git - pve-firewall.git/blobdiff - PVE/Firewall.pm
implement locking
[pve-firewall.git] / PVE / Firewall.pm
index 8e5cfb1f996ccc0d552173c87cce02bcec9e0f76..19314ad5da3cd1659fbceb4c620f731d1804996c 100644 (file)
@@ -8,10 +8,12 @@ use PVE::QemuServer;
 use File::Path;
 use IO::File;
 use Net::IP;
-use PVE::Tools qw(run_command);
+use PVE::Tools qw(run_command lock_file);
 
 use Data::Dumper;
 
+my $pve_fw_lock_filename = "/var/lock/pvefw.lck";
+
 my $macros;
 my @ruleset = ();
 
@@ -960,6 +962,18 @@ sub parse_fw_rules {
     return $res;
 }
 
+sub run_locked {
+    my ($code, @param) = @_;
+
+    my $timeout = 10;
+
+    my $res = lock_file($pve_fw_lock_filename, $timeout, $code, @param);
+
+    die $@ if $@;
+
+    return $res;
+}
+
 sub read_local_vm_config {
 
     my $openvz = {};