Skip to content

Commit

Permalink
task: add debug_shell param
Browse files Browse the repository at this point in the history
Signed-off-by: kamizjw <zhongjiawei1@huawei.com>
  • Loading branch information
kamizjw authored and Super User committed Feb 8, 2025
1 parent 34df244 commit 7b38239
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions vmm/task/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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 {
Expand All @@ -53,6 +55,7 @@ impl Default for TaskConfig {
log_level: "info".to_string(),
debug: false,
enable_tracing: false,
debug_shell: "/bin/bash".to_string(),
}
}
}
Expand All @@ -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)
}
Expand Down
9 changes: 5 additions & 4 deletions vmm/task/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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) });
Expand Down
2 changes: 1 addition & 1 deletion vmm/task/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ async fn initialize() -> anyhow::Result<TaskConfig> {
}
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);
}
}
Expand Down

0 comments on commit 7b38239

Please sign in to comment.