Skip to content

Commit

Permalink
kargs: Add more logging + debugging
Browse files Browse the repository at this point in the history
I thought there was a bug in this code; there wasn't, but
this helped me verify that.

Signed-off-by: Colin Walters <walters@verbum.org>
  • Loading branch information
cgwalters committed Jun 26, 2024
1 parent 8cecf8d commit 4dfcd2d
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion lib/src/kargs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use ostree_ext::prelude::FileExt;
use serde::Deserialize;

use crate::deploy::ImageState;
use crate::journal;

#[derive(Deserialize)]
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
Expand Down Expand Up @@ -36,16 +37,26 @@ pub(crate) fn get_kargs(
let mut options: Vec<String> = options.into_iter().map(|s| s.to_string()).collect();
kargs.append(&mut options);
}
tracing::debug!("Current base kargs: {kargs:?}");
};

// Get the kargs in kargs.d of the booted system
let mut source_kargs_files = Vec::new();
let mut existing_kargs: Vec<String> = vec![];
let fragments = liboverdrop::scan(&["/usr/lib"], "bootc/kargs.d", &["toml"], true);
for (_name, path) in fragments {
for (name, path) in fragments {
let name = name
.to_str()
.ok_or_else(|| anyhow::anyhow!("Invalid utf8: {name:?}"))?;
source_kargs_files.push(name.to_owned());
let s = std::fs::read_to_string(&path)?;
let mut parsed_kargs = parse_file(s.clone(), sys_arch.clone())?;
existing_kargs.append(&mut parsed_kargs);
}
journal::journal_print(
libsystemd::logging::Priority::Info,
&format!("Source kargs from: {source_kargs_files:?}"),
);

// Get the kargs in kargs.d of the pending image
let mut remote_kargs: Vec<String> = vec![];
Expand All @@ -57,11 +68,13 @@ pub(crate) fn get_kargs(
if !fetched_tree.query_exists(cancellable) {
// if the kargs.d directory does not exist in the fetched image, return the existing kargs
kargs.append(&mut existing_kargs);
tracing::debug!("No kargs.d in staged image");
return Ok(kargs);
}
let queryattrs = "standard::name,standard::type";
let queryflags = gio::FileQueryInfoFlags::NOFOLLOW_SYMLINKS;
let fetched_iter = fetched_tree.enumerate_children(queryattrs, queryflags, cancellable)?;
let mut applied_kargs_files = Vec::new();
while let Some(fetched_info) = fetched_iter.next_file(cancellable)? {
// only read and parse the file if it is a toml file
let name = fetched_info.name();
Expand All @@ -81,6 +94,7 @@ pub(crate) fn get_kargs(
let s = std::io::read_to_string(&mut reader)?;
let mut parsed_kargs = parse_file(s.clone(), sys_arch.clone())?;
remote_kargs.append(&mut parsed_kargs);
applied_kargs_files.push(name.to_owned());
}
}
}
Expand All @@ -97,6 +111,10 @@ pub(crate) fn get_kargs(
.filter(|item| !remote_kargs.contains(item))
.collect();

journal::journal_print(
libsystemd::logging::Priority::Info,
&format!("Applied kargs from: {applied_kargs_files:?}"),
);
tracing::debug!(
"kargs: added={:?} removed={:?}",
&added_kargs,
Expand Down

0 comments on commit 4dfcd2d

Please sign in to comment.