update_engine: Watch file descriptors using chromeos::MessageLoop.
This patch removes all the calls to g_io_*() functions used to create
io_channels from a file descriptor and watch for them in the main loop.
Instead, we use the chromeos::MessageLoop backed with the glib
implementation.
This patch also removes the duplicated process handling work done in
P2PManager and uses the common Subprocess class instead.
BUG=chromium:499886
TEST=Added and updated unittests.
Change-Id: Ia093b060d2396325fce69b2bbdb62957ba7bfbc6
Reviewed-on: https://chromium-review.googlesource.com/284593
Tested-by: Alex Deymo <[email protected]>
Reviewed-by: Alex Vakulenko <[email protected]>
Commit-Queue: Alex Deymo <[email protected]>
Trybot-Ready: Alex Deymo <[email protected]>
diff --git a/subprocess_unittest.cc b/subprocess_unittest.cc
index 37dea05..dba9e6c 100644
--- a/subprocess_unittest.cc
+++ b/subprocess_unittest.cc
@@ -68,29 +68,40 @@
MessageLoop::current()->BreakLoop();
}
+void CallbackStdoutOnlyEcho(int return_code,
+ const string& output,
+ void* /* unused */) {
+ EXPECT_EQ(0, return_code);
+ EXPECT_NE(string::npos, output.find("on stdout"));
+ EXPECT_EQ(string::npos, output.find("on stderr"));
+ MessageLoop::current()->BreakLoop();
+}
+
} // namespace
TEST_F(SubprocessTest, SimpleTest) {
- loop_.PostTask(
- FROM_HERE,
- base::Bind([] {
- Subprocess::Get().Exec(vector<string>{"/bin/false"}, Callback, nullptr);
- }));
+ Subprocess::Get().Exec(vector<string>{"/bin/false"}, Callback, nullptr);
loop_.Run();
}
TEST_F(SubprocessTest, EchoTest) {
- loop_.PostTask(
- FROM_HERE,
- base::Bind([] {
- Subprocess::Get().Exec(
- vector<string>{
- "/bin/sh",
- "-c",
- "echo this is stdout; echo this is stderr > /dev/stderr"},
- CallbackEcho,
- nullptr);
- }));
+ Subprocess::Get().Exec(
+ vector<string>{
+ "/bin/sh",
+ "-c",
+ "echo this is stdout; echo this is stderr > /dev/stderr"},
+ CallbackEcho,
+ nullptr);
+ loop_.Run();
+}
+
+TEST_F(SubprocessTest, StderrNotIncludedInOutputTest) {
+ Subprocess::Get().ExecFlags(
+ vector<string>{"/bin/sh", "-c", "echo on stdout; echo on stderr >&2"},
+ static_cast<GSpawnFlags>(0),
+ false, // don't redirect stderr
+ CallbackStdoutOnlyEcho,
+ nullptr);
loop_.Run();
}
@@ -107,10 +118,7 @@
}
TEST_F(SubprocessTest, SynchronousEchoNoOutputTest) {
- vector<string> cmd = {
- "/bin/sh",
- "-c",
- "echo test"};
+ vector<string> cmd = {"/bin/sh", "-c", "echo test"};
int rc = -1;
ASSERT_TRUE(Subprocess::SynchronousExec(cmd, &rc, nullptr));
EXPECT_EQ(0, rc);
@@ -176,7 +184,7 @@
remove(temp_file_name);
CHECK_GT(local_server_port, 0);
LOG(INFO) << "server listening on port " << local_server_port;
- Subprocess::Get().CancelExec(tag);
+ Subprocess::Get().KillExec(tag);
}
void ExitWhenDone(bool* spawned) {