| Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // | 
 | 2 | // Copyright (C) 2012 The Android Open Source Project | 
 | 3 | // | 
 | 4 | // Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 5 | // you may not use this file except in compliance with the License. | 
 | 6 | // You may obtain a copy of the License at | 
 | 7 | // | 
 | 8 | //      http://www.apache.org/licenses/LICENSE-2.0 | 
 | 9 | // | 
 | 10 | // Unless required by applicable law or agreed to in writing, software | 
 | 11 | // distributed under the License is distributed on an "AS IS" BASIS, | 
 | 12 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 13 | // See the License for the specific language governing permissions and | 
 | 14 | // limitations under the License. | 
 | 15 | // | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 16 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 17 | #include "update_engine/common/subprocess.h" | 
| Alex Deymo | aab50e3 | 2014-11-10 19:55:35 -0800 | [diff] [blame] | 18 |  | 
| Alex Deymo | 5d52780 | 2014-07-18 14:24:13 -0700 | [diff] [blame] | 19 | #include <fcntl.h> | 
| Gilad Arnold | b6c562a | 2013-07-01 02:19:26 -0700 | [diff] [blame] | 20 | #include <poll.h> | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 21 | #include <sys/types.h> | 
 | 22 | #include <unistd.h> | 
| Gilad Arnold | 8e3f126 | 2013-01-08 14:59:54 -0800 | [diff] [blame] | 23 |  | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 24 | #include <set> | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 25 | #include <string> | 
 | 26 | #include <vector> | 
| Gilad Arnold | 8e3f126 | 2013-01-08 14:59:54 -0800 | [diff] [blame] | 27 |  | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 28 | #include <base/bind.h> | 
| Alex Deymo | 279bbab | 2016-02-12 16:26:17 -0800 | [diff] [blame] | 29 | #include <base/files/scoped_temp_dir.h> | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 30 | #include <base/location.h> | 
| Alex Deymo | 0b3db6b | 2015-08-10 15:19:37 -0700 | [diff] [blame] | 31 | #include <base/message_loop/message_loop.h> | 
| Alex Vakulenko | 75039d7 | 2014-03-25 12:36:28 -0700 | [diff] [blame] | 32 | #include <base/strings/string_util.h> | 
 | 33 | #include <base/strings/stringprintf.h> | 
 | 34 | #include <base/time/time.h> | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 35 | #include <brillo/message_loops/base_message_loop.h> | 
 | 36 | #include <brillo/message_loops/message_loop.h> | 
 | 37 | #include <brillo/message_loops/message_loop_utils.h> | 
 | 38 | #include <brillo/strings/string_utils.h> | 
| Alex Deymo | e384bb2 | 2016-03-29 17:23:33 -0700 | [diff] [blame] | 39 | #include <brillo/unittest_utils.h> | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 40 | #include <gtest/gtest.h> | 
| Gilad Arnold | 8e3f126 | 2013-01-08 14:59:54 -0800 | [diff] [blame] | 41 |  | 
| Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 42 | #include "update_engine/common/test_utils.h" | 
 | 43 | #include "update_engine/common/utils.h" | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 44 |  | 
| Gilad Arnold | 8e3f126 | 2013-01-08 14:59:54 -0800 | [diff] [blame] | 45 | using base::TimeDelta; | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 46 | using brillo::MessageLoop; | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 47 | using std::string; | 
 | 48 | using std::vector; | 
 | 49 |  | 
