Skip to content

Commit

Permalink
Merge pull request #1514 from mulkieran/master-trylock
Browse files Browse the repository at this point in the history
Use Result functions instead of match primitives
  • Loading branch information
mulkieran authored Oct 4, 2019
2 parents 702fc5e + 7eeb061 commit 9c3f61e
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/bin/stratisd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,17 @@ fn initialize_log(debug: bool) -> buff_log::Handle<env_logger::Logger> {
/// 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<File> {
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())?;
Expand Down

0 comments on commit 9c3f61e

Please sign in to comment.