Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Document Info module #136

Merged
merged 2 commits into from
Jul 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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