From da206507de2bc04c577030bc6a258130e03881bc Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 12 Apr 2020 04:58:58 -0400 Subject: avoid holding the state mutex for as long in particular, don't hold it over pinentry calls, since those can take arbitrarily long --- src/bin/rbw-agent/actions.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/bin/rbw-agent/actions.rs b/src/bin/rbw-agent/actions.rs index 4662164..2cb012c 100644 --- a/src/bin/rbw-agent/actions.rs +++ b/src/bin/rbw-agent/actions.rs @@ -5,7 +5,6 @@ pub async fn login( state: std::sync::Arc>, tty: Option<&str>, ) -> anyhow::Result<()> { - let mut state = state.write().await; let email = config_email() .await .context("failed to read email from config")?; @@ -39,7 +38,7 @@ pub async fn login( .await .context("failed to log in to bitwarden instance")?; - state.priv_key = Some(keys); + state.write().await.priv_key = Some(keys); db.access_token = Some(access_token); db.refresh_token = Some(refresh_token); @@ -62,9 +61,7 @@ pub async fn unlock( state: std::sync::Arc>, tty: Option<&str>, ) -> anyhow::Result<()> { - let mut state = state.write().await; - - if state.needs_unlock() { + if state.read().await.needs_unlock() { let email = config_email() .await .context("failed to read email from config")?; @@ -103,7 +100,7 @@ pub async fn unlock( .await .context("failed to unlock database")?; - state.priv_key = Some(keys); + state.write().await.priv_key = Some(keys); } respond_ack(sock).await?; @@ -115,9 +112,7 @@ pub async fn lock( sock: &mut crate::sock::Sock, state: std::sync::Arc>, ) -> anyhow::Result<()> { - let mut state = state.write().await; - - state.priv_key = None; + state.write().await.clear(); respond_ack(sock).await?; -- cgit v1.2.3-54-g00ecf