Skip to content

Commit

Permalink
Merge pull request #70 from PeterYordanov/added-doc-comments-modules
Browse files Browse the repository at this point in the history
Added doc comments modules
  • Loading branch information
utam0k authored Jun 8, 2021
2 parents f9479f8 + 03ce61c commit d72ffa5
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 17 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# youki: A container runtime in Rust

<img src="docs/youki.png" width="230" height="230">
<p align="center">
<img src="docs/youki.png" width="230" height="230">
</p>

youki is an implementation of [runtime-spec](https://github.com/opencontainers/runtime-spec) in Rust, referring to [runc](https://github.com/opencontainers/runc).

Expand Down
4 changes: 4 additions & 0 deletions src/cgroups/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! Control groups provide a way of controlling groups of processes.
//! Examples: controlling resource limits, execution priority, measuring resource usage,
//! freezing, checkpointing and restarting groups of processes.
pub mod common;
mod test;
pub mod v1;
Expand Down
2 changes: 2 additions & 0 deletions src/command/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Contains a wrapper of syscalls for unit tests
#[allow(clippy::module_inception)]
mod command;
pub mod linux;
Expand Down
6 changes: 5 additions & 1 deletion src/cond.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Conditional variable that performs busy waiting on lock
use std::os::unix::io::RawFd;

use anyhow::Result;
Expand All @@ -11,7 +13,8 @@ pub struct Cond {

impl Cond {
pub fn new() -> Result<Cond> {
let (rfd, wfd) = pipe2(OFlag::O_CLOEXEC)?;
// Sets as close-on-execution
let (rfd, wfd) = pipe2(OFlag::O_CLOEXEC)?;
Ok(Cond { rfd, wfd })
}

Expand All @@ -22,6 +25,7 @@ impl Cond {
close(self.rfd)?;
Ok(())
}

pub fn notify(&self) -> Result<()> {
close(self.rfd)?;
close(self.wfd)?;
Expand Down
2 changes: 2 additions & 0 deletions src/container/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Container management
#[allow(clippy::module_inception)]
mod container;
mod state;
Expand Down
2 changes: 1 addition & 1 deletion src/create.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! This handles the creation of a new container
//! Handles the creation of a new container
use std::fs;
use std::path::{Path, PathBuf};
use std::process;
Expand Down
6 changes: 4 additions & 2 deletions src/logger.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Default Youki Logger
use std::env;
use std::io::{stderr, Write};
use std::path::PathBuf;
Expand Down Expand Up @@ -31,7 +33,7 @@ pub fn init(log_file: Option<PathBuf>) -> Result<()> {
.write(true)
.truncate(false)
.open(log_file_path)
.expect("fail opening log file ")
.expect("failed opening log file ")
})
});
Ok(())
Expand Down Expand Up @@ -85,7 +87,7 @@ impl Log for YoukiLogger {
if let Some(mut log_file) = LOG_FILE.get().unwrap().as_ref() {
log_file.flush().expect("Failed to flush");
} else {
stderr().flush().expect("Faild to flush");
stderr().flush().expect("Failed to flush");
}
}
}
8 changes: 4 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ fn main() -> Result<()> {
// root directory given in commandline options
let container_root = root_path.join(&kill.container_id);
if !container_root.exists() {
bail!("{} doesn't exists.", kill.container_id)
bail!("{} doesn't exist.", kill.container_id)
}

// load container state from json file, and check status of the container
Expand All @@ -105,7 +105,7 @@ fn main() -> Result<()> {
std::process::exit(0)
} else {
bail!(
"{} counld not be killed because it was {:?}",
"{} could not be killed because it was {:?}",
container.id(),
container.status()
)
Expand All @@ -117,7 +117,7 @@ fn main() -> Result<()> {
// root directory given in commandline options
let container_root = root_path.join(&delete.container_id);
if !container_root.exists() {
bail!("{} doesn't exists.", delete.container_id)
bail!("{} doesn't exist.", delete.container_id)
}
// load container state from json file, and check status of the container
// it might be possible that delete is invoked on a running container.
Expand Down Expand Up @@ -150,7 +150,7 @@ fn main() -> Result<()> {
std::process::exit(0)
} else {
bail!(
"{} counld not be deleted because it was {:?}",
"{} could not be deleted because it was {:?}",
container.id(),
container.status()
)
Expand Down
9 changes: 9 additions & 0 deletions src/namespaces.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
//! Namespaces provide isolation of resources for processes at a kernel level.
//! The namespaces are: Mount (filesystem),
//! Process (processes in a namespace have two PIDs, one for the global PID,
//! which is used by the main system and the second one is for the child within the process tree),
//! Interprocess Communication (Control or communication between processes),
//! Network (which network devices can be seen by the processes in the namespace), User (User configs),
//! UTS (hostname and domain information, processes will think they're running on servers with different names),
//! Cgroup (Resource limits, execution priority etc.)
use anyhow::Result;
use nix::{
fcntl,
Expand Down
2 changes: 1 addition & 1 deletion src/process/message.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/// Used as wrapper for messages to be sent between child and parent processes
/// Used as a wrapper for messages to be sent between child and parent processes
#[derive(Debug)]
pub enum Message {
ChildReady = 0x00,
Expand Down
6 changes: 3 additions & 3 deletions src/process/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! This provides a thin wrapper around fork syscall,
//! with enums and functions specific to youki implemented.
//! Provides a thin wrapper around fork syscall,
//! with enums and functions specific to youki implemented
use std::time::Duration;

Expand All @@ -13,7 +13,7 @@ mod parent;
pub use init::InitProcess;

/// Used to describe type of process after fork.
/// Parent and child processes mean same things as in normal fork call
/// Parent and child processes mean the same thing as in a normal fork call
/// InitProcess is specifically used to indicate the process which will run the command of container
pub enum Process {
Parent(parent::ParentProcess),
Expand Down
3 changes: 3 additions & 0 deletions src/rootfs.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! During kernel initialization, a minimal replica of the ramfs filesystem is loaded, called rootfs.
//! Most systems mount another filesystem over it
use std::fs::OpenOptions;
use std::fs::{canonicalize, create_dir_all, remove_file};
use std::os::unix::fs::symlink;
Expand Down
2 changes: 2 additions & 0 deletions src/signal.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Returns *nix signal enum value from passed string
use anyhow::{bail, Result};
use nix::sys::signal::Signal;

Expand Down
6 changes: 4 additions & 2 deletions src/start.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Starts execution of the container
use std::path::PathBuf;

use anyhow::{bail, Result};
Expand All @@ -16,12 +18,12 @@ impl Start {
pub fn exec(&self, root_path: PathBuf) -> Result<()> {
let container_root = root_path.join(&self.container_id);
if !container_root.exists() {
bail!("{} doesn't exists.", self.container_id)
bail!("{} doesn't exist.", self.container_id)
}
let container = Container::load(container_root)?.refresh_status()?;
if !container.can_start() {
let err_msg = format!(
"{} counld not be started because it was {:?}",
"{} could not be started because it was {:?}",
container.id(),
container.status()
);
Expand Down
2 changes: 2 additions & 0 deletions src/tty.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! tty (teletype) for user-system interaction
use std::os::unix::fs::symlink;
use std::os::unix::io::AsRawFd;
use std::path::Path;
Expand Down
6 changes: 4 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Utility functionality
use std::ffi::CString;
use std::fs;
use std::path::{Path, PathBuf};
Expand All @@ -14,7 +16,7 @@ pub trait PathBufExt {
impl PathBufExt for PathBuf {
fn as_in_container(&self) -> Result<PathBuf> {
if self.is_relative() {
bail!("Relative path cannnot be converted to the path in the container.")
bail!("Relative path cannot be converted to the path in the container.")
} else {
let path_string = self.to_string_lossy().into_owned();
Ok(PathBuf::from(path_string[1..].to_string()))
Expand All @@ -24,7 +26,7 @@ impl PathBufExt for PathBuf {
fn join_absolute_path(&self, p: &Path) -> Result<PathBuf> {
if !p.is_absolute() && !p.as_os_str().is_empty() {
bail!(
"connnot join {:?} because it is not the absolute path.",
"cannot join {:?} because it is not the absolute path.",
p.display()
)
}
Expand Down

0 comments on commit d72ffa5

Please sign in to comment.