summaryrefslogtreecommitdiff
path: root/common/subprocess_unittest.cc
diff options
context:
space:
mode:
authorAmin Hassani <ahassani@chromium.org>2019-11-06 11:12:28 -0800
committerCommit Bot <commit-bot@chromium.org>2019-11-07 20:51:22 +0000
commit3a4caa13a26ad50e6b742b881baba0a2eed49bd0 (patch)
tree3d9752ba4ed7aa7d61605e6b878426c29e897396 /common/subprocess_unittest.cc
parent2cbb069d65b1da20b3323022e12fe863bc0b98d0 (diff)
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>
Diffstat (limited to 'common/subprocess_unittest.cc')
-rw-r--r--common/subprocess_unittest.cc11
1 files changed, 6 insertions, 5 deletions
diff --git a/common/subprocess_unittest.cc b/common/subprocess_unittest.cc
index 104ef419..8dbaa0b2 100644
--- a/common/subprocess_unittest.cc
+++ b/common/subprocess_unittest.cc
@@ -193,7 +193,7 @@ TEST_F(SubprocessTest, EnvVarsAreFiltered) {
TEST_F(SubprocessTest, SynchronousTrueSearchsOnPath) {
int rc = -1;
EXPECT_TRUE(Subprocess::SynchronousExecFlags(
- {"true"}, Subprocess::kSearchPath, &rc, nullptr));
+ {"true"}, Subprocess::kSearchPath, &rc, nullptr, nullptr));
EXPECT_EQ(0, rc);
}
@@ -201,16 +201,17 @@ TEST_F(SubprocessTest, SynchronousEchoTest) {
vector<string> cmd = {
kBinPath "/sh", "-c", "echo -n stdout-here; echo -n stderr-there >&2"};
int rc = -1;
- string stdout;
- ASSERT_TRUE(Subprocess::SynchronousExec(cmd, &rc, &stdout));
+ string stdout, stderr;
+ ASSERT_TRUE(Subprocess::SynchronousExec(cmd, &rc, &stdout, &stderr));
EXPECT_EQ(0, rc);
- EXPECT_EQ("stdout-herestderr-there", stdout);
+ EXPECT_EQ("stdout-here", stdout);
+ EXPECT_EQ("stderr-there", stderr);
}
TEST_F(SubprocessTest, SynchronousEchoNoOutputTest) {
int rc = -1;
ASSERT_TRUE(Subprocess::SynchronousExec(
- {kBinPath "/sh", "-c", "echo test"}, &rc, nullptr));
+ {kBinPath "/sh", "-c", "echo test"}, &rc, nullptr, nullptr));
EXPECT_EQ(0, rc);
}