summaryrefslogtreecommitdiffstats
path: root/etc
diff options
context:
space:
mode:
authorScott Ullrich <sullrich@pfsense.org>2009-09-17 21:48:08 -0400
committerScott Ullrich <sullrich@pfsense.org>2009-09-17 21:48:08 -0400
commit9e7ef1a5f074fcad4a3f9fab4d44e8dfddf4449e (patch)
tree01413566dce8fe5d940478843018856933c17eb3 /etc
parente59dd448d11c74d13aa162f0e3563c0f9bc54b99 (diff)
downloadpfsense-9e7ef1a5f074fcad4a3f9fab4d44e8dfddf4449e.zip
pfsense-9e7ef1a5f074fcad4a3f9fab4d44e8dfddf4449e.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.inc62
1 files changed, 18 insertions, 44 deletions
diff --git a/etc/inc/util.inc b/etc/inc/util.inc
index 845f41c..5729fd6 100644
--- a/etc/inc/util.inc
+++ b/etc/inc/util.inc
@@ -122,54 +122,28 @@ function config_unlock() {
/* 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");
-
- $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.
- ini_set('error_reporting', E_NONE);
-
- if (!sem_acquire($cfglckkey)) {
- log_error("WARNING: lock() - Could not acquire {$lock} lock!");
- sem_remove($cfglckkey);
- 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;
-
- // Rely on or own logging for errors here.
- 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;
}
function is_module_loaded($module_name) {
OpenPOWER on IntegriCloud