[RemoteUtil] Fix output from Windows SSH commands (#90)

Adds an ArchType argument to many RemoteUtil methods, which is used to
replace -tt (forced pseudo-TTY allocation) by -T (no pseudo-TTY
allocation). The -tt option adds tons of ANSI escape sequences to the
output and makes it unparsable, even after removing the sequences, as
some sequences like "delete the last X characters" are not honoured.

An exception is BuildProcessStartInfoForSshPortForward, where
replacing -tt by -T would make the port forwarding process exit
immediately.
This commit is contained in:
Lutz Justen
2023-02-06 18:42:00 +01:00
committed by GitHub
parent 5b82722ec1
commit 24906eb36e
8 changed files with 83 additions and 31 deletions

View File

@@ -179,6 +179,7 @@ cc_library(
srcs = ["server_arch.cc"],
hdrs = ["server_arch.h"],
deps = [
"//common:ansi_filter",
"//common:arch_type",
"//common:path",
"//common:remote_util",

View File

@@ -267,7 +267,7 @@ absl::Status CdcRsyncClient::StartServer(int port, const ServerArch& arch) {
std::string remote_command = arch.GetStartServerCommand(
kExitCodeNotFound, absl::StrFormat("%i %s", port, component_args));
start_info = remote_util_->BuildProcessStartInfoForSshPortForwardAndCommand(
port, port, /*reverse=*/false, remote_command);
port, port, /*reverse=*/false, remote_command, arch.GetType());
} else {
// Run cdc_rsync_server locally.
std::string exe_dir;

View File

@@ -19,6 +19,7 @@
#include "absl/strings/match.h"
#include "absl/strings/str_format.h"
#include "absl/strings/str_split.h"
#include "common/ansi_filter.h"
#include "common/path.h"
#include "common/remote_util.h"
#include "common/status_macros.h"
@@ -119,9 +120,15 @@ absl::StatusOr<ServerArch> ServerArch::DetectFromRemoteDevice(
// Run uname, assuming it's a Linux machine.
std::string uname_out;
std::string linux_cmd = "uname -sm";
absl::Status status =
remote_util->RunWithCapture(linux_cmd, "uname", &uname_out, nullptr);
absl::Status status = remote_util->RunWithCapture(
linux_cmd, "uname", &uname_out, nullptr, ArchType::kLinux_x86_64);
if (status.ok()) {
// Running uname on Windows, assuming it's Linux, leads to tons of ANSI
// escape sequences in the output. Remove them to at least get some readable
// output.
uname_out = absl::StripAsciiWhitespace(
ansi_filter::RemoveEscapeSequences(uname_out));
LOG_DEBUG("Uname returned '%s'", uname_out);
absl::StatusOr<ArchType> type = GetArchTypeFromUname(uname_out);
if (type.ok()) {
@@ -142,8 +149,9 @@ absl::StatusOr<ServerArch> ServerArch::DetectFromRemoteDevice(
std::string arch_out;
std::string windows_cmd =
RemoteUtil::QuoteForSsh("cmd /C set PROCESSOR_ARCHITECTURE ");
status = remote_util->RunWithCapture(
windows_cmd, "set PROCESSOR_ARCHITECTURE", &arch_out, nullptr);
status = remote_util->RunWithCapture(windows_cmd,
"set PROCESSOR_ARCHITECTURE", &arch_out,
nullptr, ArchType::kWindows_x86_64);
if (status.ok()) {
LOG_DEBUG("PROCESSOR_ARCHITECTURE is '%s'", arch_out);
absl::StatusOr<ArchType> type = GetArchTypeFromWinProcArch(arch_out);