Implement clean shutdown after receiving Unix signals, resolves #169 #170
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
The database wasn't saved properly and lockfiles were not removed when receiving the signals SIGINT, SIGTERM, SIGQUIT or SIGHUP. This patch implements signal handling and performs a clean shutdown after receiving SIGINT SIGTERM or SIGQUIT and ignores SIGHUP.
Since this uses POSIX syscalls for signal and socket handling, there is no Windows implementation at the moment.
This resolves issue #169.
Motivation and Context
This patch makes sure the database is properly saved when closing KeePassXC using Ctrl+C on the terminal or when logging out of the desktop session. It also removes the lock file and therefore prevents cluttering the file system.
How Has This Been Tested?
For testing a clean shutdown, a SIGINT was sent to the application via Ctrl+C and killall -INT keepassxc. When there were unsaved changes, KeePassXC asked the user whether to save or discard the changes and then shut down and removed the lock file.
The same behavior was tested with killall for SIGQUIT and SIGTERM as well as SIGHUP which is ignored as intended.
Types of changes
Checklist: