agent: fix the issue of missing found right shell
It should iter the shells to find the existing shell
command instead of return an error directly when it
meet an absent shell command.
Fixes:
@@ -382,9 +382,21 @@ use std::path::PathBuf;
use std::process::{exit, Command, Stdio};
fn setup_debug_console(shells: Vec<String>, port: u32) -> Result<()> {
- for shell in shells.iter() {
- let binary = PathBuf::from(shell);
+ let mut shell: &str = "";
+ for sh in shells.iter() {
+ let binary = PathBuf::from(sh);
if binary.exists() {
+ shell = sh;
+ break;
+ }
+ }
+
+ if shell == "" {
+ return Err(
+ ErrorKind::ErrorCode("no shell found to launch debug console".to_string()).into(),
+ );
+ }
+
let f: RawFd = if port > 0 {
let listenfd = socket::socket(
AddressFamily::Vsock,
@@ -412,20 +424,12 @@ fn setup_debug_console(shells: Vec<String>, port: u32) -> Result<()> {
let mut cmd = match cmd {
Ok(c) => c,
- Err(_) => {
- return Err(ErrorKind::ErrorCode("failed to spawn shell".to_string()).into())
- }
+ Err(_) => return Err(ErrorKind::ErrorCode("failed to spawn shell".to_string()).into()),
};
cmd.wait()?;
return Ok(());
- } else {
- return Err(ErrorKind::ErrorCode("invalid shell".to_string()).into());
- }
- }
-
- Err(ErrorKind::ErrorCode("no shell".to_string()).into())
}
#[cfg(test)]
@@ -447,7 +451,10 @@ mod tests {
let result = setup_debug_console(shells.to_vec(), 0);
assert!(result.is_err());
- assert_eq!(result.unwrap_err().to_string(), "Error Code: 'no shell'");
+ assert_eq!(
+ result.unwrap_err().to_string(),
+ "Error Code: 'no shell found to launch debug console'"
+ );
}
#[test]
@@ -472,7 +479,7 @@ mod tests {
assert!(result.is_err());
assert_eq!(
result.unwrap_err().to_string(),
- "Error Code: 'invalid shell'"
+ "Error Code: 'no shell found to launch debug console'"
);
}
}
