Project

General

Profile

« Previous | Next » 

Revision 9e7ef1a5

Added by Scott Ullrich almost 16 years ago

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

View differences:

etc/inc/util.inc
122 122

  
123 123
/* lock configuration file */
124 124
function lock($lock) {
125
        global $g, $cfglckkeyconsumers;
126

  
127
		if (!$lock)
128
			die("WARNING: You must give a name as parameter to lock() function.");
129
        if (!file_exists("{$g['tmp_path']}/{$lock}.lock"))
130
 			@touch("{$g['tmp_path']}/{$lock}.lock");
131

  
132
		$config_lock_key = ftok("{$g['tmp_path']}/{$lock}.lock", 'a');
133
		$cfglckkey = sem_get($config_lock_key, 1, 0666, true);
134
		$cfglckkeyconsumers++;
135

  
136
		// Rely on or own logging for errors here.
137
		ini_set('error_reporting', E_NONE);
138

  
139
		if (!sem_acquire($cfglckkey)) {
140
				log_error("WARNING: lock() -  Could not acquire {$lock} lock!");
141
				sem_remove($cfglckkey);
142
				return NULL;
143
		} else if ($g['debug'])
144
			log_error("lock() -  Got {$file} lock.");
145

  
146
		ini_set('error_reporting', E_ALL  & ~E_NOTICE);
147

  
148
		return $cfglckkey;
125
	global $g, $cfglckkeyconsumers;
126
	if (!$lock)
127
		die("WARNING: You must give a name as parameter to lock() function.");
128
	if (!file_exists("{$g['tmp_path']}/{$lock}.lock"))
129
		@touch("{$g['tmp_path']}/{$lock}.lock");
130
	ini_set('error_reporting', E_NONE);
131
	$config_lock_key = ftok("{$g['tmp_path']}/{$lock}.lock", 'a');
132
	$cfglckkey = sem_get($config_lock_key, 1, 0666, true);
133
	$cfglckkeyconsumers++;
134
	if ($fp = fopen("{$g['tmp_path']}/{$lock}.lock", "w+")) {
135
		if (flock($fp, LOCK_EX))
136
			return $fp;
137
		else
138
			fclose($fp);
139
	}
149 140
}
150 141

  
151 142
/* unlock configuration file */
152 143
function unlock($cfglckkey = 0) {
153
        global $g, $cfglckkeyconsumers;
154

  
155
        if ($cfglckkey == 0)
156
                return;
157

  
158
		// Rely on or own logging for errors here.
159
		ini_set('error_reporting', E_NONE);
160

  
161
        if (!sem_release($cfglckkey))
162
                log_error("WARNING: unlock() - Could not unlock lock.");
163
        else {
164
                if ($g['debug'])
165
                        log_error("Released lock.");
166
				ini_set('error_reporting', E_NONE);
167
                sem_remove($cfglckkey);
168
				ini_set('error_reporting', E_ALL  & ~E_NOTICE);
169
        }
170
        $cfglckkeyconsumers--;
171

  
172
		ini_set('error_reporting', E_ALL  & ~E_NOTICE);
144
	global $g, $cfglckkeyconsumers;
145
	flock($cfglckkey, LOCK_UN);
146
	return;
173 147
}
174 148

  
175 149
function is_module_loaded($module_name) {

Also available in: Unified diff