| Alex Deymo | 279bbab | 2016-02-12 16:26:17 -0800 | [diff] [blame] | 50 | namespace { | 
 | 51 |  | 
 | 52 | #ifdef __ANDROID__ | 
 | 53 | #define kBinPath "/system/bin" | 
 | 54 | #define kUsrBinPath "/system/bin" | 
 | 55 | #else | 
 | 56 | #define kBinPath "/bin" | 
 | 57 | #define kUsrBinPath "/usr/bin" | 
 | 58 | #endif  // __ANDROID__ | 
 | 59 |  | 
 | 60 | }  // namespace | 
 | 61 |  | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 62 | namespace chromeos_update_engine { | 
 | 63 |  | 
 | 64 | class SubprocessTest : public ::testing::Test { | 
 | 65 |  protected: | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 66 |   void SetUp() override { | 
 | 67 |     loop_.SetAsCurrent(); | 
| Alex Deymo | b7ca096 | 2014-10-01 17:58:07 -0700 | [diff] [blame] | 68 |     async_signal_handler_.Init(); | 
 | 69 |     subprocess_.Init(&async_signal_handler_); | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 70 |   } | 
 | 71 |  | 
| Alex Deymo | 0b3db6b | 2015-08-10 15:19:37 -0700 | [diff] [blame] | 72 |   base::MessageLoopForIO base_loop_; | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 73 |   brillo::BaseMessageLoop loop_{&base_loop_}; | 
 | 74 |   brillo::AsynchronousSignalHandler async_signal_handler_; | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 75 |   Subprocess subprocess_; | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 76 | }; | 
 | 77 |  | 
 | 78 | namespace { | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 79 |  | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 80 | void ExpectedResults(int expected_return_code, | 
 | 81 |                      const string& expected_output, | 
 | 82 |                      int return_code, | 
 | 83 |                      const string& output) { | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 84 |   EXPECT_EQ(expected_return_code, return_code); | 
 | 85 |   EXPECT_EQ(expected_output, output); | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 86 |   MessageLoop::current()->BreakLoop(); | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 87 | } | 
 | 88 |  | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 89 | void ExpectedEnvVars(int return_code, const string& output) { | 
| Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 90 |   EXPECT_EQ(0, return_code); | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 91 |   const std::set<string> allowed_envs = {"LD_LIBRARY_PATH", "PATH"}; | 
| Chih-Hung Hsieh | 5c6bb1d | 2016-07-27 13:33:15 -0700 | [diff] [blame] | 92 |   for (const string& key_value : brillo::string_utils::Split(output, "\n")) { | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 93 |     auto key_value_pair = | 
 | 94 |         brillo::string_utils::SplitAtFirst(key_value, "=", true); | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 95 |     EXPECT_NE(allowed_envs.end(), allowed_envs.find(key_value_pair.first)); | 
 | 96 |   } | 
| Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 97 |   MessageLoop::current()->BreakLoop(); | 
 | 98 | } | 
 | 99 |  | 
| Alex Deymo | e384bb2 | 2016-03-29 17:23:33 -0700 | [diff] [blame] | 100 | void ExpectedDataOnPipe(const Subprocess* subprocess, | 
 | 101 |                         pid_t* pid, | 
 | 102 |                         int child_fd, | 
 | 103 |                         const string& child_fd_data, | 
 | 104 |                         int expected_return_code, | 
 | 105 |                         int return_code, | 
 | 106 |                         const string& /* output */) { | 
 | 107 |   EXPECT_EQ(expected_return_code, return_code); | 
 | 108 |  | 
 | 109 |   // Verify that we can read the data from our end of |child_fd|. | 
 | 110 |   int fd = subprocess->GetPipeFd(*pid, child_fd); | 
 | 111 |   EXPECT_NE(-1, fd); | 
 | 112 |   vector<char> buf(child_fd_data.size() + 1); | 
 | 113 |   EXPECT_EQ(static_cast<ssize_t>(child_fd_data.size()), | 
 | 114 |             HANDLE_EINTR(read(fd, buf.data(), buf.size()))); | 
 | 115 |   EXPECT_EQ(child_fd_data, | 
 | 116 |             string(buf.begin(), buf.begin() + child_fd_data.size())); | 
 | 117 |  | 
 | 118 |   MessageLoop::current()->BreakLoop(); | 
 | 119 | } | 
 | 120 |  | 
| Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 121 | }  // namespace | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 122 |  | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 123 | TEST_F(SubprocessTest, IsASingleton) { | 
 | 124 |   EXPECT_EQ(&subprocess_, &Subprocess::Get()); | 
 | 125 | } | 
 | 126 |  | 
 | 127 | TEST_F(SubprocessTest, InactiveInstancesDontChangeTheSingleton) { | 
 | 128 |   std::unique_ptr<Subprocess> another_subprocess(new Subprocess()); | 
 | 129 |   EXPECT_EQ(&subprocess_, &Subprocess::Get()); | 
 | 130 |   another_subprocess.reset(); | 
 | 131 |   EXPECT_EQ(&subprocess_, &Subprocess::Get()); | 
 | 132 | } | 
 | 133 |  | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 134 | TEST_F(SubprocessTest, SimpleTest) { | 
| Alex Deymo | 279bbab | 2016-02-12 16:26:17 -0800 | [diff] [blame] | 135 |   EXPECT_TRUE(subprocess_.Exec({kBinPath "/false"}, | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 136 |                                base::Bind(&ExpectedResults, 1, ""))); | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 137 |   loop_.Run(); | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 138 | } | 
 | 139 |  | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 140 | TEST_F(SubprocessTest, EchoTest) { | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 141 |   EXPECT_TRUE(subprocess_.Exec( | 
| Alex Deymo | 279bbab | 2016-02-12 16:26:17 -0800 | [diff] [blame] | 142 |       {kBinPath "/sh", "-c", "echo this is stdout; echo this is stderr >&2"}, | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 143 |       base::Bind(&ExpectedResults, 0, "this is stdout\nthis is stderr\n"))); | 
| Alex Deymo | 29b8153 | 2015-07-09 11:51:49 -0700 | [diff] [blame] | 144 |   loop_.Run(); | 
 | 145 | } | 
 | 146 |  | 
 | 147 | TEST_F(SubprocessTest, StderrNotIncludedInOutputTest) { | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 148 |   EXPECT_TRUE(subprocess_.ExecFlags( | 
| Alex Deymo | 279bbab | 2016-02-12 16:26:17 -0800 | [diff] [blame] | 149 |       {kBinPath "/sh", "-c", "echo on stdout; echo on stderr >&2"}, | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 150 |       0, | 
| Alex Deymo | e384bb2 | 2016-03-29 17:23:33 -0700 | [diff] [blame] | 151 |       {}, | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 152 |       base::Bind(&ExpectedResults, 0, "on stdout\n"))); | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 153 |   loop_.Run(); | 
| Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 154 | } | 
 | 155 |  | 
