Skip to content

Commit

Permalink
review feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
belohnung committed Jun 14, 2024
1 parent ef08eb3 commit 1a7c2b7
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions aya/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,11 @@ impl KernelVersion {
(u32::from(major) << 16) + (u32::from(minor) << 8) + u32::from(patch)
}

// This (L92-L133) is ported from https://github.com/torvalds/linux/blob/3f01e9f/tools/lib/bpf/libbpf_probes.c#L21-L101.
// These (get_ubuntu_kernel_version, parse_ubuntu_kernel_version, read_ubuntu_kernel_version_file)
// are ported from https://github.com/torvalds/linux/blob/3f01e9f/tools/lib/bpf/libbpf_probes.c#L21-L101.
fn get_ubuntu_kernel_version() -> Result<Option<Self>, CurrentKernelVersionError> {
if let Some(content) = Self::read_ubuntu_kernel_version_file()? {
if let Some(v) = Self::parse_ubuntu_kernel_version(&content).ok().flatten() {
return Ok(Some(v));
}
return Self::parse_ubuntu_kernel_version(&content);
}
Ok(None)
}
Expand Down Expand Up @@ -149,7 +148,7 @@ impl KernelVersion {
}

fn get_kernel_version() -> Result<Self, CurrentKernelVersionError> {
if let Some(v) = Self::get_ubuntu_kernel_version()? {
if let Ok(Some(v)) = Self::get_ubuntu_kernel_version() {
return Ok(v);
}

Expand Down Expand Up @@ -403,12 +402,12 @@ mod tests {
// cat /proc/version_signature on Proxmox VE 8.1.4
assert_matches!(
KernelVersion::parse_ubuntu_kernel_version(""),
Err(CurrentKernelVersionError::ParseError(s)) => { s.is_empty() }
Err(CurrentKernelVersionError::ParseError(s)) if s.is_empty()
);
// cat /proc/version_signature on Ubuntu 22.04
assert_matches!(KernelVersion::parse_ubuntu_kernel_version(
"Ubuntu 5.15.0-82.91-generic 5.15.111"
), Ok(Some(kernel_version))=> {
), Ok(Some(kernel_version)) => {
assert_eq!(kernel_version, KernelVersion::new(5, 15, 111))
});
// WSL.
Expand Down

0 comments on commit 1a7c2b7

Please sign in to comment.