Ignore ENOBUFS when writing to VM's socket (#18)

* Ignore ENOBUFS when writing to VM's socket

* Hint the into() target type to the compiler to fix the build error

* Fix Clippy warnings
This commit is contained in:
Nikolay Edigaryev 2022-12-15 00:15:19 +04:00 committed by GitHub
parent 4ab3cd7e5c
commit 59cd9098e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 7 deletions

View File

@ -52,8 +52,14 @@ impl Poller {
self.poller
.wait(&mut self.events, Some(Duration::from_millis(100)))?;
let vm_readable = self.events.iter().any(|ev| ev.key == EventKey::VM.into());
let host_readable = self.events.iter().any(|ev| ev.key == EventKey::Host.into());
let vm_readable = self
.events
.iter()
.any(|ev| ev.key == Into::<usize>::into(EventKey::VM));
let host_readable = self
.events
.iter()
.any(|ev| ev.key == Into::<usize>::into(EventKey::Host));
Ok((vm_readable, host_readable))
}

View File

@ -16,10 +16,21 @@ impl Proxy {
self.snoop(frame);
}
self.vm
.write(frame.as_ref())
.map(|_| ())
.context("failed to write to the VM")
match self.vm.write(frame.as_ref()) {
Ok(_) => Ok(()),
Err(err) => {
if let Some(libc::ENOBUFS) = err.raw_os_error() {
sentry::capture_message(
"No buffer space available in VM's socket",
sentry::Level::Warning,
);
return Ok(());
}
Err(err).context("failed to write to the VM")
}
}
}
fn allowed_from_host(&mut self, frame: &EthernetFrame<&[u8]>) -> Option<()> {

View File

@ -60,7 +60,7 @@ fn main() -> ExitCode {
// Enrich future events with Cirrus CI-specific tags
if let Ok(tags) = env::var("CIRRUS_SENTRY_TAGS") {
sentry::configure_scope(|scope| {
for (key, value) in tags.split(",").map(|tag| tag.split_once("=")).flatten() {
for (key, value) in tags.split(',').filter_map(|tag| tag.split_once('=')) {
scope.set_tag(key, value);
}
});