From 7b38239e4ee3c4e7b14369a8def0be8f4ed28295 Mon Sep 17 00:00:00 2001 From: kamizjw Date: Mon, 27 Jan 2025 16:48:09 +0800 Subject: [PATCH] task: add debug_shell param Signed-off-by: kamizjw --- vmm/task/src/config.rs | 4 ++++ vmm/task/src/debug.rs | 9 +++++---- vmm/task/src/main.rs | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/vmm/task/src/config.rs b/vmm/task/src/config.rs index 6ab36705..4a4c90c3 100644 --- a/vmm/task/src/config.rs +++ b/vmm/task/src/config.rs @@ -21,6 +21,7 @@ const SHAREFS_TYPE: &str = "task.sharefs_type"; const LOG_LEVEL: &str = "task.log_level"; const TASK_DEBUG: &str = "task.debug"; const ENABLE_TRACING: &str = "task.enable_tracing"; +const DEBUG_SHELL: &str = "task.debug_shell"; macro_rules! parse_cmdline { ($param:ident, $key:ident, $field:expr) => { @@ -44,6 +45,7 @@ pub struct TaskConfig { pub(crate) log_level: String, pub(crate) debug: bool, pub(crate) enable_tracing: bool, + pub(crate) debug_shell: String, } impl Default for TaskConfig { @@ -53,6 +55,7 @@ impl Default for TaskConfig { log_level: "info".to_string(), debug: false, enable_tracing: false, + debug_shell: "/bin/bash".to_string(), } } } @@ -70,6 +73,7 @@ impl TaskConfig { parse_cmdline!(param, LOG_LEVEL, config.log_level, String::from); parse_cmdline!(param, TASK_DEBUG, config.debug); parse_cmdline!(param, ENABLE_TRACING, config.enable_tracing); + parse_cmdline!(param, DEBUG_SHELL, config.debug_shell, String::from); } Ok(config) } diff --git a/vmm/task/src/debug.rs b/vmm/task/src/debug.rs index 19c2c31c..c473e3d0 100644 --- a/vmm/task/src/debug.rs +++ b/vmm/task/src/debug.rs @@ -36,13 +36,14 @@ use tokio_vsock::VsockStream; use crate::{stream::RawStream, util::wait_pid, vsock::bind_vsock}; -pub async fn listen_debug_console(addr: &str) -> Result<()> { +pub async fn listen_debug_console(addr: &str, debug_shell: &str) -> Result<()> { let l = bind_vsock(addr).await?; + let shell = String::from(debug_shell); tokio::spawn(async move { let mut incoming = l.incoming(); while let Some(Ok(s)) = incoming.next().await { debug!("get a debug console request"); - if let Err(e) = debug_console(s).await { + if let Err(e) = debug_console(s, &shell).await { error!("failed to open debug console {:?}", e); } } @@ -51,10 +52,10 @@ pub async fn listen_debug_console(addr: &str) -> Result<()> { Ok(()) } -pub async fn debug_console(stream: VsockStream) -> Result<()> { +pub async fn debug_console(stream: VsockStream, debug_shell: &str) -> Result<()> { let pty = openpty(None, None)?; let pty_master = pty.master; - let mut cmd = Command::new("/bin/bash"); + let mut cmd = Command::new(debug_shell); let pty_fd = pty.slave.into_raw_fd(); cmd.stdin(unsafe { Stdio::from_raw_fd(pty_fd) }); cmd.stdout(unsafe { Stdio::from_raw_fd(pty_fd) }); diff --git a/vmm/task/src/main.rs b/vmm/task/src/main.rs index 1076cdd1..a8870e3c 100644 --- a/vmm/task/src/main.rs +++ b/vmm/task/src/main.rs @@ -170,7 +170,7 @@ async fn initialize() -> anyhow::Result { } if config.debug { debug!("listen vsock port 1025 for debug console"); - if let Err(e) = listen_debug_console("vsock://-1:1025").await { + if let Err(e) = listen_debug_console("vsock://-1:1025", &config.debug_shell).await { error!("failed to listen debug console port, {:?}", e); } }