mirror of
https://github.com/lucaspalomodevelop/opnsense-core.git
synced 2026-03-13 00:07:27 +00:00
firewall: move lock()/unlock() to their final resting place
Simplify the code a little while at it.
This commit is contained in:
parent
0284cb4d34
commit
1130442142
@ -55,6 +55,34 @@ function is_bogonsv6_used()
|
||||
return $usebogonsv6;
|
||||
}
|
||||
|
||||
/* lock configuration file */
|
||||
function filter_lock($lock = 'filter', $op = LOCK_EX)
|
||||
{
|
||||
if (!$lock) {
|
||||
die(gettext("WARNING: You must give a name as parameter to lock() function."));
|
||||
}
|
||||
|
||||
if (!file_exists("{/tmp/{$lock}.lock")) {
|
||||
@touch("/tmp/{$lock}.lock");
|
||||
@chmod("/tmp/{$lock}.lock", 0666);
|
||||
}
|
||||
|
||||
if ($fp = fopen("/tmp/{$lock}.lock", 'a+e')) {
|
||||
if (flock($fp, $op)) {
|
||||
return $fp;
|
||||
} else {
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* unlock configuration file */
|
||||
function filter_unlock($fp)
|
||||
{
|
||||
flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
/* sort by interface only, retain the original order of rules that apply to
|
||||
the same interface */
|
||||
function filter_rules_sort()
|
||||
@ -158,7 +186,7 @@ function filter_configure_sync($verbose = false, $load_aliases = true)
|
||||
service_log('Configuring firewall.', $verbose);
|
||||
|
||||
/* Use filter lock to not allow concurrent filter reloads during this run. */
|
||||
$filterlck = lock('filter', LOCK_EX);
|
||||
$locked = filter_lock();
|
||||
|
||||
ifgroup_setup();
|
||||
|
||||
@ -273,7 +301,7 @@ function filter_configure_sync($verbose = false, $load_aliases = true)
|
||||
} else {
|
||||
mwexec("/sbin/pfctl -d", true);
|
||||
|
||||
unlock($filterlck);
|
||||
filter_unlock($locked);
|
||||
closelog();
|
||||
reopenlog();
|
||||
|
||||
@ -381,7 +409,7 @@ function filter_configure_sync($verbose = false, $load_aliases = true)
|
||||
syslog(LOG_ERR, 'ERROR: Could not write new rules!');
|
||||
file_put_contents('/tmp/rules.error', gettext('ERROR: Could not write new rules!'));
|
||||
|
||||
unlock($filterlck);
|
||||
filter_unlock($locked);
|
||||
closelog();
|
||||
reopenlog();
|
||||
|
||||
@ -423,7 +451,7 @@ function filter_configure_sync($verbose = false, $load_aliases = true)
|
||||
sprintf(gettext('There were error(s) loading the rules: %s%s'), $rules_error[0], $config_line)
|
||||
);
|
||||
|
||||
unlock($filterlck);
|
||||
filter_unlock($locked);
|
||||
closelog();
|
||||
reopenlog();
|
||||
|
||||
@ -457,7 +485,7 @@ function filter_configure_sync($verbose = false, $load_aliases = true)
|
||||
killbypid('/var/run/filterlog.pid');
|
||||
mwexec('/usr/local/sbin/filterlog -i pflog0 -p /var/run/filterlog.pid');
|
||||
|
||||
unlock($filterlck);
|
||||
filter_unlock($locked);
|
||||
closelog();
|
||||
reopenlog();
|
||||
|
||||
|
||||
@ -306,34 +306,6 @@ function clear_subsystem_dirty($subsystem = '')
|
||||
@unlink("/tmp/{$subsystem}.dirty");
|
||||
}
|
||||
|
||||
/* lock configuration file */
|
||||
function lock($lock, $op = LOCK_SH)
|
||||
{
|
||||
if (!$lock) {
|
||||
die(gettext("WARNING: You must give a name as parameter to lock() function."));
|
||||
}
|
||||
|
||||
if (!file_exists("{/tmp/{$lock}.lock")) {
|
||||
@touch("/tmp/{$lock}.lock");
|
||||
@chmod("/tmp/{$lock}.lock", 0666);
|
||||
}
|
||||
|
||||
if ($fp = fopen("/tmp/{$lock}.lock", 'a+e')) {
|
||||
if (flock($fp, $op)) {
|
||||
return $fp;
|
||||
} else {
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* unlock configuration file */
|
||||
function unlock($fp)
|
||||
{
|
||||
flock($fp, LOCK_UN);
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
function exit_on_bootup($callback = null, $arguments = [])
|
||||
{
|
||||
if (product::getInstance()->booting()) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user