From 5ba068f9a4d86a8f976aca3e3f70ed16a3e1d4d8 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Tue, 27 Feb 2018 10:26:34 -0800 Subject: [PATCH] crosvm_plugin: fix errno conversions The raw_os_error() and errno() return positive values (errno values are all positive), but the rest of crosvm plugin C API works with negative return codes, so we need to convert raw_os_error()/errno() into negatives as well. TEST=cargo test --features plugin; cargo test -p kvm BUG=None Change-Id: I8bd72c2e67cb227a638e5c9478cd2f781f0783d0 Signed-off-by: Dmitry Torokhov Reviewed-on: https://chromium-review.googlesource.com/939865 Reviewed-by: Zach Reizner --- crosvm_plugin/src/lib.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crosvm_plugin/src/lib.rs b/crosvm_plugin/src/lib.rs index bfb928734d..6f563413c3 100644 --- a/crosvm_plugin/src/lib.rs +++ b/crosvm_plugin/src/lib.rs @@ -90,7 +90,7 @@ pub struct crosvm_irq_route { fn proto_error_to_int(e: protobuf::ProtobufError) -> c_int { match e { - protobuf::ProtobufError::IoError(e) => e.raw_os_error().unwrap_or(-EINVAL), + protobuf::ProtobufError::IoError(e) => -e.raw_os_error().unwrap_or(EINVAL), _ => -EINVAL, } } @@ -165,14 +165,14 @@ impl crosvm { .map_err(proto_error_to_int)?; self.fd_messager .send(&self.socket, &[self.request_buffer.as_slice()], fds) - .map_err(|e| e.errno())?; + .map_err(|e| -e.errno())?; let mut datagram_files = Vec::new(); let msg_size = self.fd_messager .recv(&self.socket, &mut [&mut self.response_buffer], &mut datagram_files) - .map_err(|e| e.errno())?; + .map_err(|e| -e.errno())?; let response: MainResponse = parse_from_bytes(&self.response_buffer[..msg_size]) .map_err(proto_error_to_int)?; @@ -615,11 +615,11 @@ impl crosvm_vcpu { .map_err(proto_error_to_int)?; self.socket .send(self.request_buffer.as_slice()) - .map_err(|e| e.raw_os_error().unwrap_or(-EINVAL))?; + .map_err(|e| -e.raw_os_error().unwrap_or(EINVAL))?; let msg_size = self.socket .recv(&mut self.response_buffer) - .map_err(|e| e.raw_os_error().unwrap_or(-EINVAL))?; + .map_err(|e| -e.raw_os_error().unwrap_or(EINVAL))?; let response: VcpuResponse = parse_from_bytes(&self.response_buffer[..msg_size]) .map_err(proto_error_to_int)?;