From 5228c32b86e4ddc16e23e7e2adc448297dea7e48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabiano=20Fid=C3=AAncio?= Date: Thu, 9 Jul 2026 21:30:41 +0200 Subject: [PATCH] debug: do-not-merge: add logs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Fabiano FidĂȘncio --- src/libs/kata-sys-util/src/hooks.rs | 42 ++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 3 deletions(-) diff --git a/src/libs/kata-sys-util/src/hooks.rs b/src/libs/kata-sys-util/src/hooks.rs index fd1a65e301..f644d069e4 100644 --- a/src/libs/kata-sys-util/src/hooks.rs +++ b/src/libs/kata-sys-util/src/hooks.rs @@ -18,6 +18,16 @@ use crate::validate::valid_env; const DEFAULT_HOOK_TIMEOUT_SEC: i32 = 10; +// DEBUG: mirror hook execution details to /dev/kmsg so they surface on the guest +// console (the only log channel that survives the createContainer fork, where the +// slog async drain is dead). Remove once the composable CDI-hook issue is root-caused. +fn kmsg_debug(msg: &str) { + use std::io::Write; + if let Ok(mut f) = std::fs::OpenOptions::new().write(true).open("/dev/kmsg") { + let _ = writeln!(f, "KATA-HOOK-DEBUG: {msg}"); + } +} + /// A simple wrapper over `oci::Hook` to provide `Hash, Eq`. /// /// The `oci::Hook` is auto-generated from protobuf source file, which doesn't implement `Hash, Eq`. @@ -127,11 +137,30 @@ impl HookStates { Err(std::io::Error::other("execute hook fail point injection")) }); info!(sl!(), "execute hook {:?}", hook); + kmsg_debug(&format!( + "run path={} args={:?} state.pid={:?} state.bundle={:?}", + hook.path().display(), + hook.args(), + state.as_ref().map(|s| s.pid), + state.as_ref().map(|s| s.bundle.clone()), + )); self.states.insert(hook.into(), HookState::Pending); - let executor = HookExecutor::new(hook)?; - let mut job = executor.spawn(state.as_ref())?; + let executor = match HookExecutor::new(hook) { + Ok(e) => e, + Err(e) => { + kmsg_debug(&format!("new() failed for {}: {e}", hook.path().display())); + return Err(e); + } + }; + let mut job = match executor.spawn(state.as_ref()) { + Ok(j) => j, + Err(e) => { + kmsg_debug(&format!("spawn failed for {}: {e}", hook.path().display())); + return Err(e); + } + }; let communicate_result = job .communicate()? @@ -153,14 +182,20 @@ impl HookStates { Ok((ref stdout, ref stderr)) => { if !stderr.is_empty() { error!(sl!(), "hook {} stderr: {}", hook.path().display(), stderr); + kmsg_debug(&format!("{} stderr: {}", hook.path().display(), stderr)); } if !stdout.is_empty() { info!(sl!(), "hook {} stdout: {}", hook.path().display(), stdout); + kmsg_debug(&format!("{} stdout: {}", hook.path().display(), stdout)); } } } - executor.wait_and_check(&mut job)?; + if let Err(e) = executor.wait_and_check(&mut job) { + kmsg_debug(&format!("exit-check failed for {}: {e}", hook.path().display())); + return Err(e); + } + kmsg_debug(&format!("{} finished OK", hook.path().display())); info!(sl!(), "hook {} finished", hook.path().display()); self.states.insert(hook.into(), HookState::Done); @@ -185,6 +220,7 @@ impl HookStates { if let Err(e) = self.execute_hook(hook, state.clone()) { // Ignore error and try next hook, the caller should retry. error!(sl!(), "hook {} failed: {}", hook.path().display(), e); + kmsg_debug(&format!("hook {} failed: {e}", hook.path().display())); } }