From dabe66994bed6615a915b5c47b35b35ad8690a19 Mon Sep 17 00:00:00 2001 From: Valentin Haudiquet Date: Fri, 30 Oct 2026 23:13:03 +0100 Subject: [PATCH] refactor: drop the dead shell probe and unused engine bindings utils::detect_shell lost to the image probe; krun_set_root and krun_set_env have had no caller since the root crossed as a block device. Unused FFI bindings rot where they stand. --- crates/ecrou/src/krun.rs | 28 ++-------------------------- crates/ecrou/src/utils.rs | 22 ---------------------- 2 files changed, 2 insertions(+), 48 deletions(-) diff --git a/crates/ecrou/src/krun.rs b/crates/ecrou/src/krun.rs index f7a28ca..ee535f7 100644 --- a/crates/ecrou/src/krun.rs +++ b/crates/ecrou/src/krun.rs @@ -117,18 +117,6 @@ impl Krun { krun_ret(unsafe { f(ctx_id, vcpus, ram_mib) }, "krun_set_vm_config") } - /// `krun_set_root`: the virtiofs share that becomes the guest root. - pub fn set_root(&self, ctx_id: u32, root: &Path) -> Result<()> { - let root_c = path_cstring(root)?; - let f = symbol!( - self.lib, - b"krun_set_root\0", - unsafe extern "C" fn(u32, *const c_char) -> i32 - ); - // Safety: root_c is NUL-terminated and outlives the call. - krun_ret(unsafe { f(ctx_id, root_c.as_ptr()) }, "krun_set_root") - } - /// `krun_add_disk`: a raw image as a virtio-blk device. An engine /// built without the blk feature ships no such symbol, and the /// lookup failure names that, not age. @@ -264,18 +252,6 @@ impl Krun { ) } - /// `krun_set_env`: extra environment for the payload. - pub fn set_env(&self, ctx_id: u32, envp: &[String]) -> Result<()> { - let envp_c = CArgs::build(envp)?; - let f = symbol!( - self.lib, - b"krun_set_env\0", - unsafe extern "C" fn(u32, *const *const c_char) -> i32 - ); - // Safety: envp_c is NUL-terminated and outlives the call. - krun_ret(unsafe { f(ctx_id, envp_c.ptr()) }, "krun_set_env") - } - /// `krun_set_console_output`: redirect the guest console to a file. pub fn set_console_output(&self, ctx_id: u32, path: &Path) -> Result<()> { let path_c = path_cstring(path)?; @@ -437,9 +413,9 @@ mod tests { #[test] fn krun_ret_maps_negated_errno() { - let err = krun_ret(-2, "krun_set_root").unwrap_err(); + let err = krun_ret(-2, "krun_set_vm_config").unwrap_err(); let msg = format!("{err:#}"); - assert!(msg.contains("krun_set_root failed"), "{msg}"); + assert!(msg.contains("krun_set_vm_config failed"), "{msg}"); assert!(msg.contains("No such file"), "{msg}"); } } diff --git a/crates/ecrou/src/utils.rs b/crates/ecrou/src/utils.rs index 1f73ff4..75dd8c8 100644 --- a/crates/ecrou/src/utils.rs +++ b/crates/ecrou/src/utils.rs @@ -160,28 +160,6 @@ pub fn map_oci_arch(arch: &str) -> String { Arch::from_str(arch).oci_name().to_string() } -// ============================================================================ -// Shell detection -// ============================================================================ - -/// Detect the best available shell in a rootfs -/// Checks for bash first, falls back to sh -/// Returns the path relative to the rootfs (e.g., "/bin/bash") -pub fn detect_shell(rootfs: &Path) -> &'static str { - // Check for bash first (preferred) - if rootfs.join("bin/bash").exists() { - "/bin/bash" - } else if rootfs.join("bin/sh").exists() { - "/bin/sh" - } else if rootfs.join("usr/bin/bash").exists() { - "/usr/bin/bash" - } else if rootfs.join("usr/bin/sh").exists() { - "/usr/bin/sh" - } else { - "/bin/sh" // Will fail with clear error if not present - } -} - #[cfg(test)] mod tests { use super::*;