diff options
author | Elliott Hughes <enh@google.com> | 2016-06-07 13:56:52 -0700 |
---|---|---|
committer | Elliott Hughes <enh@google.com> | 2016-06-07 14:53:21 -0700 |
commit | 4577ca2b17336c37332953dfebfbe31e781a2c94 (patch) | |
tree | 6b4ff357b01cdd16776641ce23564860cd76b8e7 /client | |
parent | e18f43aa542caa51ea61756432675239fe51d49d (diff) | |
download | adb-4577ca2b17336c37332953dfebfbe31e781a2c94.tar.gz |
Allow multiple (sequential) adb users on Linux.
Before this, adb will fail to start for the second user who tries because
/tmp/adb.log already exists and isn't writable by the second user.
Also allow $TMPDIR to override the use of /tmp.
Bug: https://code.google.com/p/android/issues/detail?id=211420
Change-Id: Ic53da981ac0fa45bfed62e7b351d75dca0540235
Diffstat (limited to 'client')
-rw-r--r-- | client/main.cpp | 33 |
1 files changed, 15 insertions, 18 deletions
diff --git a/client/main.cpp b/client/main.cpp index 65640ad..d2ca44e 100644 --- a/client/main.cpp +++ b/client/main.cpp @@ -23,11 +23,6 @@ #include <stdlib.h> #include <unistd.h> -// We only build the affinity WAR code for Linux. -#if defined(__linux__) -#include <sched.h> -#endif - #include <android-base/errors.h> #include <android-base/file.h> #include <android-base/logging.h> @@ -39,21 +34,14 @@ #include "adb_utils.h" #include "transport.h" -#if defined(_WIN32) -static BOOL WINAPI ctrlc_handler(DWORD type) { - // TODO: Consider trying to kill a starting up adb server (if we're in - // launch_server) by calling GenerateConsoleCtrlEvent(). - exit(STATUS_CONTROL_C_EXIT); - return TRUE; -} - static std::string GetLogFilePath() { +#if defined(_WIN32) const char log_name[] = "adb.log"; WCHAR temp_path[MAX_PATH]; // https://msdn.microsoft.com/en-us/library/windows/desktop/aa364992%28v=vs.85%29.aspx DWORD nchars = GetTempPathW(arraysize(temp_path), temp_path); - if ((nchars >= arraysize(temp_path)) || (nchars == 0)) { + if (nchars >= arraysize(temp_path) || nchars == 0) { // If string truncation or some other error. fatal("cannot retrieve temporary file path: %s\n", android::base::SystemErrorCodeToString(GetLastError()).c_str()); @@ -65,12 +53,12 @@ static std::string GetLogFilePath() { } return temp_path_utf8 + log_name; -} #else -static std::string GetLogFilePath() { - return std::string("/tmp/adb.log"); -} + const char* tmp_dir = getenv("TMPDIR"); + if (tmp_dir == nullptr) tmp_dir = "/tmp"; + return android::base::StringPrintf("%s/adb.%u.log", tmp_dir, getuid()); #endif +} static void setup_daemon_logging(void) { const std::string log_file_path(GetLogFilePath()); @@ -90,6 +78,15 @@ static void setup_daemon_logging(void) { LOG(INFO) << adb_version(); } +#if defined(_WIN32) +static BOOL WINAPI ctrlc_handler(DWORD type) { + // TODO: Consider trying to kill a starting up adb server (if we're in + // launch_server) by calling GenerateConsoleCtrlEvent(). + exit(STATUS_CONTROL_C_EXIT); + return TRUE; +} +#endif + int adb_server_main(int is_daemon, int server_port, int ack_reply_fd) { #if defined(_WIN32) // adb start-server starts us up with stdout and stderr hooked up to |