Skip to content

Commit a8412d2

Browse files
committed
watt: use var_os; reduce allocation for lock err
Signed-off-by: NotAShelf <raf@notashelf.dev> Change-Id: I253907fd65829fa5ca3a3b5f5041afc06a6a6964
1 parent d528086 commit a8412d2

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

watt/lib.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,14 @@ pub fn main() -> anyhow::Result<()> {
4848

4949
log::info!("starting watt daemon");
5050

51-
let lock_path = env::var("XDG_RUNTIME_DIR")
52-
.map(|dir| PathBuf::from(dir).join("watt.pid"))
53-
.unwrap_or_else(|_| PathBuf::from("/run/watt.pid"));
54-
55-
let _lock = lock::LockFile::acquire(&lock_path, cli.force).context(
56-
format!("failed to acquire pid lock at {}", lock_path.display()),
57-
)?;
51+
let lock_path = env::var_os("XDG_RUNTIME_DIR")
52+
.map_or_else(|| PathBuf::from("/run"), PathBuf::from)
53+
.join("watt.pid");
54+
55+
let _lock =
56+
lock::LockFile::acquire(&lock_path, cli.force).with_context(|| {
57+
format!("failed to acquire pid lock at {}", lock_path.display())
58+
})?;
5859

5960
system::run_daemon(config)
6061
}

0 commit comments

Comments
 (0)