| Alex Deymo | e384bb2 | 2016-03-29 17:23:33 -0700 | [diff] [blame] | 156 | TEST_F(SubprocessTest, PipeRedirectFdTest) { | 
 | 157 |   pid_t pid; | 
 | 158 |   pid = subprocess_.ExecFlags( | 
 | 159 |       {kBinPath "/sh", "-c", "echo on pipe >&3"}, | 
 | 160 |       0, | 
 | 161 |       {3}, | 
 | 162 |       base::Bind(&ExpectedDataOnPipe, &subprocess_, &pid, 3, "on pipe\n", 0)); | 
 | 163 |   EXPECT_NE(0, pid); | 
 | 164 |  | 
 | 165 |   // Wrong file descriptor values should return -1. | 
 | 166 |   EXPECT_EQ(-1, subprocess_.GetPipeFd(pid, 123)); | 
 | 167 |   loop_.Run(); | 
 | 168 |   // Calling GetPipeFd() after the callback runs is invalid. | 
 | 169 |   EXPECT_EQ(-1, subprocess_.GetPipeFd(pid, 3)); | 
 | 170 | } | 
 | 171 |  | 
 | 172 | // Test that a pipe file descriptor open in the parent is not open in the child. | 
 | 173 | TEST_F(SubprocessTest, PipeClosedWhenNotRedirectedTest) { | 
 | 174 |   brillo::ScopedPipe pipe; | 
| Alex Deymo | 279d572 | 2016-04-07 16:22:13 -0700 | [diff] [blame] | 175 |  | 
 | 176 |   // test_subprocess will return with the errno of fstat, which should be EBADF | 
 | 177 |   // if the passed file descriptor is closed in the child. | 
 | 178 |   const vector<string> cmd = { | 
 | 179 |       test_utils::GetBuildArtifactsPath("test_subprocess"), | 
 | 180 |       "fstat", | 
 | 181 |       std::to_string(pipe.writer)}; | 
| Alex Deymo | e384bb2 | 2016-03-29 17:23:33 -0700 | [diff] [blame] | 182 |   EXPECT_TRUE(subprocess_.ExecFlags( | 
| Alex Deymo | 279d572 | 2016-04-07 16:22:13 -0700 | [diff] [blame] | 183 |       cmd, 0, {}, base::Bind(&ExpectedResults, EBADF, ""))); | 
| Alex Deymo | e384bb2 | 2016-03-29 17:23:33 -0700 | [diff] [blame] | 184 |   loop_.Run(); | 
 | 185 | } | 
 | 186 |  | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 187 | TEST_F(SubprocessTest, EnvVarsAreFiltered) { | 
| Alex Deymo | 279bbab | 2016-02-12 16:26:17 -0800 | [diff] [blame] | 188 |   EXPECT_TRUE( | 
 | 189 |       subprocess_.Exec({kUsrBinPath "/env"}, base::Bind(&ExpectedEnvVars))); | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 190 |   loop_.Run(); | 
 | 191 | } | 
 | 192 |  | 
 | 193 | TEST_F(SubprocessTest, SynchronousTrueSearchsOnPath) { | 
 | 194 |   int rc = -1; | 
 | 195 |   EXPECT_TRUE(Subprocess::SynchronousExecFlags( | 
 | 196 |       {"true"}, Subprocess::kSearchPath, &rc, nullptr)); | 
 | 197 |   EXPECT_EQ(0, rc); | 
 | 198 | } | 
 | 199 |  | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 200 | TEST_F(SubprocessTest, SynchronousEchoTest) { | 
 | 201 |   vector<string> cmd = { | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 202 |       kBinPath "/sh", "-c", "echo -n stdout-here; echo -n stderr-there >&2"}; | 
| Darin Petkov | 85d02b7 | 2011-05-17 13:25:51 -0700 | [diff] [blame] | 203 |   int rc = -1; | 
 | 204 |   string stdout; | 
 | 205 |   ASSERT_TRUE(Subprocess::SynchronousExec(cmd, &rc, &stdout)); | 
 | 206 |   EXPECT_EQ(0, rc); | 
 | 207 |   EXPECT_EQ("stdout-herestderr-there", stdout); | 
 | 208 | } | 
 | 209 |  | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 210 | TEST_F(SubprocessTest, SynchronousEchoNoOutputTest) { | 
| Darin Petkov | 85d02b7 | 2011-05-17 13:25:51 -0700 | [diff] [blame] | 211 |   int rc = -1; | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 212 |   ASSERT_TRUE(Subprocess::SynchronousExec( | 
| Alex Deymo | 279bbab | 2016-02-12 16:26:17 -0800 | [diff] [blame] | 213 |       {kBinPath "/sh", "-c", "echo test"}, &rc, nullptr)); | 
| Darin Petkov | 85d02b7 | 2011-05-17 13:25:51 -0700 | [diff] [blame] | 214 |   EXPECT_EQ(0, rc); | 
 | 215 | } | 
 | 216 |  | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 217 | namespace { | 
| Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 218 | void CallbackBad(int return_code, const string& output) { | 
 | 219 |   ADD_FAILURE() << "should never be called."; | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 220 | } | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 221 | }  // namespace | 
 | 222 |  | 
