-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: merging executables to save disk space (wip)
- Loading branch information
Showing
23 changed files
with
149 additions
and
254 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,36 +1,28 @@ | ||
//! The `lsmod` command allows to list loaded kernel modules. | ||
use crate::error; | ||
use std::fs::File; | ||
use std::io::BufRead; | ||
use std::io::BufReader; | ||
use std::process::exit; | ||
|
||
/// The path to the modules file. | ||
const MODULES_PATH: &str = "/proc/modules"; | ||
|
||
fn main() { | ||
let file = match File::open(MODULES_PATH) { | ||
Ok(f) => f, | ||
Err(e) => { | ||
eprintln!("lsmod: cannot open `{MODULES_PATH}`: {e}"); | ||
exit(1); | ||
} | ||
}; | ||
|
||
pub fn main() { | ||
let file = File::open(MODULES_PATH).unwrap_or_else(|e| { | ||
error("lsmod", format_args!("cannot open `{MODULES_PATH}`: {e}")); | ||
}); | ||
let reader = BufReader::new(file); | ||
|
||
println!("Name\tSize\tUsed by"); | ||
|
||
for line in reader.lines() { | ||
// TODO handle error | ||
let mut split = line.as_ref().unwrap().split(' '); | ||
|
||
let line = line.unwrap_or_else(|e| { | ||
error("lsmod", e); | ||
}); | ||
let mut split = line.split(' '); | ||
let name = split.next().unwrap(); | ||
let size = split.next().unwrap(); | ||
let use_count = split.next().unwrap(); | ||
let used_by_list = split.next().unwrap(); | ||
|
||
// TODO padding | ||
println!("{name}\t{size}\t{use_count}\t{used_by_list}"); | ||
println!("{name} {size} {use_count} {used_by_list}"); | ||
} | ||
} |
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,5 @@ | ||
//! Main of all commands that **require** the SUID flag. | ||
fn main() { | ||
// TODO | ||
} |
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,57 @@ | ||
//! Main of all commands that **do not require** the SUID flag. | ||
#![feature(option_get_or_insert_default)] | ||
|
||
mod dmesg; | ||
mod lsmod; | ||
mod mount; | ||
mod nologin; | ||
mod ps; | ||
|
||
use std::process::exit; | ||
use std::{env, fmt}; | ||
|
||
/// Writes an error to stderr, then exits. | ||
fn error<M: fmt::Display>(bin: &str, msg: M) -> ! { | ||
eprintln!("{bin}: error: {msg}"); | ||
exit(1); | ||
} | ||
|
||
fn main() { | ||
let mut args = env::args_os(); | ||
let bin = args | ||
.next() | ||
.and_then(|s| s.into_string().ok()) | ||
.unwrap_or_else(|| { | ||
error("mutils", "missing binary name"); | ||
}); | ||
match bin.as_str() { | ||
"dmesg" => dmesg::main(), | ||
"fdisk" => todo!(), | ||
"insmod" => todo!(), | ||
"lsmod" => lsmod::main(), | ||
"rmmod" => todo!(), | ||
bin @ ("mkfs" | "mkfs.ext2") => { | ||
// TODO change default fs to `ext4` when implemented | ||
let fs_name = bin.find(".").map(|i| &bin[(i + 1)..]).unwrap_or("ext2"); | ||
todo!() | ||
} | ||
"mount" => mount::main(args), | ||
"umount" => todo!(), | ||
"nologin" => nologin::main(), | ||
"powerctl" => todo!(), | ||
"halt" => todo!(), | ||
"poweroff" => todo!(), | ||
"reboot" => todo!(), | ||
"shutdown" => todo!(), | ||
"suspend" => todo!(), | ||
"ps" => ps::main(), | ||
"useradd" => todo!(), | ||
"usermod" => todo!(), | ||
"userdel" => todo!(), | ||
"groupadd" => todo!(), | ||
"groupmod" => todo!(), | ||
"groupdel" => todo!(), | ||
_ => error("mutils", "invalid binary name"), | ||
} | ||
} |
Oops, something went wrong.