Merge "adb: shell: add -n flag to not read from stdin."
This commit is contained in:
commit
aae38d9704
5 changed files with 30 additions and 26 deletions
|
|
@ -30,12 +30,31 @@
|
||||||
#include <android-base/stringprintf.h>
|
#include <android-base/stringprintf.h>
|
||||||
#include <android-base/strings.h>
|
#include <android-base/strings.h>
|
||||||
|
|
||||||
|
#include "adb.h"
|
||||||
#include "adb_trace.h"
|
#include "adb_trace.h"
|
||||||
#include "sysdeps.h"
|
#include "sysdeps.h"
|
||||||
|
|
||||||
ADB_MUTEX_DEFINE(basename_lock);
|
ADB_MUTEX_DEFINE(basename_lock);
|
||||||
ADB_MUTEX_DEFINE(dirname_lock);
|
ADB_MUTEX_DEFINE(dirname_lock);
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
|
constexpr char kNullFileName[] = "NUL";
|
||||||
|
#else
|
||||||
|
constexpr char kNullFileName[] = "/dev/null";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
void close_stdin() {
|
||||||
|
int fd = unix_open(kNullFileName, O_RDONLY);
|
||||||
|
if (fd == -1) {
|
||||||
|
fatal_errno("failed to open %s", kNullFileName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TEMP_FAILURE_RETRY(dup2(fd, STDIN_FILENO)) == -1) {
|
||||||
|
fatal_errno("failed to redirect stdin to %s", kNullFileName);
|
||||||
|
}
|
||||||
|
unix_close(fd);
|
||||||
|
}
|
||||||
|
|
||||||
bool getcwd(std::string* s) {
|
bool getcwd(std::string* s) {
|
||||||
char* cwd = getcwd(nullptr, 0);
|
char* cwd = getcwd(nullptr, 0);
|
||||||
if (cwd != nullptr) *s = cwd;
|
if (cwd != nullptr) *s = cwd;
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,8 @@
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
void close_stdin();
|
||||||
|
|
||||||
bool getcwd(std::string* cwd);
|
bool getcwd(std::string* cwd);
|
||||||
bool directory_exists(const std::string& path);
|
bool directory_exists(const std::string& path);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,11 +34,10 @@
|
||||||
#include "adb.h"
|
#include "adb.h"
|
||||||
#include "adb_auth.h"
|
#include "adb_auth.h"
|
||||||
#include "adb_listeners.h"
|
#include "adb_listeners.h"
|
||||||
|
#include "adb_utils.h"
|
||||||
#include "transport.h"
|
#include "transport.h"
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
static const char kNullFileName[] = "NUL";
|
|
||||||
|
|
||||||
static BOOL WINAPI ctrlc_handler(DWORD type) {
|
static BOOL WINAPI ctrlc_handler(DWORD type) {
|
||||||
// TODO: Consider trying to kill a starting up adb server (if we're in
|
// TODO: Consider trying to kill a starting up adb server (if we're in
|
||||||
// launch_server) by calling GenerateConsoleCtrlEvent().
|
// launch_server) by calling GenerateConsoleCtrlEvent().
|
||||||
|
|
@ -66,24 +65,11 @@ static std::string GetLogFilePath() {
|
||||||
return temp_path_utf8 + log_name;
|
return temp_path_utf8 + log_name;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
static const char kNullFileName[] = "/dev/null";
|
|
||||||
|
|
||||||
static std::string GetLogFilePath() {
|
static std::string GetLogFilePath() {
|
||||||
return std::string("/tmp/adb.log");
|
return std::string("/tmp/adb.log");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static void close_stdin() {
|
|
||||||
int fd = unix_open(kNullFileName, O_RDONLY);
|
|
||||||
if (fd == -1) {
|
|
||||||
fatal("cannot open '%s': %s", kNullFileName, strerror(errno));
|
|
||||||
}
|
|
||||||
if (dup2(fd, STDIN_FILENO) == -1) {
|
|
||||||
fatal("cannot redirect stdin: %s", strerror(errno));
|
|
||||||
}
|
|
||||||
unix_close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void setup_daemon_logging(void) {
|
static void setup_daemon_logging(void) {
|
||||||
const std::string log_file_path(GetLogFilePath());
|
const std::string log_file_path(GetLogFilePath());
|
||||||
int fd = unix_open(log_file_path.c_str(), O_WRONLY | O_CREAT | O_APPEND, 0640);
|
int fd = unix_open(log_file_path.c_str(), O_WRONLY | O_CREAT | O_APPEND, 0640);
|
||||||
|
|
|
||||||
|
|
@ -112,9 +112,10 @@ static void help() {
|
||||||
" (-a preserves file timestamp and mode)\n"
|
" (-a preserves file timestamp and mode)\n"
|
||||||
" adb sync [ <directory> ] - copy host->device only if changed\n"
|
" adb sync [ <directory> ] - copy host->device only if changed\n"
|
||||||
" (-l means list but don't copy)\n"
|
" (-l means list but don't copy)\n"
|
||||||
" adb shell [-e escape] [-Tt] [-x] [command]\n"
|
" adb shell [-e escape] [-n] [-Tt] [-x] [command]\n"
|
||||||
" - run remote shell command (interactive shell if no command given)\n"
|
" - run remote shell command (interactive shell if no command given)\n"
|
||||||
" (-e: choose escape character, or \"none\"; default '~')\n"
|
" (-e: choose escape character, or \"none\"; default '~')\n"
|
||||||
|
" (-n: don't read from stdin)\n"
|
||||||
" (-T: disable PTY allocation)\n"
|
" (-T: disable PTY allocation)\n"
|
||||||
" (-t: force PTY allocation)\n"
|
" (-t: force PTY allocation)\n"
|
||||||
" (-x: disable remote exit codes and stdout/stderr separation)\n"
|
" (-x: disable remote exit codes and stdout/stderr separation)\n"
|
||||||
|
|
@ -731,6 +732,11 @@ static int adb_shell(int argc, const char** argv,
|
||||||
++argv;
|
++argv;
|
||||||
} else if (!strcmp(argv[0], "-x")) {
|
} else if (!strcmp(argv[0], "-x")) {
|
||||||
use_shell_protocol = false;
|
use_shell_protocol = false;
|
||||||
|
--argc;
|
||||||
|
++argv;
|
||||||
|
} else if (!strcmp(argv[0], "-n")) {
|
||||||
|
close_stdin();
|
||||||
|
|
||||||
--argc;
|
--argc;
|
||||||
++argv;
|
++argv;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -34,6 +34,7 @@
|
||||||
#include "adb.h"
|
#include "adb.h"
|
||||||
#include "adb_auth.h"
|
#include "adb_auth.h"
|
||||||
#include "adb_listeners.h"
|
#include "adb_listeners.h"
|
||||||
|
#include "adb_utils.h"
|
||||||
#include "transport.h"
|
#include "transport.h"
|
||||||
|
|
||||||
static const char* root_seclabel = nullptr;
|
static const char* root_seclabel = nullptr;
|
||||||
|
|
@ -217,16 +218,6 @@ int adbd_main(int server_port) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void close_stdin() {
|
|
||||||
int fd = unix_open("/dev/null", O_RDONLY);
|
|
||||||
if (fd == -1) {
|
|
||||||
perror("failed to open /dev/null, stdin will remain open");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
dup2(fd, STDIN_FILENO);
|
|
||||||
unix_close(fd);
|
|
||||||
}
|
|
||||||
|
|
||||||
int main(int argc, char** argv) {
|
int main(int argc, char** argv) {
|
||||||
while (true) {
|
while (true) {
|
||||||
static struct option opts[] = {
|
static struct option opts[] = {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue