watt: implement single-instance lock mechanism for watt daemon#47
Merged
watt: implement single-instance lock mechanism for watt daemon#47
Conversation
fda9b6e to
f9e0c0c
Compare
RGBCube
reviewed
Jan 28, 2026
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: Ideaf221f690c7bc694ca1f171385bfde6a6a6964
f9e0c0c to
54a6879
Compare
RGBCube
requested changes
Jan 28, 2026
Collaborator
RGBCube
left a comment
There was a problem hiding this comment.
Bro burnt the pan after review 😭
| .map(|dir| PathBuf::from(dir).join("watt.pid")) | ||
| .unwrap_or_else(|_| PathBuf::from("/run/watt.pid")); | ||
|
|
||
| let _lock = lock::LockFile::acquire(&lock_path, cli.force).context( |
Collaborator
There was a problem hiding this comment.
with_context, otherwise you're allocating each time even on no error
Comment on lines
+51
to
+53
| let lock_path = env::var("XDG_RUNTIME_DIR") | ||
| .map(|dir| PathBuf::from(dir).join("watt.pid")) | ||
| .unwrap_or_else(|_| PathBuf::from("/run/watt.pid")); |
Collaborator
There was a problem hiding this comment.
Why not .join("watt.pid") at the end?
let lock_path = env::var_os("XDG_RUNTIME_DIR"). map_or_else(PathBuf::new, || PathBuf::new("/run")).join("watt.pid")
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This was probably something we should've implemented earlier. While not too likely, it's possible that there will be multiple Watt instances running simultaneously, which can create access issues if two of them try to write a sysfs path at the same time. This PR introduces process locking to the Watt daemon in order to prevent multiple instances from running simultaneously.
This is done in the new
watt::lockmodule that manages a PID file lock, and a new--forceflag has been added for when this behaviour is explicitly desired.Change-Id: Ideaf221f690c7bc694ca1f171385bfde6a6a6964