Skip to content

Commit

Permalink
Add optional tracing support to Session drop impl (#164)
Browse files Browse the repository at this point in the history
* Add optional dependency tracing

Signed-off-by: Jiahao XU <[email protected]>

* Add logging for <process_mux_impl::Session as Drop>::drop

Signed-off-by: Jiahao XU <[email protected]>

* Add tracing to <native_mux_impl::Session as Drop>::drop

Signed-off-by: Jiahao XU <[email protected]>

* Unify drop logging msg

Signed-off-by: Jiahao XU <[email protected]>

---------

Signed-off-by: Jiahao XU <[email protected]>
  • Loading branch information
NobodyXu authored Sep 8, 2024
1 parent e977789 commit 1c25749
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ openssh-mux-client = { version = "0.17.0", optional = true }

libc = "0.2.137"

tracing = { version = "0.1", optional = true }

[dev-dependencies]
regex = "1"
tokio = { version = "1", features = [ "full" ] }
Expand Down
6 changes: 5 additions & 1 deletion src/native_mux_impl/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ impl Drop for Session {
None => return,
};

let _ = shutdown_mux_master(&self.ctl);
let _res = shutdown_mux_master(&self.ctl);
#[cfg(feature = "tracing")]
if let Err(err) = _res {
tracing::error!("Closing ssh session failed: {}", err);
}
}
}
6 changes: 5 additions & 1 deletion src/process_impl/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,14 @@ impl Drop for Session {
None => return,
};

let _ = self
let _res = self
.new_std_cmd(&["-O", "exit"])
.stdout(Stdio::null())
.stderr(Stdio::null())
.status();
#[cfg(feature = "tracing")]
if let Err(err) = _res {
tracing::error!("Closing ssh session failed: {}", err);
}
}
}

0 comments on commit 1c25749

Please sign in to comment.