summaryrefslogtreecommitdiffstats
path: root/src/etc/rc.prunecaptiveportal
diff options
context:
space:
mode:
authorplumbeo <plumbeo@users.noreply.github.com>2016-12-28 02:15:46 +0100
committerplumbeo <plumbeo@users.noreply.github.com>2016-12-29 11:55:57 +0100
commitd793617ee9b4c3f66575737df3e8f6cf04e7c782 (patch)
tree5814116b0d63187c0315b1c8593cca9ae04ea022 /src/etc/rc.prunecaptiveportal
parent025ec94a3285c129d2e14b00b629e811b83a9330 (diff)
downloadpfsense-d793617ee9b4c3f66575737df3e8f6cf04e7c782.zip
pfsense-d793617ee9b4c3f66575737df3e8f6cf04e7c782.tar.gz
Captive portal: use locking to avoid race conditions between rc.prunecaptiveportal and captiveportal_disconnect_all()
Convert rc.prunecaptiveportal to lock()/unlock()/try_lock() and use the lock to ensure that there aren't race conditions between it and captiveportal_disconnect_all().
Diffstat (limited to 'src/etc/rc.prunecaptiveportal')
-rwxr-xr-xsrc/etc/rc.prunecaptiveportal18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/etc/rc.prunecaptiveportal b/src/etc/rc.prunecaptiveportal
index 8a5253b..89e6328 100755
--- a/src/etc/rc.prunecaptiveportal
+++ b/src/etc/rc.prunecaptiveportal
@@ -43,18 +43,16 @@ if (!is_array($config['captiveportal'][$cpzone])) {
}
$cpzoneid = $config['captiveportal'][$cpzone]['zoneid'];
-if (file_exists("{$g['tmp_path']}/.rc.prunecaptiveportal.{$cpzone}.running")) {
- $stat = stat("{$g['tmp_path']}/.rc.prunecaptiveportal.{$cpzone}.running");
- if (time() - $stat['mtime'] >= 120) {
- @unlink("{$g['tmp_path']}/.rc.prunecaptiveportal.{$cpzone}.running");
- } else {
- log_error("Skipping CP pruning process because previous/another instance is already running");
- return;
- }
+$rcprunelock = try_lock("rcprunecaptiveportal{$cpzone}", 3);
+
+if (!$rcprunelock) {
+ log_error("Skipping CP pruning process for zone {$cpzone} because previous/another instance is already running");
+ unlock_force("rcprunecaptiveportal{$cpzone}");
+ return;
}
-@file_put_contents("{$g['tmp_path']}/.rc.prunecaptiveportal.{$cpzone}.running", "");
captiveportal_prune_old();
-@unlink("{$g['tmp_path']}/.rc.prunecaptiveportal.{$cpzone}.running");
+
+unlock($rcprunelock);
?>
OpenPOWER on IntegriCloud