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 23, 2024
1 parent 655ee1e commit f67eb6c
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 @@ -2,6 +2,7 @@ use anyhow::Ok;
use anyhow::Result;

use crate::deploy::ImageState;
use crate::journal;
use ostree::gio;
use ostree_ext::ostree;
use ostree_ext::ostree::Deployment;
Expand Down Expand Up @@ -37,16 +38,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 @@ -58,11 +69,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 @@ -82,6 +95,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 @@ -98,6 +112,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 f67eb6c

Please sign in to comment.