Skip to content

Commit

Permalink
Merge pull request #136 from YJDoc2/main
Browse files Browse the repository at this point in the history
Document Info module
  • Loading branch information
utam0k authored Jul 13, 2021
2 parents 0c40908 + e5119a0 commit 886e9e8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions docs/doc-draft.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,13 @@ This also provides implementation for Linux syscalls for the trait.

## Capabilities

This has functions related to set and reset specific capabilities, as well as to drop extra privileges

- [Simple explanation of capabilities](https://blog.container-solutions.com/linux-capabilities-in-practice)
- [man page for capabilities](https://man7.org/linux/man-pages/man7/capabilities.7.html)

## Info

This is primarily for printing info about system running youki, such as OS release, architecture, cpu info, cgroups info etc. , as this info can be helpful when reporting issues.

- [about /etc/os-release](https://www.freedesktop.org/software/systemd/man/os-release.html)
8 changes: 8 additions & 0 deletions src/info.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//! Contains functions related to printing information about system running Youki
use std::{fs, path::Path};

use anyhow::Result;
Expand All @@ -21,17 +22,20 @@ impl Info {
}
}

/// print Version of Youki
pub fn print_youki() {
println!("{:<18}{}", "Version", env!("CARGO_PKG_VERSION"));
}

/// Print Kernel Release, Version and Architecture
pub fn print_kernel() {
let uname = nix::sys::utsname::uname();
println!("{:<18}{}", "Kernel-Release", uname.release());
println!("{:<18}{}", "Kernel-Version", uname.version());
println!("{:<18}{}", "Architecture", uname.machine());
}

/// Prints OS Distribution information
// see https://www.freedesktop.org/software/systemd/man/os-release.html
pub fn print_os() {
if let Some(os) = try_read_os_from("/etc/os-release") {
Expand All @@ -41,6 +45,7 @@ pub fn print_os() {
}
}

/// Helper function to read the OS Distribution info
fn try_read_os_from<P: AsRef<Path>>(path: P) -> Option<String> {
let os_release = path.as_ref();
if !os_release.exists() {
Expand Down Expand Up @@ -69,6 +74,7 @@ fn try_read_os_from<P: AsRef<Path>>(path: P) -> Option<String> {
None
}

/// Helper function to find keyword values in OS info string
fn find_parameter<'a>(content: &'a str, param_name: &str) -> Option<&'a str> {
let param_value = content
.lines()
Expand All @@ -82,6 +88,7 @@ fn find_parameter<'a>(content: &'a str, param_name: &str) -> Option<&'a str> {
None
}

/// Print Hardware information of system
pub fn print_hardware() {
if let Ok(cpu_info) = CpuInfo::new() {
println!("{:<18}{}", "Cores", cpu_info.num_cores());
Expand All @@ -96,6 +103,7 @@ pub fn print_hardware() {
}
}

/// Print cgroups info of system
pub fn print_cgroups() {
if let Ok(cgroup_fs) = cgroups::common::get_supported_cgroup_fs() {
let cgroup_fs: Vec<String> = cgroup_fs.into_iter().map(|c| c.to_string()).collect();
Expand Down

0 comments on commit 886e9e8

Please sign in to comment.