Revision b6c34bfc
Added by Ermal LUÇI about 15 years ago
etc/inc/config.lib.inc | ||
---|---|---|
338 | 338 |
|
339 | 339 |
clear_subsystem_dirty('mount'); |
340 | 340 |
/* sync data, then force a remount of /cf */ |
341 |
mwexec("/bin/sync"); |
|
342 |
mwexec("/bin/sync"); |
|
341 |
mwexec("/bin/sync; /bin/sync"); |
|
343 | 342 |
mwexec("/sbin/mount -u -r -f {$g['cf_path']}"); |
344 | 343 |
mwexec("/sbin/mount -u -r -f /"); |
345 | 344 |
} |
... | ... | |
474 | 473 |
$config['revision']['description'] = "{$_SESSION['Username']}: " . $desc; |
475 | 474 |
$config['revision']['username'] = $_SESSION["Username"]; |
476 | 475 |
|
477 |
$lockkey = lock('config'); |
|
476 |
conf_mount_rw(); |
|
477 |
$lockkey = lock('config', LOCK_EX); |
|
478 | 478 |
|
479 | 479 |
/* generate configuration XML */ |
480 | 480 |
$xmlconfig = dump_xml_config($config, $g['xml_rootobj']); |
481 | 481 |
|
482 |
conf_mount_rw(); |
|
483 |
|
|
484 | 482 |
/* write new configuration */ |
485 | 483 |
if (!safe_write_file("{$g['cf_conf_path']}/config.xml", $xmlconfig, false)) { |
486 | 484 |
log_error("WARNING: Config contents could not be save. Could not open file!"); |
... | ... | |
506 | 504 |
fclose($fd); |
507 | 505 |
} |
508 | 506 |
|
509 |
/* tell kernel to sync fs data */ |
|
510 |
if (!$g['booting']) |
|
511 |
conf_mount_ro(); |
|
512 |
|
|
513 | 507 |
unlock($lockkey); |
514 | 508 |
|
515 | 509 |
unlink_if_exists("/usr/local/pkg/pf/carp_sync_client.php"); |
516 | 510 |
|
511 |
/* tell kernel to sync fs data */ |
|
512 |
conf_mount_ro(); |
|
513 |
|
|
517 | 514 |
/* sync carp entries to other firewalls */ |
518 | 515 |
carp_sync_client(); |
519 | 516 |
|
... | ... | |
534 | 531 |
function reset_factory_defaults($lock = false) { |
535 | 532 |
global $g; |
536 | 533 |
|
537 |
if (!$lock) |
|
538 |
$lockkey = lock('config'); |
|
539 | 534 |
conf_mount_rw(); |
535 |
if (!$lock) |
|
536 |
$lockkey = lock('config', LOCK_EX); |
|
540 | 537 |
|
541 | 538 |
/* create conf directory, if necessary */ |
542 | 539 |
safe_mkdir("{$g['cf_conf_path']}"); |
... | ... | |
555 | 552 |
|
556 | 553 |
/* call the wizard */ |
557 | 554 |
touch("/conf/trigger_initial_wizard"); |
558 |
conf_mount_ro(); |
|
559 | 555 |
if (!$lock) |
560 | 556 |
unlock($lockkey); |
557 |
conf_mount_ro(); |
|
561 | 558 |
|
562 | 559 |
return 0; |
563 | 560 |
} |
... | ... | |
572 | 569 |
|
573 | 570 |
conf_mount_rw(); |
574 | 571 |
|
575 |
$lockkey = lock('config'); |
|
572 |
$lockkey = lock('config', LOCK_EX);
|
|
576 | 573 |
|
577 | 574 |
copy($conffile, "{$g['cf_conf_path']}/config.xml"); |
578 | 575 |
unlink_if_exists("{$g['tmp_path']}/config.cache"); |
... | ... | |
603 | 600 |
log_error("Installing configuration ...."); |
604 | 601 |
|
605 | 602 |
conf_mount_rw(); |
606 |
$lockkey = lock('config'); |
|
603 |
$lockkey = lock('config', LOCK_EX);
|
|
607 | 604 |
|
608 | 605 |
copy($conffile, "{$g['conf_path']}/config.xml"); |
609 | 606 |
|
Also available in: Unified diff
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.