Fix permission denied error when updating allowed_nodes

The update_allowed_nodes function was changing ownership of the temp file
before all writes were complete, causing 'Permission denied' errors when
appending the allowed_nodes section.

Root cause:
- mktemp creates file owned by script runner (root)
- chown changed ownership to pulse-sensor-proxy:pulse-sensor-proxy
- Subsequent append (>>) failed because root can't write to the file

Fix: Defer chown until after all writes complete and file is moved to
final location. Ownership is still correctly set on the final config file.
This commit is contained in:
rcourtman 2025-11-14 23:21:46 +00:00
parent 20a5bcedad
commit 8204b54051

View file

@ -120,13 +120,11 @@ update_allowed_nodes() {
}
' "$config_file" > "$tmp_config"
# Preserve file permissions
# Preserve file permissions (but defer ownership change until after all writes)
chmod --reference="$config_file" "$tmp_config" 2>/dev/null || chmod 0644 "$tmp_config"
chown --reference="$config_file" "$tmp_config" 2>/dev/null || true
else
touch "$tmp_config"
chmod 0644 "$tmp_config"
chown pulse-sensor-proxy:pulse-sensor-proxy "$tmp_config" 2>/dev/null || true
fi
# Append new allowed_nodes section