| Alex Deymo | 279bbab | 2016-02-12 16:26:17 -0800 | [diff] [blame] | 223 | // Test that you can cancel a program that's already running. | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 224 | TEST_F(SubprocessTest, CancelTest) { | 
| Alex Deymo | 279bbab | 2016-02-12 16:26:17 -0800 | [diff] [blame] | 225 |   base::ScopedTempDir tempdir; | 
 | 226 |   ASSERT_TRUE(tempdir.CreateUniqueTempDir()); | 
| Hidehiko Abe | 2b9d241 | 2017-12-13 18:56:18 +0900 | [diff] [blame] | 227 |   string fifo_path = tempdir.GetPath().Append("fifo").value(); | 
| Alex Deymo | 279bbab | 2016-02-12 16:26:17 -0800 | [diff] [blame] | 228 |   EXPECT_EQ(0, mkfifo(fifo_path.c_str(), 0666)); | 
 | 229 |  | 
 | 230 |   // Start a process, make sure it is running and try to cancel it. We write | 
 | 231 |   // two bytes to the fifo, the first one marks that the program is running and | 
 | 232 |   // the second one marks that the process waited for a timeout and was not | 
 | 233 |   // killed. We should read the first byte but not the second one. | 
 | 234 |   vector<string> cmd = { | 
 | 235 |       kBinPath "/sh", | 
 | 236 |       "-c", | 
 | 237 |       base::StringPrintf( | 
| Ben Chan | 70a2119 | 2017-01-10 19:56:50 -0800 | [diff] [blame] | 238 |           // The 'sleep' launched below could be left behind as an orphaned | 
 | 239 |           // process when the 'sh' process is terminated by SIGTERM. As a | 
 | 240 |           // remedy, trap SIGTERM and kill the 'sleep' process, which requires | 
 | 241 |           // launching 'sleep' in background and then waiting for it. | 
 | 242 |           "cleanup() { kill \"${sleep_pid}\"; exit 0; }; " | 
 | 243 |           "trap cleanup TERM; " | 
 | 244 |           "sleep 60 & " | 
 | 245 |           "sleep_pid=$!; " | 
 | 246 |           "printf X >\"%s\"; " | 
 | 247 |           "wait; " | 
 | 248 |           "printf Y >\"%s\"; " | 
 | 249 |           "exit 1", | 
| Alex Deymo | 279bbab | 2016-02-12 16:26:17 -0800 | [diff] [blame] | 250 |           fifo_path.c_str(), | 
 | 251 |           fifo_path.c_str())}; | 
 | 252 |   uint32_t tag = Subprocess::Get().Exec(cmd, base::Bind(&CallbackBad)); | 
 | 253 |   EXPECT_NE(0U, tag); | 
 | 254 |  | 
 | 255 |   int fifo_fd = HANDLE_EINTR(open(fifo_path.c_str(), O_RDONLY)); | 
 | 256 |   EXPECT_GE(fifo_fd, 0); | 
 | 257 |  | 
 | 258 |   loop_.WatchFileDescriptor(FROM_HERE, | 
 | 259 |                             fifo_fd, | 
 | 260 |                             MessageLoop::WatchMode::kWatchRead, | 
 | 261 |                             false, | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 262 |                             base::Bind( | 
 | 263 |                                 [](int fifo_fd, uint32_t tag) { | 
 | 264 |                                   char c; | 
 | 265 |                                   EXPECT_EQ(1, | 
 | 266 |                                             HANDLE_EINTR(read(fifo_fd, &c, 1))); | 
 | 267 |                                   EXPECT_EQ('X', c); | 
 | 268 |                                   LOG(INFO) << "Killing tag " << tag; | 
 | 269 |                                   Subprocess::Get().KillExec(tag); | 
 | 270 |                                 }, | 
 | 271 |                                 fifo_fd, | 
 | 272 |                                 tag)); | 
