Alex Deymo | aea4c1c | 2015-08-19 20:24:43 -0700 | [diff] [blame] | 1 | // |
| 2 | // Copyright (C) 2011 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/payload_consumer/postinstall_runner_action.h" |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 18 | |
Alex Deymo | 0d29854 | 2016-03-30 18:31:49 -0700 | [diff] [blame] | 19 | #include <fcntl.h> |
Alex Deymo | d15c546 | 2016-03-09 18:11:12 -0800 | [diff] [blame] | 20 | #include <signal.h> |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 21 | #include <stdlib.h> |
Alex Vakulenko | 44cab30 | 2014-07-23 13:12:15 -0700 | [diff] [blame] | 22 | #include <sys/mount.h> |
Alex Deymo | d15c546 | 2016-03-09 18:11:12 -0800 | [diff] [blame] | 23 | #include <sys/types.h> |
Alex Deymo | 0d29854 | 2016-03-30 18:31:49 -0700 | [diff] [blame] | 24 | #include <unistd.h> |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 25 | |
Alex Deymo | 44b3567 | 2016-04-05 17:57:48 -0700 | [diff] [blame^] | 26 | #include <cmath> |
| 27 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 28 | #include <base/files/file_path.h> |
| 29 | #include <base/files/file_util.h> |
Alex Deymo | d15c546 | 2016-03-09 18:11:12 -0800 | [diff] [blame] | 30 | #include <base/logging.h> |
Alex Deymo | 0d29854 | 2016-03-30 18:31:49 -0700 | [diff] [blame] | 31 | #include <base/strings/string_split.h> |
Alex Deymo | 390efed | 2016-02-18 11:00:40 -0800 | [diff] [blame] | 32 | #include <base/strings/string_util.h> |
Alex Deymo | 461b259 | 2015-07-24 20:10:52 -0700 | [diff] [blame] | 33 | |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 34 | #include "update_engine/common/action_processor.h" |
Alex Deymo | b15a0b8 | 2015-11-25 20:30:40 -0300 | [diff] [blame] | 35 | #include "update_engine/common/boot_control_interface.h" |
Alex Deymo | 14dbd33 | 2016-03-01 18:55:54 -0800 | [diff] [blame] | 36 | #include "update_engine/common/platform_constants.h" |
Alex Deymo | 39910dc | 2015-11-09 17:04:30 -0800 | [diff] [blame] | 37 | #include "update_engine/common/subprocess.h" |
| 38 | #include "update_engine/common/utils.h" |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 39 | |
Alex Deymo | 0d29854 | 2016-03-30 18:31:49 -0700 | [diff] [blame] | 40 | namespace { |
| 41 | |
| 42 | // The file descriptor number from the postinstall program's perspective where |
| 43 | // it can report status updates. This can be any number greater than 2 (stderr), |
| 44 | // but must be kept in sync with the "bin/postinst_progress" defined in the |
| 45 | // sample_images.sh file. |
| 46 | const int kPostinstallStatusFd = 3; |
| 47 | |
| 48 | } // namespace |
| 49 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 50 | namespace chromeos_update_engine { |
| 51 | |
Alex Deymo | 0d29854 | 2016-03-30 18:31:49 -0700 | [diff] [blame] | 52 | using brillo::MessageLoop; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 53 | using std::string; |
Andrew de los Reyes | f971443 | 2010-05-04 10:21:23 -0700 | [diff] [blame] | 54 | using std::vector; |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 55 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 56 | void PostinstallRunnerAction::PerformAction() { |
| 57 | CHECK(HasInputObject()); |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 58 | install_plan_ = GetInputObject(); |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 59 | |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 60 | if (install_plan_.powerwash_required) { |
Gilad Arnold | 30dedd8 | 2013-07-03 06:19:09 -0700 | [diff] [blame] | 61 | if (utils::CreatePowerwashMarkerFile(powerwash_marker_file_)) { |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 62 | powerwash_marker_created_ = true; |
| 63 | } else { |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 64 | return CompletePostinstall(ErrorCode::kPostinstallPowerwashError); |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 65 | } |
| 66 | } |
| 67 | |
Alex Deymo | 0d29854 | 2016-03-30 18:31:49 -0700 | [diff] [blame] | 68 | // Initialize all the partition weights. |
| 69 | partition_weight_.resize(install_plan_.partitions.size()); |
| 70 | total_weight_ = 0; |
| 71 | for (size_t i = 0; i < install_plan_.partitions.size(); ++i) { |
| 72 | // TODO(deymo): This code sets the weight to all the postinstall commands, |
| 73 | // but we could remember how long they took in the past and use those |
| 74 | // values. |
| 75 | partition_weight_[i] = install_plan_.partitions[i].run_postinstall; |
| 76 | total_weight_ += partition_weight_[i]; |
| 77 | } |
| 78 | accumulated_weight_ = 0; |
| 79 | ReportProgress(0); |
| 80 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 81 | PerformPartitionPostinstall(); |
| 82 | } |
| 83 | |
| 84 | void PostinstallRunnerAction::PerformPartitionPostinstall() { |
Alex Deymo | 390efed | 2016-02-18 11:00:40 -0800 | [diff] [blame] | 85 | if (install_plan_.download_url.empty()) { |
| 86 | LOG(INFO) << "Skipping post-install during rollback"; |
| 87 | return CompletePostinstall(ErrorCode::kSuccess); |
| 88 | } |
| 89 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 90 | // Skip all the partitions that don't have a post-install step. |
| 91 | while (current_partition_ < install_plan_.partitions.size() && |
| 92 | !install_plan_.partitions[current_partition_].run_postinstall) { |
| 93 | VLOG(1) << "Skipping post-install on partition " |
| 94 | << install_plan_.partitions[current_partition_].name; |
| 95 | current_partition_++; |
| 96 | } |
| 97 | if (current_partition_ == install_plan_.partitions.size()) |
| 98 | return CompletePostinstall(ErrorCode::kSuccess); |
| 99 | |
| 100 | const InstallPlan::Partition& partition = |
| 101 | install_plan_.partitions[current_partition_]; |
| 102 | |
| 103 | const string mountable_device = |
| 104 | utils::MakePartitionNameForMount(partition.target_path); |
| 105 | if (mountable_device.empty()) { |
| 106 | LOG(ERROR) << "Cannot make mountable device from " << partition.target_path; |
| 107 | return CompletePostinstall(ErrorCode::kPostinstallRunnerError); |
| 108 | } |
| 109 | |
| 110 | // Perform post-install for the current_partition_ partition. At this point we |
| 111 | // need to call CompletePartitionPostinstall to complete the operation and |
| 112 | // cleanup. |
Alex Deymo | 390efed | 2016-02-18 11:00:40 -0800 | [diff] [blame] | 113 | #ifdef __ANDROID__ |
| 114 | fs_mount_dir_ = "/postinstall"; |
| 115 | #else // __ANDROID__ |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 116 | TEST_AND_RETURN( |
Alex Deymo | 390efed | 2016-02-18 11:00:40 -0800 | [diff] [blame] | 117 | utils::MakeTempDirectory("au_postint_mount.XXXXXX", &fs_mount_dir_)); |
| 118 | #endif // __ANDROID__ |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 119 | |
Alex Deymo | cbc2274 | 2016-03-04 17:53:02 -0800 | [diff] [blame] | 120 | base::FilePath postinstall_path(partition.postinstall_path); |
| 121 | if (postinstall_path.IsAbsolute()) { |
| 122 | LOG(ERROR) << "Invalid absolute path passed to postinstall, use a relative" |
| 123 | "path instead: " |
| 124 | << partition.postinstall_path; |
| 125 | return CompletePostinstall(ErrorCode::kPostinstallRunnerError); |
| 126 | } |
| 127 | |
| 128 | string abs_path = |
| 129 | base::FilePath(fs_mount_dir_).Append(postinstall_path).value(); |
Alex Deymo | 390efed | 2016-02-18 11:00:40 -0800 | [diff] [blame] | 130 | if (!base::StartsWith( |
| 131 | abs_path, fs_mount_dir_, base::CompareCase::SENSITIVE)) { |
| 132 | LOG(ERROR) << "Invalid relative postinstall path: " |
| 133 | << partition.postinstall_path; |
| 134 | return CompletePostinstall(ErrorCode::kPostinstallRunnerError); |
| 135 | } |
| 136 | |
| 137 | if (!utils::MountFilesystem(mountable_device, |
| 138 | fs_mount_dir_, |
| 139 | MS_RDONLY, |
Alex Deymo | 14dbd33 | 2016-03-01 18:55:54 -0800 | [diff] [blame] | 140 | partition.filesystem_type, |
| 141 | constants::kPostinstallMountOptions)) { |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 142 | return CompletePartitionPostinstall( |
| 143 | 1, "Error mounting the device " + mountable_device); |
| 144 | } |
| 145 | |
Alex Deymo | 390efed | 2016-02-18 11:00:40 -0800 | [diff] [blame] | 146 | LOG(INFO) << "Performing postinst (" << partition.postinstall_path << " at " |
| 147 | << abs_path << ") installed on device " << partition.target_path |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 148 | << " and mountable device " << mountable_device; |
| 149 | |
Alex Deymo | 032e772 | 2014-03-25 17:53:56 -0700 | [diff] [blame] | 150 | // Logs the file format of the postinstall script we are about to run. This |
| 151 | // will help debug when the postinstall script doesn't match the architecture |
| 152 | // of our build. |
Alex Deymo | 390efed | 2016-02-18 11:00:40 -0800 | [diff] [blame] | 153 | LOG(INFO) << "Format file for new " << partition.postinstall_path |
| 154 | << " is: " << utils::GetFileFormat(abs_path); |
Alex Deymo | 032e772 | 2014-03-25 17:53:56 -0700 | [diff] [blame] | 155 | |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 156 | // Runs the postinstall script asynchronously to free up the main loop while |
| 157 | // it's running. |
Alex Deymo | 0d29854 | 2016-03-30 18:31:49 -0700 | [diff] [blame] | 158 | vector<string> command = {abs_path}; |
| 159 | #ifdef __ANDROID__ |
| 160 | // In Brillo and Android, we pass the slot number and status fd. |
| 161 | command.push_back(std::to_string(install_plan_.target_slot)); |
| 162 | command.push_back(std::to_string(kPostinstallStatusFd)); |
| 163 | #else |
| 164 | // Chrome OS postinstall expects the target rootfs as the first parameter. |
| 165 | command.push_back(partition.target_path); |
| 166 | #endif // __ANDROID__ |
| 167 | |
| 168 | current_command_ = Subprocess::Get().ExecFlags( |
Alex Deymo | d15c546 | 2016-03-09 18:11:12 -0800 | [diff] [blame] | 169 | command, |
Alex Deymo | 0d29854 | 2016-03-30 18:31:49 -0700 | [diff] [blame] | 170 | Subprocess::kRedirectStderrToStdout, |
| 171 | {kPostinstallStatusFd}, |
Alex Deymo | d15c546 | 2016-03-09 18:11:12 -0800 | [diff] [blame] | 172 | base::Bind(&PostinstallRunnerAction::CompletePartitionPostinstall, |
| 173 | base::Unretained(this))); |
| 174 | // Subprocess::Exec should never return a negative process id. |
| 175 | CHECK_GE(current_command_, 0); |
| 176 | |
Alex Deymo | 0d29854 | 2016-03-30 18:31:49 -0700 | [diff] [blame] | 177 | if (!current_command_) { |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 178 | CompletePartitionPostinstall(1, "Postinstall didn't launch"); |
Alex Deymo | 0d29854 | 2016-03-30 18:31:49 -0700 | [diff] [blame] | 179 | return; |
| 180 | } |
| 181 | |
| 182 | // Monitor the status file descriptor. |
| 183 | progress_fd_ = |
| 184 | Subprocess::Get().GetPipeFd(current_command_, kPostinstallStatusFd); |
| 185 | int fd_flags = fcntl(progress_fd_, F_GETFL, 0) | O_NONBLOCK; |
| 186 | if (HANDLE_EINTR(fcntl(progress_fd_, F_SETFL, fd_flags)) < 0) { |
| 187 | PLOG(ERROR) << "Unable to set non-blocking I/O mode on fd " << progress_fd_; |
| 188 | } |
| 189 | |
| 190 | progress_task_ = MessageLoop::current()->WatchFileDescriptor( |
| 191 | FROM_HERE, |
| 192 | progress_fd_, |
| 193 | MessageLoop::WatchMode::kWatchRead, |
| 194 | true, |
| 195 | base::Bind(&PostinstallRunnerAction::OnProgressFdReady, |
| 196 | base::Unretained(this))); |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 197 | } |
| 198 | |
Alex Deymo | 0d29854 | 2016-03-30 18:31:49 -0700 | [diff] [blame] | 199 | void PostinstallRunnerAction::OnProgressFdReady() { |
| 200 | char buf[1024]; |
| 201 | size_t bytes_read; |
| 202 | do { |
| 203 | bytes_read = 0; |
| 204 | bool eof; |
| 205 | bool ok = |
| 206 | utils::ReadAll(progress_fd_, buf, arraysize(buf), &bytes_read, &eof); |
| 207 | progress_buffer_.append(buf, bytes_read); |
| 208 | // Process every line. |
| 209 | vector<string> lines = base::SplitString( |
| 210 | progress_buffer_, "\n", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 211 | if (!lines.empty()) { |
| 212 | progress_buffer_ = lines.back(); |
| 213 | lines.pop_back(); |
| 214 | for (const auto& line : lines) { |
| 215 | ProcessProgressLine(line); |
| 216 | } |
| 217 | } |
| 218 | if (!ok || eof) { |
| 219 | // There was either an error or an EOF condition, so we are done watching |
| 220 | // the file descriptor. |
| 221 | MessageLoop::current()->CancelTask(progress_task_); |
| 222 | progress_task_ = MessageLoop::kTaskIdNull; |
| 223 | return; |
| 224 | } |
| 225 | } while (bytes_read); |
| 226 | } |
| 227 | |
| 228 | bool PostinstallRunnerAction::ProcessProgressLine(const string& line) { |
| 229 | double frac = 0; |
| 230 | if (sscanf(line.c_str(), "global_progress %lf", &frac) == 1) { |
| 231 | ReportProgress(frac); |
| 232 | return true; |
| 233 | } |
| 234 | |
| 235 | return false; |
| 236 | } |
| 237 | |
| 238 | void PostinstallRunnerAction::ReportProgress(double frac) { |
| 239 | if (!delegate_) |
| 240 | return; |
| 241 | if (current_partition_ >= partition_weight_.size()) { |
| 242 | delegate_->ProgressUpdate(1.); |
| 243 | return; |
| 244 | } |
Alex Deymo | 44b3567 | 2016-04-05 17:57:48 -0700 | [diff] [blame^] | 245 | if (!std::isfinite(frac) || frac < 0) |
Alex Deymo | 0d29854 | 2016-03-30 18:31:49 -0700 | [diff] [blame] | 246 | frac = 0; |
| 247 | if (frac > 1) |
| 248 | frac = 1; |
| 249 | double postinst_action_progress = |
| 250 | (accumulated_weight_ + partition_weight_[current_partition_] * frac) / |
| 251 | total_weight_; |
| 252 | delegate_->ProgressUpdate(postinst_action_progress); |
| 253 | } |
| 254 | |
| 255 | void PostinstallRunnerAction::Cleanup() { |
Alex Deymo | 390efed | 2016-02-18 11:00:40 -0800 | [diff] [blame] | 256 | utils::UnmountFilesystem(fs_mount_dir_); |
Alex Deymo | d15c546 | 2016-03-09 18:11:12 -0800 | [diff] [blame] | 257 | #ifndef __ANDROID__ |
Alex Deymo | 390efed | 2016-02-18 11:00:40 -0800 | [diff] [blame] | 258 | if (!base::DeleteFile(base::FilePath(fs_mount_dir_), false)) { |
| 259 | PLOG(WARNING) << "Not removing temporary mountpoint " << fs_mount_dir_; |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 260 | } |
Alex Deymo | d15c546 | 2016-03-09 18:11:12 -0800 | [diff] [blame] | 261 | #endif // !__ANDROID__ |
Alex Deymo | 390efed | 2016-02-18 11:00:40 -0800 | [diff] [blame] | 262 | fs_mount_dir_.clear(); |
Alex Deymo | 0d29854 | 2016-03-30 18:31:49 -0700 | [diff] [blame] | 263 | |
| 264 | progress_fd_ = -1; |
| 265 | if (progress_task_ != MessageLoop::kTaskIdNull) { |
| 266 | MessageLoop::current()->CancelTask(progress_task_); |
| 267 | progress_task_ = MessageLoop::kTaskIdNull; |
| 268 | } |
| 269 | progress_buffer_.clear(); |
Alex Deymo | d15c546 | 2016-03-09 18:11:12 -0800 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | void PostinstallRunnerAction::CompletePartitionPostinstall( |
| 273 | int return_code, const string& output) { |
| 274 | current_command_ = 0; |
Alex Deymo | 0d29854 | 2016-03-30 18:31:49 -0700 | [diff] [blame] | 275 | Cleanup(); |
Alex Deymo | 31d95ac | 2015-09-17 11:56:18 -0700 | [diff] [blame] | 276 | |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 277 | if (return_code != 0) { |
| 278 | LOG(ERROR) << "Postinst command failed with code: " << return_code; |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 279 | ErrorCode error_code = ErrorCode::kPostinstallRunnerError; |
Jay Srinivasan | 1c0fe79 | 2013-03-28 16:45:25 -0700 | [diff] [blame] | 280 | |
Andrew de los Reyes | fe57d54 | 2011-06-07 09:00:36 -0700 | [diff] [blame] | 281 | if (return_code == 3) { |
Andrew de los Reyes | c1d5c93 | 2011-04-20 17:15:47 -0700 | [diff] [blame] | 282 | // This special return code means that we tried to update firmware, |
| 283 | // but couldn't because we booted from FW B, and we need to reboot |
| 284 | // to get back to FW A. |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 285 | error_code = ErrorCode::kPostinstallBootedFromFirmwareB; |
Andrew de los Reyes | c1d5c93 | 2011-04-20 17:15:47 -0700 | [diff] [blame] | 286 | } |
Don Garrett | 81018e0 | 2013-07-30 18:46:31 -0700 | [diff] [blame] | 287 | |
| 288 | if (return_code == 4) { |
| 289 | // This special return code means that we tried to update firmware, |
| 290 | // but couldn't because we booted from FW B, and we need to reboot |
| 291 | // to get back to FW A. |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 292 | error_code = ErrorCode::kPostinstallFirmwareRONotUpdatable; |
Don Garrett | 81018e0 | 2013-07-30 18:46:31 -0700 | [diff] [blame] | 293 | } |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 294 | return CompletePostinstall(error_code); |
| 295 | } |
Alex Deymo | 0d29854 | 2016-03-30 18:31:49 -0700 | [diff] [blame] | 296 | accumulated_weight_ += partition_weight_[current_partition_]; |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 297 | current_partition_++; |
Alex Deymo | 0d29854 | 2016-03-30 18:31:49 -0700 | [diff] [blame] | 298 | ReportProgress(0); |
| 299 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 300 | PerformPartitionPostinstall(); |
| 301 | } |
| 302 | |
| 303 | void PostinstallRunnerAction::CompletePostinstall(ErrorCode error_code) { |
| 304 | // We only attempt to mark the new slot as active if all the postinstall |
| 305 | // steps succeeded. |
| 306 | if (error_code == ErrorCode::kSuccess && |
Alex Deymo | b15a0b8 | 2015-11-25 20:30:40 -0300 | [diff] [blame] | 307 | !boot_control_->SetActiveBootSlot(install_plan_.target_slot)) { |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 308 | error_code = ErrorCode::kPostinstallRunnerError; |
| 309 | } |
| 310 | |
| 311 | ScopedActionCompleter completer(processor_, this); |
Alex Deymo | cbc2274 | 2016-03-04 17:53:02 -0800 | [diff] [blame] | 312 | completer.set_code(error_code); |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 313 | |
| 314 | if (error_code != ErrorCode::kSuccess) { |
| 315 | LOG(ERROR) << "Postinstall action failed."; |
| 316 | |
| 317 | // Undo any changes done to trigger Powerwash using clobber-state. |
| 318 | if (powerwash_marker_created_) |
| 319 | utils::DeletePowerwashMarkerFile(powerwash_marker_file_); |
Don Garrett | 81018e0 | 2013-07-30 18:46:31 -0700 | [diff] [blame] | 320 | |
Darin Petkov | 6f03a3b | 2010-11-10 14:27:14 -0800 | [diff] [blame] | 321 | return; |
| 322 | } |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 323 | |
Alex Deymo | e5e5fe9 | 2015-10-05 09:28:19 -0700 | [diff] [blame] | 324 | LOG(INFO) << "All post-install commands succeeded"; |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 325 | if (HasOutputPipe()) { |
| 326 | SetOutputObject(install_plan_); |
| 327 | } |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 328 | } |
| 329 | |
Alex Deymo | d15c546 | 2016-03-09 18:11:12 -0800 | [diff] [blame] | 330 | void PostinstallRunnerAction::SuspendAction() { |
| 331 | if (!current_command_) |
| 332 | return; |
| 333 | if (kill(current_command_, SIGSTOP) != 0) { |
| 334 | PLOG(ERROR) << "Couldn't pause child process " << current_command_; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | void PostinstallRunnerAction::ResumeAction() { |
| 339 | if (!current_command_) |
| 340 | return; |
| 341 | if (kill(current_command_, SIGCONT) != 0) { |
| 342 | PLOG(ERROR) << "Couldn't resume child process " << current_command_; |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | void PostinstallRunnerAction::TerminateProcessing() { |
| 347 | if (!current_command_) |
| 348 | return; |
| 349 | // Calling KillExec() will discard the callback we registered and therefore |
| 350 | // the unretained reference to this object. |
| 351 | Subprocess::Get().KillExec(current_command_); |
| 352 | current_command_ = 0; |
Alex Deymo | 0d29854 | 2016-03-30 18:31:49 -0700 | [diff] [blame] | 353 | Cleanup(); |
Alex Deymo | d15c546 | 2016-03-09 18:11:12 -0800 | [diff] [blame] | 354 | } |
| 355 | |
adlr@google.com | 3defe6a | 2009-12-04 20:57:17 +0000 | [diff] [blame] | 356 | } // namespace chromeos_update_engine |