aya-rs / aya

Aya is an eBPF library for the Rust programming language, built with a focus on developer experience and operability.
https://aya-rs.dev/book/
Apache License 2.0
3.18k stars 284 forks source link

Remove instances of KernelVersion::current().unwrap() #1024

Open alessandrod opened 1 month ago

alessandrod commented 1 month ago

In a bunch of places we do if KernelVersion::current().unwrap() >= KernelVersion::new(....) {

In theory, we should always know the kernel version so the unwrap is understandable. However it seems that distributions really like to mess with how the kernel version is reported and we've had this unwrap fail in more than one case (some version of ubuntu and recently proxmox).

In the cases where we have if version { ... } else { ... } we should handle the case where current() fails, log a warning, and probably do the else thing which is usually whatever is supported by older kernels.

pythops commented 1 month ago

I have started working on this one. What do you mean by log a warning ? would eprintln! with a message work or should we include tracing crate ?

alessandrod commented 1 month ago

I have started working on this one.

Awesome thanks!

What do you mean by log a warning ? would eprintln! with a message work or should we include tracing crate ?

We use the log crate, so you can

use log::warn;

warn!("some warning message");