summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorScott Ullrich <sullrich@pfsense.org>2009-09-17 21:47:34 -0400
committerScott Ullrich <sullrich@pfsense.org>2009-09-17 21:47:34 -0400
commite6b21089430306b48bc2b44e5eb069423f162b98 (patch)
tree6683f694c6fd58e548488e0906d4f75f3a84f124 /etc
parent92880548e03b24f41372cbb1fee8008689fbe903 (diff)
downloadpfsense-e6b21089430306b48bc2b44e5eb069423f162b98.zip
pfsense-e6b21089430306b48bc2b44e5eb069423f162b98.tar.gz
Update locking to use Ermals non semaphore patch. I just beat the holy heck out of it with the CP torture scripts and all seems OK
Diffstat (limited to 'etc')
-rw-r--r--etc/inc/util.inc59
1 files changed, 18 insertions, 41 deletions
diff --git a/etc/inc/util.inc b/etc/inc/util.inc
index 6fc5476..ba0460d 100644
--- a/etc/inc/util.inc
+++ b/etc/inc/util.inc
@@ -344,52 +344,29 @@ function get_interface_list($mode = "active", $keyby = "physical", $vfaces = "")
return $iflist;
}
-/* lock configuration file */
function lock($lock) {
- global $g, $cfglckkeyconsumers;
-
- if (!$lock)
- die("WARNING: You must give a name as parameter to lock() function.");
- if (!file_exists("{$g['tmp_path']}/{$lock}.lock"))
- @touch("{$g['tmp_path']}/{$lock}.lock");
- ini_set('error_reporting', E_NONE);
- $config_lock_key = ftok("{$g['tmp_path']}/{$lock}.lock", 'a');
- $cfglckkey = sem_get($config_lock_key, 1, 0666, true);
- $cfglckkeyconsumers++;
- // Rely on or own logging for errors here.
- if (!sem_acquire($cfglckkey)) {
- log_error("WARNING: lock() - Could not acquire {$lock} lock!");
- ini_set('error_reporting', E_NONE);
- sem_remove($cfglckkey);
- ini_set('error_reporting', E_ALL & ~E_NOTICE);
- return NULL;
- } else if ($g['debug'])
- log_error("lock() - Got {$file} lock.");
- ini_set('error_reporting', E_ALL & ~E_NOTICE);
- return $cfglckkey;
+ global $g, $cfglckkeyconsumers;
+ if (!$lock)
+ die("WARNING: You must give a name as parameter to lock() function.");
+ if (!file_exists("{$g['tmp_path']}/{$lock}.lock"))
+ @touch("{$g['tmp_path']}/{$lock}.lock");
+ ini_set('error_reporting', E_NONE);
+ $config_lock_key = ftok("{$g['tmp_path']}/{$lock}.lock", 'a');
+ $cfglckkey = sem_get($config_lock_key, 1, 0666, true);
+ $cfglckkeyconsumers++;
+ if ($fp = fopen("{$g['tmp_path']}/{$lock}.lock", "w+")) {
+ if (flock($fp, LOCK_EX))
+ return $fp;
+ else
+ fclose($fp);
+ }
}
/* unlock configuration file */
function unlock($cfglckkey = 0) {
- global $g, $cfglckkeyconsumers;
-
- if ($cfglckkey == 0)
- return;
-
- ini_set('error_reporting', E_NONE);
-
- if (!sem_release($cfglckkey))
- log_error("WARNING: unlock() - Could not unlock lock.");
- else {
- if ($g['debug'])
- log_error("Released lock.");
- ini_set('error_reporting', E_NONE);
- sem_remove($cfglckkey);
- ini_set('error_reporting', E_ALL & ~E_NOTICE);
- }
- $cfglckkeyconsumers--;
-
- ini_set('error_reporting', E_ALL & ~E_NOTICE);
+ global $g, $cfglckkeyconsumers;
+ flock($cfglckkey, LOCK_UN);
+ return;
}
/* wrapper for exec() */
OpenPOWER on IntegriCloud