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

Minor bits #20

Merged
merged 2 commits into from
Nov 2, 2024
Merged
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
25 changes: 19 additions & 6 deletions src/bin/composefs-pivot-sysroot.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
use std::io::Read;
use std::path::Path;

use anyhow::{bail, Result};

use composefs_experiments::{fsverity::Sha256HashValue, repository::Repository};

fn parse_composefs_cmdline() -> Result<Sha256HashValue> {
let mut cmdline = vec![];
let mut proc_cmdline = std::fs::File::open("/proc/cmdline")?;
proc_cmdline.read_to_end(&mut cmdline)?;
fn parse_composefs_cmdline(cmdline: &[u8]) -> Result<Sha256HashValue> {
// TODO?: officially we need to understand quoting with double-quotes...
for part in cmdline.split(|c| c.is_ascii_whitespace()) {
if let Some(digest) = part.strip_prefix(b"composefs=") {
Expand All @@ -22,8 +18,25 @@ fn parse_composefs_cmdline() -> Result<Sha256HashValue> {

fn main() -> Result<()> {
let repo = Repository::open_system()?;
let image = parse_composefs_cmdline()?;
let cmdline = std::fs::read("/proc/cmdline")?;
let image = parse_composefs_cmdline(&cmdline)?;
repo.pivot_sysroot(&hex::encode(image), Path::new("/sysroot"))?;

Ok(())
}

#[test]
fn test_parse() {
let failing = ["", "foo", "composefs", "composefs=foo"];
for case in failing {
assert!(parse_composefs_cmdline(case.as_bytes()).is_err());
}
let digest = "8b7df143d91c716ecfa5fc1730022f6b421b05cedee8fd52b1fc65a96030ad52";
let digest_bytes = hex::decode(&digest).unwrap();
assert_eq!(
parse_composefs_cmdline(format!("composefs={digest}").as_bytes())
.unwrap()
.as_slice(),
&digest_bytes
);
}