| Alex Deymo | 279bbab | 2016-02-12 16:26:17 -0800 | [diff] [blame] | 273 |  | 
| Alex Deymo | 60ca1a7 | 2015-06-18 18:19:15 -0700 | [diff] [blame] | 274 |   // This test would leak a callback that runs when the child process exits | 
 | 275 |   // unless we wait for it to run. | 
| Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 276 |   brillo::MessageLoopRunUntil( | 
| Amin Hassani | b268959 | 2019-01-13 17:04:28 -0800 | [diff] [blame] | 277 |       &loop_, TimeDelta::FromSeconds(120), base::Bind([] { | 
 | 278 |         return Subprocess::Get().subprocess_records_.empty(); | 
 | 279 |       })); | 
| Alex Deymo | 279bbab | 2016-02-12 16:26:17 -0800 | [diff] [blame] | 280 |   EXPECT_TRUE(Subprocess::Get().subprocess_records_.empty()); | 
 | 281 |   // Check that there isn't anything else to read from the pipe. | 
 | 282 |   char c; | 
 | 283 |   EXPECT_EQ(0, HANDLE_EINTR(read(fifo_fd, &c, 1))); | 
 | 284 |   IGNORE_EINTR(close(fifo_fd)); | 
| adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 285 | } | 
 | 286 |  | 
 | 287 | }  // namespace chromeos_update_engine |