mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: Fix various clippy issues
Assisted-by: Claude:Opus-4.7 Signed-off-by: Bo Chen <bchen@crusoe.ai>
This commit is contained in:
@@ -484,7 +484,7 @@ impl run_blocking::BlockingEventLoop for GdbEventLoop {
|
||||
}
|
||||
}
|
||||
|
||||
if conn.peek().map(|b| b.is_some()).unwrap_or(true) {
|
||||
if conn.peek().map_or(true, |b| b.is_some()) {
|
||||
let byte = conn
|
||||
.read()
|
||||
.map_err(run_blocking::WaitForStopReasonError::Connection)?;
|
||||
|
||||
@@ -433,7 +433,7 @@ pub fn load_igvm(
|
||||
let mut now = Instant::now();
|
||||
|
||||
// Sort the gpas to group them by the page type
|
||||
gpas.sort_by(|a, b| a.gpa.cmp(&b.gpa));
|
||||
gpas.sort_by_key(|a| a.gpa);
|
||||
|
||||
let gpas_grouped = gpas
|
||||
.iter()
|
||||
|
||||
@@ -735,22 +735,20 @@ impl Vmm {
|
||||
|
||||
for signal in signals.forever() {
|
||||
match signal {
|
||||
SIGTERM | SIGINT => {
|
||||
if exit_evt.write(1).is_err() {
|
||||
// Resetting the terminal is usually done as the VMM exits
|
||||
if let Ok(lock) = original_termios_opt.lock() {
|
||||
if let Some(termios) = *lock {
|
||||
// SAFETY: FFI call
|
||||
let _ = unsafe {
|
||||
tcsetattr(stdout().lock().as_raw_fd(), TCSANOW, &termios)
|
||||
};
|
||||
}
|
||||
} else {
|
||||
warn!("Failed to lock original termios");
|
||||
SIGTERM | SIGINT if exit_evt.write(1).is_err() => {
|
||||
// Resetting the terminal is usually done as the VMM exits
|
||||
if let Ok(lock) = original_termios_opt.lock() {
|
||||
if let Some(termios) = *lock {
|
||||
// SAFETY: FFI call
|
||||
let _ = unsafe {
|
||||
tcsetattr(stdout().lock().as_raw_fd(), TCSANOW, &termios)
|
||||
};
|
||||
}
|
||||
|
||||
std::process::exit(1);
|
||||
} else {
|
||||
warn!("Failed to lock original termios");
|
||||
}
|
||||
|
||||
std::process::exit(1);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -132,33 +132,29 @@ impl SerialManager {
|
||||
|
||||
let in_fd = match output {
|
||||
ConsoleOutput::Pty(ref fd) => fd.as_raw_fd(),
|
||||
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 running on an interactive TTY then accept input.
|
||||
// SAFETY: trivially safe
|
||||
ConsoleOutput::Tty(_) 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::Socket(ref fd) => {
|
||||
if let Some(path_in_socket) = socket {
|
||||
|
||||
Reference in New Issue
Block a user