From 7eeb061c8cdf7059bd4710edb66633952ebe5e07 Mon Sep 17 00:00:00 2001 From: mulhern Date: Tue, 7 May 2019 11:17:34 -0400 Subject: [PATCH] Tidy up error distinction when unable to open pidfile Using map_err is more direct and more Rustic. Signed-off-by: mulhern --- src/bin/stratisd.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/bin/stratisd.rs b/src/bin/stratisd.rs index b433b93112..95c7224cb3 100644 --- a/src/bin/stratisd.rs +++ b/src/bin/stratisd.rs @@ -105,20 +105,17 @@ fn initialize_log(debug: bool) -> buff_log::Handle { /// To ensure only one instance of stratisd runs at a time, acquire an /// exclusive lock. Return an error if lock attempt fails. fn trylock_pid_file() -> StratisResult { - let mut f = match OpenOptions::new() + let mut f = OpenOptions::new() .read(true) .write(true) .create(true) .open(STRATISD_PID_PATH) - { - Ok(f) => f, - Err(e) => { - return Err(StratisError::Error(format!( + .map_err(|err| { + StratisError::Error(format!( "Failed to create or open the stratisd PID file at {}: {}", - STRATISD_PID_PATH, e - ))); - } - }; + STRATISD_PID_PATH, err + )) + })?; match flock(f.as_raw_fd(), FlockArg::LockExclusiveNonblock) { Ok(_) => { f.write_all(format!("{}\n", getpid()).as_bytes())?;