summaryrefslogtreecommitdiffstats
path: root/etc/inc/util.inc
diff options
context:
space:
mode:
authorErmal Luçi <eri@pfsense.org>2009-05-08 18:42:37 +0000
committerErmal Luçi <eri@pfsense.org>2009-05-08 18:42:37 +0000
commit0027de0a544438f146cfc94f005fd6f4ba9f94d7 (patch)
tree3f97d22951284c2a7b02563ecdbb0fd126b46f15 /etc/inc/util.inc
parent89e6e210158ca4ca24d2ddbc02ccab72175875a5 (diff)
downloadpfsense-0027de0a544438f146cfc94f005fd6f4ba9f94d7.zip
pfsense-0027de0a544438f146cfc94f005fd6f4ba9f94d7.tar.gz
* Create two new functions lock($subsystem)/unlock() to have more reliable locking using semaphores.
This function can sleep till the resource is free and can help find not well behaving code. * Remove most of the config_lock/config_unlock logics on the whole scripts/pages it is an abuse of this. If any sybsytem wants to lock can do so with its own lock. * Lock the config when doing a filter reload to avoid parallell recursion on this function, since it is not reentrant. This compenstates for the removal of lock aquiring from the scripts/pages. * config_lock/config_unlock are now compate shims that do nothing. They are preserved since packages 'abuse' them too.
Diffstat (limited to 'etc/inc/util.inc')
-rw-r--r--etc/inc/util.inc66
1 files changed, 53 insertions, 13 deletions
diff --git a/etc/inc/util.inc b/etc/inc/util.inc
index 8968428..e1bc857 100644
--- a/etc/inc/util.inc
+++ b/etc/inc/util.inc
@@ -77,6 +77,53 @@ function killbyname($procname) {
mwexec("/usr/bin/killall " . escapeshellarg($procname));
}
+function config_lock() {
+ log_error("config_lock() is depricated please use lock().");
+ return;
+}
+function config_unlock() {
+ log_error("config_unlock() is depricated please use unlock().");
+ return;
+}
+
+/* lock configuration file */
+function lock($file) {
+ global $g, $cfglckkeyconsumers;
+
+ if (!$file)
+ 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);
+ $cfglckkeyconsumers++;
+ 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 config lock.");
+
+ return $cfglckkey;
+}
+
+/* unlock configuration file */
+function unlock($cfglckkey = 0) {
+ global $g, $cfglckkeyconsumers;
+
+ if (!$cfglckkey)
+ return;
+
+ if (!sem_release($cfglckkey))
+ log_error("WARNING: unlock() - Could not unlock config lock.");
+ else {
+ if ($g['debug'])
+ log_error("Released config lock.");
+ sem_remove($cfglckkey);
+ }
+ $cfglckkeyconsumers--;
+}
+
function is_module_loaded($module_name) {
$running = `/sbin/kldstat | grep {$module_name} | /usr/bin/grep -v grep | /usr/bin/wc -l`;
if (intval($running) >= 1)
@@ -803,19 +850,12 @@ function run_plugins($directory) {
$files = return_dir_as_array($directory);
if (is_array($files)) {
foreach ($files as $file) {
- if($file) {
- $text = file_get_contents($directory . $file);
- if($text) {
- if(stristr($file, ".sh") == true) {
- mwexec($directory . $file . " start");
- } else {
- if(!stristr($file,"CVS")) {
- if($g['booting'] == true)
- echo "\t{$file}... ";
- require_once($directory . $file);
- }
- }
- }
+ if (stristr($file, ".sh") == true)
+ mwexec($directory . $file . " start");
+ else if (!stristr($file,"CVS")) {
+ if ($g['booting'] == true)
+ echo "\t{$file}... ";
+ require_once($directory . $file);
}
}
}
OpenPOWER on IntegriCloud