Fix clippy warnings and format code

- Fix redundant closure warning in api_server.rs
- Add backticks to login_tty in documentation comments
- All clippy warnings resolved
This commit is contained in:
Peter Steinberger 2025-06-18 14:16:43 +02:00
parent f0658bccd0
commit 5f067c7a80
2 changed files with 14 additions and 10 deletions

View file

@ -1041,13 +1041,14 @@ fn handle_session_kill(control_path: &Path, path: &str) -> Response<String> {
// Wait up to 3 seconds for the process to actually die
let session_path = control_path.join(&session_id);
let session_json_path = session_path.join("session.json");
let mut process_died = false;
if let Ok(content) = std::fs::read_to_string(&session_json_path) {
if let Ok(session_info) = serde_json::from_str::<serde_json::Value>(&content) {
if let Some(pid) = session_info.get("pid").and_then(|p| p.as_u64()) {
if let Some(pid) = session_info.get("pid").and_then(serde_json::Value::as_u64) {
// Wait for the process to actually die
for _ in 0..30 { // 30 * 100ms = 3 seconds max
for _ in 0..30 {
// 30 * 100ms = 3 seconds max
if !sessions::is_pid_alive(pid as u32) {
process_died = true;
break;
@ -1057,7 +1058,7 @@ fn handle_session_kill(control_path: &Path, path: &str) -> Response<String> {
}
}
}
// Update session status to exited after confirming kill
if let Ok(content) = std::fs::read_to_string(&session_json_path) {
if let Ok(mut session_info) = serde_json::from_str::<serde_json::Value>(&content) {
@ -1068,13 +1069,16 @@ fn handle_session_kill(control_path: &Path, path: &str) -> Response<String> {
}
}
}
if process_died {
(StatusCode::OK, "Session killed")
} else {
(StatusCode::OK, "Session kill signal sent (process may still be terminating)")
(
StatusCode::OK,
"Session kill signal sent (process may still be terminating)",
)
}
},
}
Err(e) => {
let response = ApiResponse {
success: None,

View file

@ -43,8 +43,8 @@ use tempfile::NamedTempFile;
pub const DEFAULT_TERM: &str = "xterm-256color";
/// Cross-platform implementation of login_tty
/// On systems with login_tty, use it directly. Otherwise, implement manually.
/// Cross-platform implementation of `login_tty`
/// On systems with `login_tty`, use it directly. Otherwise, implement manually.
#[cfg(any(
target_os = "macos",
target_os = "freebsd",
@ -78,7 +78,7 @@ unsafe fn login_tty_compat(fd: i32) -> Result<(), Error> {
let tiocsctty = TIOCSCTTY;
#[cfg(not(target_os = "linux"))]
let tiocsctty = libc::TIOCSCTTY;
if libc::ioctl(fd, tiocsctty.try_into().unwrap_or(0x540E), 0) == -1 {
// Try without forcing
if libc::ioctl(fd, tiocsctty.try_into().unwrap_or(0x540E), 1) == -1 {