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.
This commit is contained in:
Nick Mathewson 2021-10-19 10:34:47 -04:00
parent 36353aacd8
commit 6b26ae20a1
1 changed files with 9 additions and 1 deletions

View File

@ -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<R: Runtime> TorClient<R> {
circ_cfg: CircMgrConfig,
client_cfg: ClientConfig,
) -> Result<TorClient<R>> {
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))?;