mirror of
https://github.com/pfsense/pfsense.git
synced 2025-10-26 11:38:35 +00:00
Ticket #1279. Decrease the refcount even though we're in booting phase. This helps the refcount to work as intended and help in making filesystem read only correctly on embedded platfroms. While here put some exceptions to refcount API and silent any related errors that might trigger. Also take not of the NOTE on the php manual that after a share memory is opened further references to it for size and access mode should be 0.
This commit is contained in:
parent
86e1405de4
commit
e1b068d70b
@ -348,10 +348,10 @@ function conf_mount_ro() {
|
||||
if($platform == "cdrom" or $platform == "pfSense")
|
||||
return;
|
||||
|
||||
if($g['booting'])
|
||||
if (refcount_unreference(1000) > 0)
|
||||
return;
|
||||
|
||||
if (refcount_unreference(1000) > 0)
|
||||
if($g['booting'])
|
||||
return;
|
||||
|
||||
clear_subsystem_dirty('mount');
|
||||
|
||||
@ -179,36 +179,44 @@ function send_multiple_events($cmds) {
|
||||
}
|
||||
|
||||
function refcount_init($reference) {
|
||||
$shmid = shmop_open($reference, "c", 0644, 10);
|
||||
shmop_write($shmid, 0, 0);
|
||||
shmop_close($shmid);
|
||||
$shmid = @shmop_open($reference, "c", 0644, 10);
|
||||
@shmop_write($shmid, 0, 0);
|
||||
@shmop_close($shmid);
|
||||
}
|
||||
|
||||
function refcount_reference($reference) {
|
||||
$shmid = @shmop_open($reference, "w", 0644, 10);
|
||||
if (!$shmid) {
|
||||
refcount_init($reference);
|
||||
$shmid = shmop_open($reference, "w", 0644, 10);
|
||||
try {
|
||||
$shmid = @shmop_open($reference, "w", 0, 0);
|
||||
if (!$shmid) {
|
||||
refcount_init($reference);
|
||||
$shmid = @shmop_open($reference, "w", 0, 0);
|
||||
}
|
||||
$shm_data = @shmop_read($shmid, 0, 10);
|
||||
$shm_data = intval($shm_data) + 1;
|
||||
@shmop_write($shmid, $shm_data, 0);
|
||||
@shmop_close($shmid);
|
||||
} catch (Exception $e) {
|
||||
log_error($e->getMessage());
|
||||
}
|
||||
$shm_data = shmop_read($shmid, 0, 10);
|
||||
$shm_data = intval($shm_data) + 1;
|
||||
shmop_write($shmid, $shm_data, 0);
|
||||
shmop_close($shmid);
|
||||
|
||||
|
||||
return $shm_data;
|
||||
}
|
||||
|
||||
function refcount_unreference($reference) {
|
||||
/* We assume that the shared memory exists. */
|
||||
$shmid = shmop_open($reference, "w", 0644, 10);
|
||||
$shm_data = shmop_read($shmid, 0, 10);
|
||||
$shm_data = intval($shm_data) - 1;
|
||||
if ($shm_data < 0) {
|
||||
//debug_backtrace();
|
||||
log_error("Reference {$reference} is going negative, not doing unreference.");
|
||||
} else
|
||||
shmop_write($shmid, $shm_data, 0);
|
||||
shmop_close($shmid);
|
||||
try {
|
||||
/* We assume that the shared memory exists. */
|
||||
$shmid = @shmop_open($reference, "w", 0, 0);
|
||||
$shm_data = @shmop_read($shmid, 0, 10);
|
||||
$shm_data = intval($shm_data) - 1;
|
||||
if ($shm_data < 0) {
|
||||
//debug_backtrace();
|
||||
log_error("Reference {$reference} is going negative, not doing unreference.");
|
||||
} else
|
||||
@shmop_write($shmid, $shm_data, 0);
|
||||
@shmop_close($shmid);
|
||||
} catch (Exception $e) {
|
||||
log_error($e->getMessage());
|
||||
}
|
||||
|
||||
return $shm_data;
|
||||
}
|
||||
@ -1502,4 +1510,4 @@ function array_merge_recursive_unique($array0, $array1) {
|
||||
return $result;
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user