From 3c62fabfc3c8676272e27b36a671b5a88d290312 Mon Sep 17 00:00:00 2001 From: Anatol Belski Date: Thu, 5 Mar 2026 23:43:57 +0100 Subject: [PATCH] vmm: Collapse nested if into match arm guards Do the necessary replacements to satisfy clippy::collapsible_match. Signed-off-by: Anatol Belski --- vmm/src/lib.rs | 1 + vmm/src/serial_manager.rs | 49 ++++++++++++++++++++------------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index 9ffd7fc0b..5c75a2db0 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -735,6 +735,7 @@ impl Vmm { for signal in signals.forever() { match signal { + #[allow(clippy::collapsible_match)] SIGTERM | SIGINT => { if exit_evt.write(1).is_err() { // Resetting the terminal is usually done as the VMM exits diff --git a/vmm/src/serial_manager.rs b/vmm/src/serial_manager.rs index 5f8de1874..8a0d391d6 100644 --- a/vmm/src/serial_manager.rs +++ b/vmm/src/serial_manager.rs @@ -132,33 +132,34 @@ impl SerialManager { let in_fd = match output { ConsoleOutput::Pty(ref fd) => fd.as_raw_fd(), - ConsoleOutput::Tty(_) => { + ConsoleOutput::Tty(_) // If running on an interactive TTY then accept input // SAFETY: trivially safe - if unsafe { libc::isatty(libc::STDIN_FILENO) == 1 } { - // SAFETY: STDIN_FILENO is a valid fd - let fd = unsafe { libc::dup(libc::STDIN_FILENO) }; - if fd == -1 { - return Err(Error::DupFd(std::io::Error::last_os_error())); - } - // SAFETY: fd is valid and owned by us - let stdin_clone = unsafe { File::from_raw_fd(fd) }; - // SAFETY: FFI calls with correct arguments - let ret = unsafe { - let mut flags = libc::fcntl(stdin_clone.as_raw_fd(), libc::F_GETFL); - flags |= libc::O_NONBLOCK; - libc::fcntl(stdin_clone.as_raw_fd(), libc::F_SETFL, flags) - }; - - if ret < 0 { - return Err(Error::SetNonBlocking(std::io::Error::last_os_error())); - } - - output = ConsoleOutput::Tty(Arc::new(stdin_clone)); - fd - } else { - return Ok(None); + if unsafe { libc::isatty(libc::STDIN_FILENO) == 1 } => + { + // SAFETY: STDIN_FILENO is a valid fd + let fd = unsafe { libc::dup(libc::STDIN_FILENO) }; + if fd == -1 { + return Err(Error::DupFd(std::io::Error::last_os_error())); } + // SAFETY: fd is valid and owned by us + let stdin_clone = unsafe { File::from_raw_fd(fd) }; + // SAFETY: FFI calls with correct arguments + let ret = unsafe { + let mut flags = libc::fcntl(stdin_clone.as_raw_fd(), libc::F_GETFL); + flags |= libc::O_NONBLOCK; + libc::fcntl(stdin_clone.as_raw_fd(), libc::F_SETFL, flags) + }; + + if ret < 0 { + return Err(Error::SetNonBlocking(std::io::Error::last_os_error())); + } + + output = ConsoleOutput::Tty(Arc::new(stdin_clone)); + fd + } + ConsoleOutput::Tty(_) => { + return Ok(None); } ConsoleOutput::Socket(ref fd) => { if let Some(path_in_socket) = socket {