Skip to content

Commit

Permalink
task:check bash cmd exist
Browse files Browse the repository at this point in the history
Signed-off-by: kamizjw <zhongjiawei1@huawei.com>
  • Loading branch information
Super User committed Jan 26, 2025
1 parent 34df244 commit 8cb7f97
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions vmm/task/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ limitations under the License.
*/

use std::{
fs,
os::{fd::IntoRawFd, unix::prelude::FromRawFd},
process::Stdio,
};

use containerd_shim::{
io_error,
monitor::{monitor_subscribe, Topic},
other_error, Error, Result,
other_error, Error, Result, other
};
use futures::StreamExt;
use log::{debug, error};
Expand Down Expand Up @@ -51,10 +52,23 @@ pub async fn listen_debug_console(addr: &str) -> Result<()> {
Ok(())
}

pub async fn check_exec_cmd() -> Result<Command> {
let cmd = vec![
String::from("/usr/bin/bash"),
String::from("/bin/bash"),
];
for file_path in &cmd {
if let Ok(_) = fs::metadata(file_path) {
return Ok(Command::new(file_path));
}
}
Err(other!("failed to get bash cmd"))
}

pub async fn debug_console(stream: VsockStream) -> Result<()> {
let pty = openpty(None, None)?;
let pty_master = pty.master;
let mut cmd = Command::new("/bin/bash");
let mut cmd = check_exec_cmd().await?;
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

0 comments on commit 8cb7f97

Please sign in to comment.