From 6b26ae20a15ef7e3cf7f22d64c99287d20726c4f Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 19 Oct 2021 10:34:47 -0400 Subject: [PATCH] On startup, try to lock the state file, and log whether we succeed. Previously we'd try to grab the lock the first time we wrote to the file. --- crates/tor-client/src/client.rs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/crates/tor-client/src/client.rs b/crates/tor-client/src/client.rs index 1ca92e4cf..816baf52a 100644 --- a/crates/tor-client/src/client.rs +++ b/crates/tor-client/src/client.rs @@ -8,6 +8,7 @@ use crate::address::IntoTorAddr; use crate::config::ClientConfig; use tor_circmgr::{CircMgrConfig, IsolationToken, TargetPort}; use tor_dirmgr::{DirEvent, DirMgrConfig}; +use tor_persist::{FsStateMgr, StateMgr}; use tor_proto::circuit::{ClientCirc, IpVersionPreference}; use tor_proto::stream::DataStream; use tor_rtcompat::{Runtime, SleepProviderExt}; @@ -149,7 +150,14 @@ impl TorClient { circ_cfg: CircMgrConfig, client_cfg: ClientConfig, ) -> Result> { - let statemgr = tor_persist::FsStateMgr::from_path(state_cfg)?; + let statemgr = FsStateMgr::from_path(state_cfg)?; + if statemgr.try_lock()? { + debug!("It appears we have the lock on our state files."); + } else { + info!( + "Another process has the lock on our state files. We'll proceed in read-only mode." + ); + } let chanmgr = Arc::new(tor_chanmgr::ChanMgr::new(runtime.clone())); let circmgr = tor_circmgr::CircMgr::new(circ_cfg, statemgr, &runtime, Arc::clone(&chanmgr))?;