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 <dtor@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/939865
Reviewed-by: Zach Reizner <zachr@chromium.org>
This commit is contained in:
Dmitry Torokhov 2018-02-27 10:26:34 -08:00 committed by chrome-bot
parent cda18d757b
commit 5ba068f9a4

View file

@ -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)?;