diff options
author | 2021-09-13 16:31:38 -0700 | |
---|---|---|
committer | 2021-09-14 15:12:58 -0700 | |
commit | c9a77aaf722e63f1e947caf5a28f0ad6eb029c30 (patch) | |
tree | 259283fdc137753f88935de540c4f1b27f5898a8 | |
parent | 20f5a270658bcdff7a4cc4f9f0059c572ca123eb (diff) |
Fix frameworks/native compiling against musl
stdout is a macro in musl, don't use it as an identifier.
Bug: 190084016
Test: m USE_HOST_MUSL=true
Change-Id: I470f329573cdee607abedf0f1a6448cad2b5151e
-rw-r--r-- | libs/binder/ServiceManagerHost.cpp | 16 | ||||
-rw-r--r-- | libs/binder/UtilsHost.cpp | 6 | ||||
-rw-r--r-- | libs/binder/UtilsHost.h | 10 | ||||
-rw-r--r-- | libs/binder/tests/binderHostDeviceTest.cpp | 6 | ||||
-rw-r--r-- | libs/binder/tests/binderUtilsHostTest.cpp | 10 |
5 files changed, 24 insertions, 24 deletions
diff --git a/libs/binder/ServiceManagerHost.cpp b/libs/binder/ServiceManagerHost.cpp index 59334b7542..27cc563adc 100644 --- a/libs/binder/ServiceManagerHost.cpp +++ b/libs/binder/ServiceManagerHost.cpp @@ -74,12 +74,12 @@ std::optional<AdbForwarder> AdbForwarder::forward(unsigned int devicePort) { result->toString().c_str()); return std::nullopt; } - if (!result->stderr.empty()) { + if (!result->stderrStr.empty()) { LOG_HOST("`adb forward tcp:0 tcp:%d` writes to stderr: %s", devicePort, - result->stderr.c_str()); + result->stderrStr.c_str()); } - unsigned int hostPort = parsePortNumber(result->stdout, "host port"); + unsigned int hostPort = parsePortNumber(result->stdoutStr, "host port"); if (hostPort == 0) return std::nullopt; return AdbForwarder(hostPort); @@ -105,9 +105,9 @@ AdbForwarder::~AdbForwarder() { result->toString().c_str()); return; } - if (!result->stderr.empty()) { + if (!result->stderrStr.empty()) { LOG_HOST("`adb forward --remove tcp:%d` writes to stderr: %s", *mPort, - result->stderr.c_str()); + result->stderrStr.c_str()); } LOG_HOST("Successfully run `adb forward --remove tcp:%d`", *mPort); @@ -139,8 +139,8 @@ sp<IBinder> getDeviceService(std::vector<std::string>&& serviceDispatcherArgs) { ALOGE("Command exits with: %s", result->toString().c_str()); return nullptr; } - if (!result->stderr.empty()) { - LOG_HOST("servicedispatcher writes to stderr: %s", result->stderr.c_str()); + if (!result->stderrStr.empty()) { + LOG_HOST("servicedispatcher writes to stderr: %s", result->stderrStr.c_str()); } if (!result->stdoutEndsWithNewLine()) { @@ -148,7 +148,7 @@ sp<IBinder> getDeviceService(std::vector<std::string>&& serviceDispatcherArgs) { return nullptr; } - unsigned int devicePort = parsePortNumber(result->stdout, "device port"); + unsigned int devicePort = parsePortNumber(result->stdoutStr, "device port"); if (devicePort == 0) return nullptr; auto forwardResult = AdbForwarder::forward(devicePort); diff --git a/libs/binder/UtilsHost.cpp b/libs/binder/UtilsHost.cpp index d121ce2221..52b8f69d36 100644 --- a/libs/binder/UtilsHost.cpp +++ b/libs/binder/UtilsHost.cpp @@ -63,7 +63,7 @@ std::ostream& operator<<(std::ostream& os, const CommandResult& res) { if (res.exitCode) os << "code=" << *res.exitCode; if (res.signal) os << "signal=" << *res.signal; if (res.pid) os << ", pid=" << *res.pid; - return os << ", stdout=" << res.stdout << ", stderr=" << res.stderr; + return os << ", stdout=" << res.stdoutStr << ", stderr=" << res.stderrStr; } std::string CommandResult::toString() const { @@ -142,9 +142,9 @@ android::base::Result<CommandResult> execute(std::vector<std::string> argStringV int pollRet = poll(fds, nfds, 1000 /* ms timeout */); if (pollRet == -1) return android::base::ErrnoError() << "poll()"; - if (!handlePoll(&ret.outPipe, outPollFd, &ret.stdout)) + if (!handlePoll(&ret.outPipe, outPollFd, &ret.stdoutStr)) return android::base::ErrnoError() << "read(stdout)"; - if (!handlePoll(&ret.errPipe, errPollFd, &ret.stderr)) + if (!handlePoll(&ret.errPipe, errPollFd, &ret.stderrStr)) return android::base::ErrnoError() << "read(stderr)"; if (end && end(ret)) return ret; diff --git a/libs/binder/UtilsHost.h b/libs/binder/UtilsHost.h index 0f29f60320..98ac4e0c48 100644 --- a/libs/binder/UtilsHost.h +++ b/libs/binder/UtilsHost.h @@ -43,8 +43,8 @@ struct CommandResult { std::optional<int32_t> exitCode; std::optional<int32_t> signal; std::optional<pid_t> pid; - std::string stdout; - std::string stderr; + std::string stdoutStr; + std::string stderrStr; android::base::unique_fd outPipe; android::base::unique_fd errPipe; @@ -55,15 +55,15 @@ struct CommandResult { std::swap(exitCode, other.exitCode); std::swap(signal, other.signal); std::swap(pid, other.pid); - std::swap(stdout, other.stdout); - std::swap(stderr, other.stderr); + std::swap(stdoutStr, other.stdoutStr); + std::swap(stderrStr, other.stderrStr); return *this; } ~CommandResult(); [[nodiscard]] std::string toString() const; [[nodiscard]] bool stdoutEndsWithNewLine() const { - return !stdout.empty() && stdout.back() == '\n'; + return !stdoutStr.empty() && stdoutStr.back() == '\n'; } private: diff --git a/libs/binder/tests/binderHostDeviceTest.cpp b/libs/binder/tests/binderHostDeviceTest.cpp index 3f72b8f58a..eec3b447de 100644 --- a/libs/binder/tests/binderHostDeviceTest.cpp +++ b/libs/binder/tests/binderHostDeviceTest.cpp @@ -75,10 +75,10 @@ public: auto debuggableResult = execute(Split("adb shell getprop ro.debuggable", " "), nullptr); ASSERT_THAT(debuggableResult, Ok()); ASSERT_EQ(0, debuggableResult->exitCode) << *debuggableResult; - auto debuggableBool = ParseBool(Trim(debuggableResult->stdout)); - ASSERT_NE(ParseBoolResult::kError, debuggableBool) << Trim(debuggableResult->stdout); + auto debuggableBool = ParseBool(Trim(debuggableResult->stdoutStr)); + ASSERT_NE(ParseBoolResult::kError, debuggableBool) << Trim(debuggableResult->stdoutStr); if (debuggableBool == ParseBoolResult::kFalse) { - GTEST_SKIP() << "ro.debuggable=" << Trim(debuggableResult->stdout); + GTEST_SKIP() << "ro.debuggable=" << Trim(debuggableResult->stdoutStr); } auto lsResult = execute(Split("adb shell which servicedispatcher", " "), nullptr); diff --git a/libs/binder/tests/binderUtilsHostTest.cpp b/libs/binder/tests/binderUtilsHostTest.cpp index fb248369a0..4330e3e615 100644 --- a/libs/binder/tests/binderUtilsHostTest.cpp +++ b/libs/binder/tests/binderUtilsHostTest.cpp @@ -34,7 +34,7 @@ TEST(UtilsHost, ExecuteImmediately) { auto result = execute({"echo", "foo"}, nullptr); ASSERT_THAT(result, Ok()); EXPECT_THAT(result->exitCode, Optional(EX_OK)); - EXPECT_EQ(result->stdout, "foo\n"); + EXPECT_EQ(result->stdoutStr, "foo\n"); } TEST(UtilsHost, ExecuteLongRunning) { @@ -44,7 +44,7 @@ TEST(UtilsHost, ExecuteLongRunning) { std::vector<std::string> args{"sh", "-c", "sleep 0.5 && echo -n f && sleep 0.5 && echo oo && sleep 1"}; auto result = execute(std::move(args), [](const CommandResult& commandResult) { - return android::base::EndsWith(commandResult.stdout, "\n"); + return android::base::EndsWith(commandResult.stdoutStr, "\n"); }); auto elapsed = std::chrono::system_clock::now() - now; auto elapsedMs = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count(); @@ -53,7 +53,7 @@ TEST(UtilsHost, ExecuteLongRunning) { ASSERT_THAT(result, Ok()); EXPECT_EQ(std::nullopt, result->exitCode); - EXPECT_EQ(result->stdout, "foo\n"); + EXPECT_EQ(result->stdoutStr, "foo\n"); } // ~CommandResult() called, child process is killed. @@ -70,7 +70,7 @@ TEST(UtilsHost, ExecuteLongRunning2) { std::vector<std::string> args{"sh", "-c", "sleep 2 && echo -n f && sleep 2 && echo oo && sleep 2"}; auto result = execute(std::move(args), [](const CommandResult& commandResult) { - return android::base::EndsWith(commandResult.stdout, "\n"); + return android::base::EndsWith(commandResult.stdoutStr, "\n"); }); auto elapsed = std::chrono::system_clock::now() - now; auto elapsedMs = std::chrono::duration_cast<std::chrono::milliseconds>(elapsed).count(); @@ -79,7 +79,7 @@ TEST(UtilsHost, ExecuteLongRunning2) { ASSERT_THAT(result, Ok()); EXPECT_EQ(std::nullopt, result->exitCode); - EXPECT_EQ(result->stdout, "foo\n"); + EXPECT_EQ(result->stdoutStr, "foo\n"); } // ~CommandResult() called, child process is killed. |