Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions plugin/plugin.j2
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions tests/config_backup_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading