diff options
author | Elliott Hughes <enh@google.com> | 2015-11-16 10:55:34 -0800 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2015-11-16 10:55:34 -0800 |
commit | 18ddf5c6a233bd56d20548fd834c0ecbf8216410 (patch) | |
tree | 7ea00e1672895b145e822de901e00e45d1d5ea39 /adb/shell_service.cpp | |
parent | 942f8ea84f3f96c2e2556fe90ebba0ec76730553 (diff) | |
download | core-18ddf5c6a233bd56d20548fd834c0ecbf8216410.tar.gz core-18ddf5c6a233bd56d20548fd834c0ecbf8216410.tar.bz2 core-18ddf5c6a233bd56d20548fd834c0ecbf8216410.zip |
Pass $TERM to the device.
Unfortunately, this isn't backwards-compatible with the current shell
protocol because we made unknown shell: arguments errors. We could try
to commit the change to make them just warnings first, but how would
we know when everyone was running adbd with that change? Bumping the
protocol version doesn't help because that only affects the code running
on the host. And although we could add another feature to the reported
features, since shell_v2 is still in development, that doesn't seem
worthwhile.
Bug: http://b/25601436
Change-Id: I12b81aa656cd25b91d14ef691dcbd2b7dab49535
Diffstat (limited to 'adb/shell_service.cpp')
-rw-r--r-- | adb/shell_service.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/adb/shell_service.cpp b/adb/shell_service.cpp index e3fde2691..2e41fe649 100644 --- a/adb/shell_service.cpp +++ b/adb/shell_service.cpp @@ -175,8 +175,8 @@ bool CreateSocketpair(ScopedFd* fd1, ScopedFd* fd2) { class Subprocess { public: - Subprocess(const std::string& command, SubprocessType type, - SubprocessProtocol protocol); + Subprocess(const std::string& command, const char* terminal_type, + SubprocessType type, SubprocessProtocol protocol); ~Subprocess(); const std::string& command() const { return command_; } @@ -207,6 +207,7 @@ class Subprocess { ScopedFd* PassOutput(ScopedFd* sfd, ShellProtocol::Id id); const std::string command_; + const std::string terminal_type_; SubprocessType type_; SubprocessProtocol protocol_; pid_t pid_ = -1; @@ -220,9 +221,12 @@ class Subprocess { DISALLOW_COPY_AND_ASSIGN(Subprocess); }; -Subprocess::Subprocess(const std::string& command, SubprocessType type, - SubprocessProtocol protocol) - : command_(command), type_(type), protocol_(protocol) { +Subprocess::Subprocess(const std::string& command, const char* terminal_type, + SubprocessType type, SubprocessProtocol protocol) + : command_(command), + terminal_type_(terminal_type ? terminal_type : ""), + type_(type), + protocol_(protocol) { } Subprocess::~Subprocess() { @@ -290,6 +294,9 @@ bool Subprocess::ForkAndExec() { setenv("SHELL", pw->pw_shell, 1); setenv("USER", pw->pw_name, 1); } + if (!terminal_type_.empty()) { + setenv("TERM", terminal_type_.c_str(), 1); + } if (is_interactive()) { execl(_PATH_BSHELL, _PATH_BSHELL, "-", nullptr); @@ -644,13 +651,14 @@ void Subprocess::WaitForExit() { } // namespace -int StartSubprocess(const char *name, SubprocessType type, - SubprocessProtocol protocol) { - D("starting %s subprocess (protocol=%s): '%s'", +int StartSubprocess(const char* name, const char* terminal_type, + SubprocessType type, SubprocessProtocol protocol) { + D("starting %s subprocess (protocol=%s, TERM=%s): '%s'", type == SubprocessType::kRaw ? "raw" : "PTY", - protocol == SubprocessProtocol::kNone ? "none" : "shell", name); + protocol == SubprocessProtocol::kNone ? "none" : "shell", + terminal_type, name); - Subprocess* subprocess = new Subprocess(name, type, protocol); + Subprocess* subprocess = new Subprocess(name, terminal_type, type, protocol); if (!subprocess) { LOG(ERROR) << "failed to allocate new subprocess"; return -1; |