diff --git a/plugin/plugin.j2 b/plugin/plugin.j2 index 5756391..abb57e7 100644 --- a/plugin/plugin.j2 +++ b/plugin/plugin.j2 @@ -93,16 +93,13 @@ fi mkdir -p /var/tmp/fanctrlplus2 rm -f /var/tmp/fanctrlplus2/* pkill -f "/usr/local/emhttp/plugins/fanctrlplus2/scripts/array_monitor.sh" +rm -f /boot/config/plugins/fanctrlplus2/.config.lock # the lock now lives in /var/run +# start() launches array_monitor.sh (pgrep-guarded); do not start it again here. if [[ -x "$dst" ]]; then "$dst" restart fi -script="/usr/local/emhttp/plugins/fanctrlplus2/scripts/array_monitor.sh" -if [[ -x "$script" ]]; then - nohup "$script" >/dev/null 2>&1 & -fi - echo "" echo "------------------------------------------------" echo " FanCtrl Plus 2 is installed." diff --git a/src/usr/local/emhttp/plugins/fanctrlplus2/include/ConfigBackup.php b/src/usr/local/emhttp/plugins/fanctrlplus2/include/ConfigBackup.php index 823ce64..a1dbc56 100644 --- a/src/usr/local/emhttp/plugins/fanctrlplus2/include/ConfigBackup.php +++ b/src/usr/local/emhttp/plugins/fanctrlplus2/include/ConfigBackup.php @@ -5,7 +5,8 @@ function fcp_config_lock(string $dir, int $mode = LOCK_EX) { if (is_link($dir) || (!is_dir($dir) && !@mkdir($dir, 0700, true))) throw new RuntimeException('Configuration directory is unavailable.'); - $path = "$dir/.config.lock"; + // In RAM, so taking the lock never writes to the flash drive (#19). Shared with array_monitor.sh. + $path = getenv('FCP_CONFIG_LOCK') ?: '/var/run/fanctrlplus2.config.lock'; if (is_link($path) || (file_exists($path) && !is_file($path))) throw new RuntimeException('Unsafe configuration lock.'); // Service daemons must never inherit the request's flock descriptor. $lock = @fopen($path, 'ce'); diff --git a/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/array_monitor.sh b/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/array_monitor.sh index 2360543..0f737f1 100644 --- a/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/array_monitor.sh +++ b/src/usr/local/emhttp/plugins/fanctrlplus2/scripts/array_monitor.sh @@ -7,7 +7,7 @@ rc_script="/etc/rc.d/rc.${plugin}" pidfile="/var/run/fanctrlplus2.user_stopped" # Shared with the settings page; a configuration restore holds it while it # swaps files. -config_lock="/boot/config/plugins/${plugin}/.config.lock" +config_lock="/var/run/${plugin}.config.lock" last_md_state="" last_fanctrl_state=0 @@ -45,7 +45,7 @@ while true; do log "FanCtrlPlus not running after array start → launching" "$rc_script" start 9>&- fi - ) 9>"$config_lock" + ) 9>>"$config_lock" # append: '>' would rewrite the file on the flash drive every pass fi sleep "$CHECK_INTERVAL" diff --git a/tests/config_backup_test.php b/tests/config_backup_test.php index f14658c..8402aa1 100644 --- a/tests/config_backup_test.php +++ b/tests/config_backup_test.php @@ -4,6 +4,7 @@ require_once $module; $root = sys_get_temp_dir().'/fcp_backup_'.getmypid(); mkdir($root, 0700, true); +putenv("FCP_CONFIG_LOCK=$root/.config.lock"); $failures = []; $check = function ($condition, string $message) use (&$failures) { if (!$condition) $failures[] = $message; }; $fan = <<<'CFG'