Skip to content

Commit

Permalink
entry: Use entry-specific filesystem root for additions to kernel
Browse files Browse the repository at this point in the history
The cmdline extensions are per transaction in moss terminology so
we need to load relative to their sysroot, rather than cross-contaminating
entries (i.e enabling plymouth in a non plymouth enabled install, etc)

Signed-off-by: Ikey Doherty <[email protected]>
  • Loading branch information
ikeycode committed Dec 22, 2024
1 parent 1291bba commit 84c7aad
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 32 deletions.
18 changes: 17 additions & 1 deletion blsforme/src/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
//
// SPDX-License-Identifier: MPL-2.0

use std::path::PathBuf;

use crate::{AuxiliaryFile, Kernel, Schema};

/// An entry corresponds to a single kernel, and may have a supplemental
Expand All @@ -10,6 +12,8 @@ use crate::{AuxiliaryFile, Kernel, Schema};
pub struct Entry<'a> {
pub(crate) kernel: &'a Kernel,

pub(crate) sysroot: Option<PathBuf>,

// Additional cmdline
#[allow(dead_code)]
cmdline: Option<String>,
Expand All @@ -18,7 +22,11 @@ pub struct Entry<'a> {
impl<'a> Entry<'a> {
/// New entry for the given kernel
pub fn new(kernel: &'a Kernel) -> Self {
Self { kernel, cmdline: None }
Self {
kernel,
cmdline: None,
sysroot: None,
}
}

/// With the following cmdline
Expand All @@ -29,6 +37,14 @@ impl<'a> Entry<'a> {
}
}

/// With the given system root
pub fn with_sysroot(self, sysroot: impl Into<PathBuf>) -> Self {
Self {
sysroot: Some(sysroot.into()),
..self
}
}

/// Return an entry ID, suitable for `.conf` generation
pub fn id(&self, schema: &Schema) -> String {
// TODO: For BLS schema, grab something even uniquer (TM)
Expand Down
61 changes: 30 additions & 31 deletions blsforme/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ pub struct Manager<'a> {

mounts: Mounts,

cmdline: String,
cmdline: Vec<String>,

system_excluded_snippets: Vec<String>,
}

impl<'a> Manager<'a> {
Expand All @@ -51,7 +53,7 @@ impl<'a> Manager<'a> {
log::info!("root = {:?}", root.cmd_line());

// Right now we assume `rw` for the rootfs
let mut cmdline = vec![root.cmd_line(), "rw".to_string()];
let cmdline = [root.cmd_line(), "rw".to_string()];
let mut local_cmdline = vec![];

let etc_cmdline_d = config.root.path().join("etc").join("kernel").join("cmdline.d");
Expand Down Expand Up @@ -83,30 +85,6 @@ impl<'a> Manager<'a> {
}
}

// Merge the system-wide cmdline with the rootfs cmdline
if let Ok(it) = fs::read_dir(
config
.root
.path()
.join("usr")
.join("lib")
.join("kernel")
.join("cmdline.d"),
) {
log::trace!("reading system cmdline.d entries");
let entries = it
.filter_map(|p| p.ok())
.filter(|d| {
if let Some(name) = d.file_name().to_str() {
!system_excludes.contains(&name.to_string())
} else {
true
}
})
.filter_map(|p| cmdline_snippet(p.path()).ok());
cmdline.extend(entries);
}

// Grab parent disk, establish disk environment setup
let disk_parent = probe.get_device_parent(root.path);
let boot_env = BootEnvironment::new(&probe, disk_parent, config)?;
Expand Down Expand Up @@ -140,20 +118,20 @@ impl<'a> Manager<'a> {
}
}

let cmdline_string = cmdline
let cmdline_joined = cmdline
.iter()
.chain(local_cmdline.iter())
.cloned()
.collect::<Vec<_>>()
.join(" ");
.collect::<Vec<_>>();

Ok(Self {
config,
entries: vec![],
bootloader_assets: vec![],
boot_env,
mounts,
cmdline: cmdline_string,
cmdline: cmdline_joined,
system_excluded_snippets: system_excludes,
})
}

Expand Down Expand Up @@ -240,7 +218,28 @@ impl<'a> Manager<'a> {

// Install every kernel that was passed to us
for entry in self.entries.iter() {
bootloader.install(&self.cmdline, entry)?;
let root_dir = entry
.sysroot
.clone()
.unwrap_or_else(|| self.config.root.path().to_path_buf());
let mut cmdline = self.cmdline.clone();

// Merge the system-wide cmdline with the rootfs cmdline
if let Ok(it) = fs::read_dir(root_dir.join("usr").join("lib").join("kernel").join("cmdline.d")) {
log::trace!("reading system cmdline.d entries");
let entries = it
.filter_map(|p| p.ok())
.filter(|d| {
if let Some(name) = d.file_name().to_str() {
!self.system_excluded_snippets.contains(&name.to_string())
} else {
true
}
})
.filter_map(|p| cmdline_snippet(p.path()).ok());
cmdline.extend(entries);
}
bootloader.install(&cmdline.join(" "), entry)?;
}

Ok(())
Expand Down

0 comments on commit 84c7aad

Please sign in to comment.