-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #854 from sylvestre/kernel
Add a check of the kernel version
- Loading branch information
Showing
4 changed files
with
43 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use std::ffi::CStr; | ||
|
||
use std::mem::zeroed; | ||
|
||
use crate::common::Error; | ||
|
||
pub fn kernel_check(major: u32, minor: u32) -> Result<(), Error> { | ||
let mut utsname: libc::utsname = unsafe { zeroed() }; | ||
|
||
if unsafe { libc::uname(&mut utsname) } != 0 { | ||
// Could not get the kernel version. Try to run anyway | ||
return Ok(()); | ||
} | ||
|
||
let release = unsafe { CStr::from_ptr(utsname.release.as_ptr()) } | ||
.to_string_lossy() | ||
.into_owned(); | ||
|
||
let version_parts: Vec<&str> = release.split('.').collect(); | ||
|
||
if version_parts.len() < 2 { | ||
// Could not get the kernel version. Try to run anyway | ||
return Ok(()); | ||
} | ||
|
||
// Parse the major and minor version numbers | ||
if let (Ok(major_version), Ok(minor_version)) = ( | ||
version_parts[0].parse::<u32>(), | ||
version_parts[1].parse::<u32>(), | ||
) { | ||
if major_version > major || (major_version == major && minor_version >= minor) { | ||
return Ok(()); | ||
} | ||
} | ||
|
||
Err(Error::KernelCheck) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters