diff options
author | plumbeo <plumbeo@users.noreply.github.com> | 2016-12-28 02:15:46 +0100 |
---|---|---|
committer | plumbeo <plumbeo@users.noreply.github.com> | 2016-12-29 11:55:57 +0100 |
commit | d793617ee9b4c3f66575737df3e8f6cf04e7c782 (patch) | |
tree | 5814116b0d63187c0315b1c8593cca9ae04ea022 /src/etc/rc.prunecaptiveportal | |
parent | 025ec94a3285c129d2e14b00b629e811b83a9330 (diff) | |
download | pfsense-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-x | src/etc/rc.prunecaptiveportal | 18 |
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); ?> |