sys_metrics/host/sys/unix/kernel_version.rs
1use crate::host;
2use crate::to_str;
3
4#[cfg(target_os = "linux")]
5use libc::utsname;
6use std::io::Error;
7
8/// Get the kernel version.
9pub fn get_kernel_version() -> Result<String, Error> {
10 let x = host::get_uname()?;
11 Ok(to_str(x.release.as_ptr()).to_owned())
12}
13
14/// Inlined function to get the kernel version from a reference of uname.
15#[cfg(target_os = "linux")]
16#[inline]
17pub(crate) fn get_kernel_version_from_uname(uts: &utsname) -> String {
18 to_str(uts.release.as_ptr()).to_owned()
19}