diff options
author | Ermal <eri@pfsense.org> | 2010-05-13 18:23:07 +0000 |
---|---|---|
committer | Ermal <eri@pfsense.org> | 2010-05-13 18:23:07 +0000 |
commit | b6c34bfcb51ac68036a900e96ee8036e6bd8f2c3 (patch) | |
tree | 8785b77bd1cfe13867a5844a0bd0014e04deb143 /etc/inc/util.inc | |
parent | 883b25522646849a376438c6413b0b5fd008e60f (diff) | |
download | pfsense-b6c34bfcb51ac68036a900e96ee8036e6bd8f2c3.zip pfsense-b6c34bfcb51ac68036a900e96ee8036e6bd8f2c3.tar.gz |
Ticket #544. Restore locking, seems w+ migh already lock the file sometimes. While there improve the locking to a read/write locking schema. Make the default locking a read only lock and if explicitly specified a write locking can be specified through LOCK_EX optional parameter to lock(). During config manipulation do the filesystem mounting in rw, if needed, before doing any locking to avoid possible problems and also to be consistent through out the code on the method used. Also update calls to config to lock exclusively where required.
Diffstat (limited to 'etc/inc/util.inc')
-rw-r--r-- | etc/inc/util.inc | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/etc/inc/util.inc b/etc/inc/util.inc index 0fc10d7..930f9ac 100644 --- a/etc/inc/util.inc +++ b/etc/inc/util.inc @@ -119,18 +119,18 @@ function config_unlock() { } /* lock configuration file */ -function lock($lock) { +function lock($lock, $op = LOCK_SH) { 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"); $cfglckkeyconsumers++; - if ($fp = fopen("{$g['tmp_path']}/{$lock}.lock", "w+")) { - //if (flock($fp, LOCK_EX)) + if ($fp = fopen("{$g['tmp_path']}/{$lock}.lock", "w")) { + if (flock($fp, $op)) return $fp; - //else - // fclose($fp); + else + fclose($fp); } } |