From: Ian Jackson Date: Tue, 1 Jun 2021 00:55:46 +0000 (+0100) Subject: cmdlistener: Display account in log messages X-Git-Tag: otter-0.7.0~162 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=4cfefc22972f5e20d868b9176e135df693da4e0c;p=otter.git cmdlistener: Display account in log messages Signed-off-by: Ian Jackson --- diff --git a/daemon/cmdlistener.rs b/daemon/cmdlistener.rs index 6dc11dd4..7af65d2f 100644 --- a/daemon/cmdlistener.rs +++ b/daemon/cmdlistener.rs @@ -44,11 +44,21 @@ struct CommandStream<'d> { } struct CommandStreamData<'d> { - desc: &'d str, + conn_desc: &'d str, account: Option, authstate: AuthState, } +impl Display for CommandStreamData<'_> { + #[throws(fmt::Error)] + fn fmt(&self, f: &mut Formatter) { + write!(f, "command conn {}", self.conn_desc)?; + if let Some(account) = &self.account { + write!(f, " {} ", &account.cooked)?; + } + } +} + type Euid = Result; #[derive(Debug)] @@ -472,13 +482,11 @@ fn execute_and_respond(cs: &mut CommandStreamData, cmd: MgmtCommand, let resp = match resp { Ok(resp) => { - info!("command connection {}: executed {}", - &cs.desc, cmd_s); + info!("{}: executed {}", &cs, cmd_s); resp } Err(error) => { - info!("command connection {}: error {:?} from {}", - &cs.desc, &error, cmd_s); + info!("{}: error {:?} from {}", &cs, &error, cmd_s); MgmtResponse::Error { error } } }; @@ -1455,7 +1463,7 @@ impl CommandStream<'_> { }, Err(EOF) => break, Err(IO(e)) if e.kind() == ErrorKind::TimedOut => { - info!("{}: idle timeout reading command stream", &self.d.desc); + info!("{}: idle timeout reading command stream", &self.d); self.write_error(ME::IdleTimeout)?; break; } @@ -1539,7 +1547,7 @@ impl CommandListener { let chan = MgmtChannel::new_timed(conn)?; let d = CommandStreamData { - account: None, desc: &desc, + account: None, conn_desc: &desc, authstate: AuthState::None { euid: euid.map(Uid::from_raw) }, }; let cs = CommandStream { chan, d }; @@ -1584,13 +1592,13 @@ impl CommandStreamData<'_> { return Authorisation::promise_for(&client_euid); } throw!(anyhow!("{}: euid mismatch: client={:?} server={:?} wanted={:?}{}", - &self.desc, client_euid, server_uid, wanted, + &self, client_euid, server_uid, wanted, xinfo.unwrap_or(""))); } fn map_auth_err(&self, ae: AuthorisationError) -> MgmtError { - warn!("command connection {}: authorisation error: {}", - self.desc, ae.0); + warn!("{}: authorisation error: {}", + self, ae.0); MgmtError::AuthorisationError } }