Skip to content

fix(config): write config atomically via tmp + rename#550

Open
jelmerdehen wants to merge 1 commit intoPixlOne:mainfrom
jelmerdehen:fix/atomic-config-save
Open

fix(config): write config atomically via tmp + rename#550
jelmerdehen wants to merge 1 commit intoPixlOne:mainfrom
jelmerdehen:fix/atomic-config-save

Conversation

@jelmerdehen
Copy link
Copy Markdown

Summary

Configuration::save calls _config.writeFile(path) directly on the destination. A crash, power loss, or out-of-disk during the write leaves a truncated or corrupt /etc/logid.cfg behind, after which logid fails to start.

Fix

Write to <path>.tmp first, then std::filesystem::rename over the destination. The destination always holds either the previous contents or the full new contents. Tmp file is removed on error.

Test plan

  • Builds cleanly.
  • Trigger Save over D-Bus and confirm /etc/logid.cfg updates atomically.
  • Inject a write failure and confirm the original config survives.

writeFile overwrote the existing config in place. A crash, power loss,
or out-of-disk during the write would leave a truncated or corrupt
config behind. Write to <path>.tmp and rename, so the destination
either holds the previous contents or the full new contents. Clean up
the tmp file on error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant