update_engine: pipe stderr individually in SycnronousExec
Currently, SyncronousExec pipes stderr to stdout which is fine but not
ideal. Specially we have an issue with vpd_get_value script that exits
with 0 even with underlying failures. This is problematic, because we
get the combined stdout/stderr of the command and since the exit code is
0 we assume the output is correct. Then, we create the XML request based
on this output but with stderr combined (too much junk) as the value of
an XML attribute. This causes update failure. Fortunately, vpd_get_value
correctly separates its children's stderr and stdout. So as long as we
don't combine both stdout and stderr into one stream, this error wil not
happen again anymore.
Also a few other nitpicks in this CL:
- Constructing the command for shutdown using simpler syntax.
- Logging the command before running it for all external subprocess runs.
BUG=chromium:1010306
TEST=sudo FEATURES=test emerge update_engine
Change-Id: Ia620afed814e4fe9ba24b1a0ad01680481c6ba7c
Reviewed-on: https://chromium-review.googlesource.com/c/aosp/platform/system/update_engine/+/1901886
Tested-by: Amin Hassani <ahassani@chromium.org>
Reviewed-by: Andrew Lassalle <lassalle@chromium.org>
Reviewed-by: Jae Hoon Kim <kimjae@chromium.org>
Commit-Queue: Amin Hassani <ahassani@chromium.org>
diff --git a/common/subprocess.h b/common/subprocess.h
index bac9e48..3eda8d5 100644
--- a/common/subprocess.h
+++ b/common/subprocess.h
@@ -88,14 +88,16 @@
// Executes a command synchronously. Returns true on success. If |stdout| is
// non-null, the process output is stored in it, otherwise the output is
- // logged. Note that stderr is redirected to stdout.
+ // logged.
static bool SynchronousExec(const std::vector<std::string>& cmd,
int* return_code,
- std::string* stdout);
+ std::string* stdout,
+ std::string* stderr);
static bool SynchronousExecFlags(const std::vector<std::string>& cmd,
uint32_t flags,
int* return_code,
- std::string* stdout);
+ std::string* stdout,
+ std::string* stderr);
// Gets the one instance.
static Subprocess& Get() { return *subprocess_singleton_; }