Rename stdout and stderr to stdout_str and stderr_str
Support building with musl libc by not reusing the stdout and
stderr names, which are macros in musl.
Bug: 190084016
Test: m USE_HOST_MUSL=true host-native
Change-Id: Ia8093f42ede166c77c04f5524d442de836bde43c
diff --git a/common/subprocess.cc b/common/subprocess.cc
index 023017b..a0cb9a7 100644
--- a/common/subprocess.cc
+++ b/common/subprocess.cc
@@ -124,7 +124,7 @@
bool eof;
bool ok = utils::ReadAll(
record->stdout_fd, buf, base::size(buf), &bytes_read, &eof);
- record->stdout.append(buf, bytes_read);
+ record->stdout_str.append(buf, bytes_read);
if (!ok || eof) {
// There was either an error or an EOF condition, so we are done watching
// the file descriptor.
@@ -152,11 +152,11 @@
LOG(INFO) << "Subprocess exited with si_status: " << info.si_status;
}
- if (!record->stdout.empty()) {
- LOG(INFO) << "Subprocess output:\n" << record->stdout;
+ if (!record->stdout_str.empty()) {
+ LOG(INFO) << "Subprocess output:\n" << record->stdout_str;
}
if (!record->callback.is_null()) {
- record->callback.Run(info.si_status, record->stdout);
+ record->callback.Run(info.si_status, record->stdout_str);
}
// Release and close all the pipes after calling the callback so our
// redirected pipes are still alive. Releasing the process first makes
@@ -230,29 +230,30 @@
bool Subprocess::SynchronousExec(const vector<string>& cmd,
int* return_code,
- string* stdout,
- string* stderr) {
+ string* stdout_str,
+ string* stderr_str) {
// The default for |SynchronousExec| is to use |kSearchPath| since the code
// relies on that.
- return SynchronousExecFlags(cmd, kSearchPath, return_code, stdout, stderr);
+ return SynchronousExecFlags(
+ cmd, kSearchPath, return_code, stdout_str, stderr_str);
}
bool Subprocess::SynchronousExecFlags(const vector<string>& cmd,
uint32_t flags,
int* return_code,
- string* stdout,
- string* stderr) {
+ string* stdout_str,
+ string* stderr_str) {
brillo::ProcessImpl proc;
if (!LaunchProcess(cmd, flags, {STDERR_FILENO}, &proc)) {
LOG(ERROR) << "Failed to launch subprocess";
return false;
}
- if (stdout) {
- stdout->clear();
+ if (stdout_str) {
+ stdout_str->clear();
}
- if (stderr) {
- stderr->clear();
+ if (stderr_str) {
+ stderr_str->clear();
}
// Read from both stdout and stderr individually.
@@ -267,8 +268,8 @@
stdout_closed = true;
if (rc < 0)
PLOG(ERROR) << "Reading from child's stdout";
- } else if (stdout != nullptr) {
- stdout->append(buffer.data(), rc);
+ } else if (stdout_str != nullptr) {
+ stdout_str->append(buffer.data(), rc);
}
}
@@ -278,8 +279,8 @@
stderr_closed = true;
if (rc < 0)
PLOG(ERROR) << "Reading from child's stderr";
- } else if (stderr != nullptr) {
- stderr->append(buffer.data(), rc);
+ } else if (stderr_str != nullptr) {
+ stderr_str->append(buffer.data(), rc);
}
}
}
@@ -299,9 +300,9 @@
SubprocessRecord* record = pid_record.second.get();
// Make sure we read any remaining process output.
OnStdoutReady(record);
- if (!record->stdout.empty()) {
+ if (!record->stdout_str.empty()) {
LOG(INFO) << "Subprocess(" << pid_record.first << ") output:\n"
- << record->stdout;
+ << record->stdout_str;
}
}
}
diff --git a/common/subprocess.h b/common/subprocess.h
index 2ed8b81..e59776a 100644
--- a/common/subprocess.h
+++ b/common/subprocess.h
@@ -91,18 +91,18 @@
// |output_pipes|, otherwise returns -1.
int GetPipeFd(pid_t pid, int fd) const;
- // Executes a command synchronously. Returns true on success. If |stdout| is
- // non-null, the process output is stored in it, otherwise the output is
+ // Executes a command synchronously. Returns true on success. If |stdout_str|
+ // is non-null, the process output is stored in it, otherwise the output is
// logged.
static bool SynchronousExec(const std::vector<std::string>& cmd,
int* return_code,
- std::string* stdout,
- std::string* stderr);
+ std::string* stdout_str,
+ std::string* stderr_str);
static bool SynchronousExecFlags(const std::vector<std::string>& cmd,
uint32_t flags,
int* return_code,
- std::string* stdout,
- std::string* stderr);
+ std::string* stdout_str,
+ std::string* stderr_str);
// Gets the one instance.
static Subprocess& Get() { return *subprocess_singleton_; }
@@ -131,7 +131,7 @@
std::unique_ptr<base::FileDescriptorWatcher::Controller> stdout_controller;
int stdout_fd{-1};
- std::string stdout;
+ std::string stdout_str;
};
// Callback which runs whenever there is input available on the subprocess
diff --git a/payload_generator/squashfs_filesystem.cc b/payload_generator/squashfs_filesystem.cc
index a41e283..16b26eb 100644
--- a/payload_generator/squashfs_filesystem.cc
+++ b/payload_generator/squashfs_filesystem.cc
@@ -76,12 +76,12 @@
// Run unsquashfs to get the system file map.
// unsquashfs -m <map-file> <squashfs-file>
vector<string> cmd = {"unsquashfs", "-m", map_file.path(), sqfs_path};
- string stdout, stderr;
+ string stdout_str, stderr_str;
int exit_code;
- if (!Subprocess::SynchronousExec(cmd, &exit_code, &stdout, &stderr) ||
+ if (!Subprocess::SynchronousExec(cmd, &exit_code, &stdout_str, &stderr_str) ||
exit_code != 0) {
LOG(ERROR) << "Failed to run `unsquashfs -m` with stdout content: "
- << stdout << " and stderr content: " << stderr;
+ << stdout_str << " and stderr content: " << stderr_str;
return false;
}
TEST_AND_RETURN_FALSE(utils::ReadFile(map_file.path(), map));
@@ -104,12 +104,12 @@
unsquash_dir.GetPath().value(),
sqfs_path,
kUpdateEngineConf};
- string stdout, stderr;
+ string stdout_str, stderr_str;
int exit_code;
- if (!Subprocess::SynchronousExec(cmd, &exit_code, &stdout, &stderr) ||
+ if (!Subprocess::SynchronousExec(cmd, &exit_code, &stdout_str, &stderr_str) ||
exit_code != 0) {
PLOG(ERROR) << "Failed to unsquashfs etc/update_engine.conf with stdout: "
- << stdout << " and stderr: " << stderr;
+ << stdout_str << " and stderr: " << stderr_str;
return false;
}