From 04b20d134816c239de21c4858d7dd92b139844a9 Mon Sep 17 00:00:00 2001 From: Chip Senkbeil Date: Fri, 19 Aug 2022 01:25:32 -0500 Subject: [PATCH] Fix distant client shell choosing appropriate default; update CHANGELOG --- CHANGELOG.md | 8 ++++++++ src/cli/commands/client/shell.rs | 22 +++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45935e7..899ce8b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- `distant client shell` will now choose between `/bin/sh` and `cmd.exe` as the + default shell based on the family returned by a system info request +- `distant client shell` properly terminates master pty when the shell exits, + resolving the hanging that occurred for Windows `cmd.exe` and + `powershell.exe` upon exit + ## [0.18.0] - 2022-08-18 ### Changed diff --git a/src/cli/commands/client/shell.rs b/src/cli/commands/client/shell.rs index 0ce3a17..4cd310d 100644 --- a/src/cli/commands/client/shell.rs +++ b/src/cli/commands/client/shell.rs @@ -2,7 +2,7 @@ use super::{link::RemoteProcessLink, CliError, CliResult}; use anyhow::Context; use distant_core::{ data::{Environment, PtySize}, - DistantChannel, RemoteCommand, + DistantChannel, DistantChannelExt, RemoteCommand, }; use log::*; use std::time::Duration; @@ -22,7 +22,7 @@ impl Shell { } pub async fn spawn( - self, + mut self, cmd: impl Into>, mut environment: Environment, persist: bool, @@ -32,7 +32,23 @@ impl Shell { environment.insert("TERM".to_string(), "xterm-256color".to_string()); } - let cmd = cmd.into().unwrap_or_else(|| "/bin/sh".to_string()); + // Use provided shell, or determine remote operating system to pick a shell + let cmd = match cmd.into() { + Some(cmd) => cmd, + None => { + let system_info = self + .0 + .system_info() + .await + .context("Failed to detect remote operating system")?; + if system_info.family.eq_ignore_ascii_case("windows") { + "cmd.exe".to_string() + } else { + "/bin/sh".to_string() + } + } + }; + let mut proc = RemoteCommand::new() .persist(persist) .environment(environment)