Skip to content

watt: implement single-instance lock mechanism for watt daemon#47

Merged
NotAShelf merged 1 commit intomainfrom
notashelf/push-mlpkxxyktqzn
Jan 28, 2026
Merged

watt: implement single-instance lock mechanism for watt daemon#47
NotAShelf merged 1 commit intomainfrom
notashelf/push-mlpkxxyktqzn

Conversation

@NotAShelf
Copy link
Owner

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::lock module that manages a PID file lock, and a new --force flag has been added for when this behaviour is explicitly desired.

Change-Id: Ideaf221f690c7bc694ca1f171385bfde6a6a6964

@NotAShelf NotAShelf force-pushed the notashelf/push-mlpkxxyktqzn branch from fda9b6e to f9e0c0c Compare January 28, 2026 09:33
Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: Ideaf221f690c7bc694ca1f171385bfde6a6a6964
@NotAShelf NotAShelf force-pushed the notashelf/push-mlpkxxyktqzn branch from f9e0c0c to 54a6879 Compare January 28, 2026 10:24
@NotAShelf NotAShelf merged commit f459c8d into main Jan 28, 2026
2 checks passed
@NotAShelf NotAShelf deleted the notashelf/push-mlpkxxyktqzn branch January 28, 2026 10:54
Copy link
Collaborator

@RGBCube RGBCube left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")

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.

2 participants