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 | // |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 16 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 17 | #include <inttypes.h> |
| 18 | #include <sysexits.h> |
| 19 | #include <unistd.h> |
| 20 | |
Casey Dahlin | e844c1a | 2015-12-16 14:30:58 -0800 | [diff] [blame] | 21 | #include <memory> |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 22 | #include <string> |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 23 | #include <vector> |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 24 | |
Amin Hassani | 1a53ba0 | 2017-07-28 15:03:14 -0700 | [diff] [blame] | 25 | #include <base/bind.h> |
| 26 | #include <base/command_line.h> |
| 27 | #include <base/logging.h> |
| 28 | #include <base/macros.h> |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 29 | #include <base/strings/string_split.h> |
Amin Hassani | 1a53ba0 | 2017-07-28 15:03:14 -0700 | [diff] [blame] | 30 | #include <base/threading/platform_thread.h> |
| 31 | #include <brillo/daemons/daemon.h> |
| 32 | #include <brillo/flag_helper.h> |
| 33 | |
Alex Deymo | 9a06922 | 2016-03-02 16:14:42 -0800 | [diff] [blame] | 34 | #include "update_engine/client.h" |
Shuqian Zhao | 2997173 | 2016-02-05 11:29:32 -0800 | [diff] [blame] | 35 | #include "update_engine/common/error_code.h" |
| 36 | #include "update_engine/common/error_code_utils.h" |
Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 37 | #include "update_engine/omaha_utils.h" |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 38 | #include "update_engine/status_update_handler.h" |
| 39 | #include "update_engine/update_status.h" |
Alex Deymo | 5f52811 | 2016-01-27 23:32:36 -0800 | [diff] [blame] | 40 | #include "update_engine/update_status_utils.h" |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 41 | |
Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 42 | using chromeos_update_engine::EolStatus; |
Shuqian Zhao | 2997173 | 2016-02-05 11:29:32 -0800 | [diff] [blame] | 43 | using chromeos_update_engine::ErrorCode; |
Alex Deymo | 9a06922 | 2016-03-02 16:14:42 -0800 | [diff] [blame] | 44 | using chromeos_update_engine::UpdateStatusToString; |
| 45 | using chromeos_update_engine::utils::ErrorCodeToString; |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 46 | using std::string; |
Casey Dahlin | e844c1a | 2015-12-16 14:30:58 -0800 | [diff] [blame] | 47 | using std::unique_ptr; |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 48 | using std::vector; |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 49 | using update_engine::UpdateStatus; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 50 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 51 | namespace { |
| 52 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 53 | // Constant to signal that we need to continue running the daemon after |
| 54 | // initialization. |
| 55 | const int kContinueRunning = -1; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 56 | |
Amin Hassani | 3584bce | 2017-06-29 14:21:19 -0700 | [diff] [blame] | 57 | // The ShowStatus request will be retried `kShowStatusRetryCount` times at |
| 58 | // `kShowStatusRetryInterval` second intervals on failure. |
| 59 | const int kShowStatusRetryCount = 30; |
Amin Hassani | 1a53ba0 | 2017-07-28 15:03:14 -0700 | [diff] [blame] | 60 | const int kShowStatusRetryIntervalInSeconds = 2; |
Amin Hassani | 3584bce | 2017-06-29 14:21:19 -0700 | [diff] [blame] | 61 | |
Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 62 | class UpdateEngineClient : public brillo::Daemon { |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 63 | public: |
Casey Dahlin | e844c1a | 2015-12-16 14:30:58 -0800 | [diff] [blame] | 64 | UpdateEngineClient(int argc, char** argv) : argc_(argc), argv_(argv) { |
Casey Dahlin | e844c1a | 2015-12-16 14:30:58 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 67 | ~UpdateEngineClient() override = default; |
| 68 | |
| 69 | protected: |
| 70 | int OnInit() override { |
Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 71 | int ret = Daemon::OnInit(); |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 72 | if (ret != EX_OK) return ret; |
Casey Dahlin | 1944141 | 2016-01-07 14:56:40 -0800 | [diff] [blame] | 73 | |
| 74 | client_ = update_engine::UpdateEngineClient::CreateInstance(); |
| 75 | |
| 76 | if (!client_) { |
| 77 | LOG(ERROR) << "UpdateEngineService not available."; |
| 78 | return 1; |
| 79 | } |
| 80 | |
Alex Deymo | 690810b | 2016-01-19 16:11:40 -0800 | [diff] [blame] | 81 | // We can't call QuitWithExitCode from OnInit(), so we delay the execution |
| 82 | // of the ProcessFlags method after the Daemon initialization is done. |
Eric Caruso | 2295167 | 2018-01-23 14:37:01 -0800 | [diff] [blame] | 83 | base::MessageLoop::current()->task_runner()->PostTask( |
Alex Deymo | 690810b | 2016-01-19 16:11:40 -0800 | [diff] [blame] | 84 | FROM_HERE, |
| 85 | base::Bind(&UpdateEngineClient::ProcessFlagsAndExit, |
| 86 | base::Unretained(this))); |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 87 | return EX_OK; |
Andrew de los Reyes | 68ab6ed | 2011-08-09 14:46:39 -0700 | [diff] [blame] | 88 | } |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 89 | |
| 90 | private: |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 91 | // Show the status of the update engine in stdout. |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 92 | bool ShowStatus(); |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 93 | |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 94 | // Return whether we need to reboot. 0 if reboot is needed, 1 if an error |
| 95 | // occurred, 2 if no reboot is needed. |
| 96 | int GetNeedReboot(); |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 97 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 98 | // Main method that parses and triggers all the actions based on the passed |
Alex Deymo | 690810b | 2016-01-19 16:11:40 -0800 | [diff] [blame] | 99 | // flags. Returns the exit code of the program of kContinueRunning if it |
| 100 | // should not exit. |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 101 | int ProcessFlags(); |
| 102 | |
Alex Deymo | 690810b | 2016-01-19 16:11:40 -0800 | [diff] [blame] | 103 | // Processes the flags and exits the program accordingly. |
| 104 | void ProcessFlagsAndExit(); |
| 105 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 106 | // Copy of argc and argv passed to main(). |
| 107 | int argc_; |
| 108 | char** argv_; |
| 109 | |
Casey Dahlin | e844c1a | 2015-12-16 14:30:58 -0800 | [diff] [blame] | 110 | // Library-based client |
| 111 | unique_ptr<update_engine::UpdateEngineClient> client_; |
| 112 | |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 113 | // Pointers to handlers for cleanup |
| 114 | vector<unique_ptr<update_engine::StatusUpdateHandler>> handlers_; |
| 115 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 116 | DISALLOW_COPY_AND_ASSIGN(UpdateEngineClient); |
| 117 | }; |
| 118 | |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 119 | class ExitingStatusUpdateHandler : public update_engine::StatusUpdateHandler { |
| 120 | public: |
| 121 | ~ExitingStatusUpdateHandler() override = default; |
| 122 | |
| 123 | void IPCError(const string& error) override; |
| 124 | }; |
| 125 | |
| 126 | void ExitingStatusUpdateHandler::IPCError(const string& error) { |
| 127 | LOG(ERROR) << error; |
| 128 | exit(1); |
| 129 | } |
| 130 | |
| 131 | class WatchingStatusUpdateHandler : public ExitingStatusUpdateHandler { |
| 132 | public: |
| 133 | ~WatchingStatusUpdateHandler() override = default; |
| 134 | |
Alex Deymo | 690810b | 2016-01-19 16:11:40 -0800 | [diff] [blame] | 135 | void HandleStatusUpdate(int64_t last_checked_time, |
| 136 | double progress, |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 137 | UpdateStatus current_operation, |
Alex Deymo | 690810b | 2016-01-19 16:11:40 -0800 | [diff] [blame] | 138 | const string& new_version, |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 139 | int64_t new_size) override; |
| 140 | }; |
| 141 | |
| 142 | void WatchingStatusUpdateHandler::HandleStatusUpdate( |
| 143 | int64_t last_checked_time, double progress, UpdateStatus current_operation, |
| 144 | const string& new_version, int64_t new_size) { |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 145 | LOG(INFO) << "Got status update:"; |
| 146 | LOG(INFO) << " last_checked_time: " << last_checked_time; |
| 147 | LOG(INFO) << " progress: " << progress; |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 148 | LOG(INFO) << " current_operation: " |
| 149 | << UpdateStatusToString(current_operation); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 150 | LOG(INFO) << " new_version: " << new_version; |
| 151 | LOG(INFO) << " new_size: " << new_size; |
| 152 | } |
| 153 | |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 154 | bool UpdateEngineClient::ShowStatus() { |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 155 | int64_t last_checked_time = 0; |
| 156 | double progress = 0.0; |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 157 | UpdateStatus current_op; |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 158 | string new_version; |
| 159 | int64_t new_size = 0; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 160 | |
Amin Hassani | 3584bce | 2017-06-29 14:21:19 -0700 | [diff] [blame] | 161 | int retry_count = kShowStatusRetryCount; |
| 162 | while (retry_count > 0) { |
| 163 | if (client_->GetStatus(&last_checked_time, &progress, ¤t_op, |
| 164 | &new_version, &new_size)) { |
| 165 | break; |
| 166 | } |
| 167 | if (--retry_count == 0) { |
| 168 | return false; |
| 169 | } |
Amin Hassani | 1a53ba0 | 2017-07-28 15:03:14 -0700 | [diff] [blame] | 170 | LOG(WARNING) << "Will try " << retry_count << " more times!"; |
| 171 | base::PlatformThread::Sleep( |
| 172 | base::TimeDelta::FromSeconds(kShowStatusRetryIntervalInSeconds)); |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 173 | } |
| 174 | |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 175 | printf("LAST_CHECKED_TIME=%" PRIi64 |
| 176 | "\nPROGRESS=%f\nCURRENT_OP=%s\n" |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 177 | "NEW_VERSION=%s\nNEW_SIZE=%" PRIi64 "\n", |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 178 | last_checked_time, progress, UpdateStatusToString(current_op), |
| 179 | new_version.c_str(), new_size); |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 180 | |
| 181 | return true; |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 184 | int UpdateEngineClient::GetNeedReboot() { |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 185 | int64_t last_checked_time = 0; |
| 186 | double progress = 0.0; |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 187 | UpdateStatus current_op; |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 188 | string new_version; |
| 189 | int64_t new_size = 0; |
| 190 | |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 191 | if (!client_->GetStatus(&last_checked_time, &progress, ¤t_op, |
| 192 | &new_version, &new_size)) { |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 193 | return 1; |
| 194 | } |
| 195 | |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 196 | if (current_op == UpdateStatus::UPDATED_NEED_REBOOT) { |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 197 | return 0; |
| 198 | } |
| 199 | |
| 200 | return 2; |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 203 | class UpdateWaitHandler : public ExitingStatusUpdateHandler { |
| 204 | public: |
Alex Deymo | 9a06922 | 2016-03-02 16:14:42 -0800 | [diff] [blame] | 205 | explicit UpdateWaitHandler(bool exit_on_error, |
| 206 | update_engine::UpdateEngineClient* client) |
| 207 | : exit_on_error_(exit_on_error), client_(client) {} |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 208 | |
| 209 | ~UpdateWaitHandler() override = default; |
| 210 | |
Alex Deymo | 690810b | 2016-01-19 16:11:40 -0800 | [diff] [blame] | 211 | void HandleStatusUpdate(int64_t last_checked_time, |
| 212 | double progress, |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 213 | UpdateStatus current_operation, |
Alex Deymo | 690810b | 2016-01-19 16:11:40 -0800 | [diff] [blame] | 214 | const string& new_version, |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 215 | int64_t new_size) override; |
| 216 | |
| 217 | private: |
| 218 | bool exit_on_error_; |
Alex Deymo | 9a06922 | 2016-03-02 16:14:42 -0800 | [diff] [blame] | 219 | update_engine::UpdateEngineClient* client_; |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 220 | }; |
| 221 | |
| 222 | void UpdateWaitHandler::HandleStatusUpdate(int64_t /* last_checked_time */, |
| 223 | double /* progress */, |
| 224 | UpdateStatus current_operation, |
| 225 | const string& /* new_version */, |
| 226 | int64_t /* new_size */) { |
| 227 | if (exit_on_error_ && current_operation == UpdateStatus::IDLE) { |
Alex Deymo | 9a06922 | 2016-03-02 16:14:42 -0800 | [diff] [blame] | 228 | int last_attempt_error; |
| 229 | ErrorCode code = ErrorCode::kSuccess; |
| 230 | if (client_ && client_->GetLastAttemptError(&last_attempt_error)) |
| 231 | code = static_cast<ErrorCode>(last_attempt_error); |
| 232 | |
| 233 | LOG(ERROR) << "Update failed, current operation is " |
| 234 | << UpdateStatusToString(current_operation) |
| 235 | << ", last error code is " << ErrorCodeToString(code) << "(" |
| 236 | << last_attempt_error << ")"; |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 237 | exit(1); |
| 238 | } |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 239 | if (current_operation == UpdateStatus::UPDATED_NEED_REBOOT) { |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 240 | LOG(INFO) << "Update succeeded -- reboot needed."; |
| 241 | exit(0); |
| 242 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 243 | } |
| 244 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 245 | int UpdateEngineClient::ProcessFlags() { |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 246 | DEFINE_string(app_version, "", "Force the current app version."); |
| 247 | DEFINE_string(channel, "", |
| 248 | "Set the target channel. The device will be powerwashed if the " |
| 249 | "target channel is more stable than the current channel unless " |
| 250 | "--nopowerwash is specified."); |
| 251 | DEFINE_bool(check_for_update, false, "Initiate check for updates."); |
Alex Deymo | d63fab3 | 2016-10-06 15:40:49 -0700 | [diff] [blame] | 252 | DEFINE_string( |
| 253 | cohort_hint, "", "Set the current cohort hint to the passed value."); |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 254 | DEFINE_bool(follow, false, |
| 255 | "Wait for any update operations to complete." |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 256 | "Exit status is 0 if the update succeeded, and 1 otherwise."); |
| 257 | DEFINE_bool(interactive, true, "Mark the update request as interactive."); |
| 258 | DEFINE_string(omaha_url, "", "The URL of the Omaha update server."); |
| 259 | DEFINE_string(p2p_update, "", |
| 260 | "Enables (\"yes\") or disables (\"no\") the peer-to-peer update" |
| 261 | " sharing."); |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 262 | DEFINE_bool(powerwash, true, |
| 263 | "When performing rollback or channel change, " |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 264 | "do a powerwash or allow it respectively."); |
| 265 | DEFINE_bool(reboot, false, "Initiate a reboot if needed."); |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 266 | DEFINE_bool(is_reboot_needed, false, |
| 267 | "Exit status 0 if reboot is needed, " |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 268 | "2 if reboot is not needed or 1 if an error occurred."); |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 269 | DEFINE_bool(block_until_reboot_is_needed, false, |
| 270 | "Blocks until reboot is " |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 271 | "needed. Returns non-zero exit status if an error occurred."); |
| 272 | DEFINE_bool(reset_status, false, "Sets the status in update_engine to idle."); |
Alex Deymo | 1ac8b59 | 2015-01-26 13:22:58 -0800 | [diff] [blame] | 273 | DEFINE_bool(rollback, false, |
| 274 | "Perform a rollback to the previous partition. The device will " |
| 275 | "be powerwashed unless --nopowerwash is specified."); |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 276 | DEFINE_bool(can_rollback, false, |
| 277 | "Shows whether rollback partition " |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 278 | "is available."); |
| 279 | DEFINE_bool(show_channel, false, "Show the current and target channels."); |
Alex Deymo | d63fab3 | 2016-10-06 15:40:49 -0700 | [diff] [blame] | 280 | DEFINE_bool(show_cohort_hint, false, "Show the current cohort hint."); |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 281 | DEFINE_bool(show_p2p_update, false, |
| 282 | "Show the current setting for peer-to-peer update sharing."); |
| 283 | DEFINE_bool(show_update_over_cellular, false, |
| 284 | "Show the current setting for updates over cellular networks."); |
| 285 | DEFINE_bool(status, false, "Print the status to stdout."); |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 286 | DEFINE_bool(update, false, |
| 287 | "Forces an update and waits for it to complete. " |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 288 | "Implies --follow."); |
| 289 | DEFINE_string(update_over_cellular, "", |
| 290 | "Enables (\"yes\") or disables (\"no\") the updates over " |
| 291 | "cellular networks."); |
| 292 | DEFINE_bool(watch_for_updates, false, |
| 293 | "Listen for status updates and print them to the screen."); |
| 294 | DEFINE_bool(prev_version, false, |
| 295 | "Show the previous OS version used before the update reboot."); |
Shuqian Zhao | 2997173 | 2016-02-05 11:29:32 -0800 | [diff] [blame] | 296 | DEFINE_bool(last_attempt_error, false, "Show the last attempt error."); |
Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 297 | DEFINE_bool(eol_status, false, "Show the current end-of-life status."); |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 298 | DEFINE_bool(install, false, "Requests an install."); |
| 299 | DEFINE_string(dlc_ids, "", "colon-separated list of DLC IDs."); |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 300 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 301 | // Boilerplate init commands. |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 302 | base::CommandLine::Init(argc_, argv_); |
Sen Jiang | 49a0897 | 2017-07-26 15:54:18 -0700 | [diff] [blame] | 303 | brillo::FlagHelper::Init(argc_, argv_, "A/B Update Engine Client"); |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 304 | |
Alex Deymo | 8ce80d6 | 2015-01-27 15:10:43 -0800 | [diff] [blame] | 305 | // Ensure there are no positional arguments. |
Alex Deymo | 690810b | 2016-01-19 16:11:40 -0800 | [diff] [blame] | 306 | const vector<string> positional_args = |
Alex Deymo | 8ce80d6 | 2015-01-27 15:10:43 -0800 | [diff] [blame] | 307 | base::CommandLine::ForCurrentProcess()->GetArgs(); |
| 308 | if (!positional_args.empty()) { |
| 309 | LOG(ERROR) << "Found a positional argument '" << positional_args.front() |
| 310 | << "'. If you want to pass a value to a flag, pass it as " |
| 311 | "--flag=value."; |
| 312 | return 1; |
| 313 | } |
| 314 | |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 315 | // Update the status if requested. |
| 316 | if (FLAGS_reset_status) { |
| 317 | LOG(INFO) << "Setting Update Engine status to idle ..."; |
Casey Dahlin | e844c1a | 2015-12-16 14:30:58 -0800 | [diff] [blame] | 318 | |
| 319 | if (client_->ResetStatus()) { |
| 320 | LOG(INFO) << "ResetStatus succeeded; to undo partition table changes " |
| 321 | "run:\n" |
| 322 | "(D=$(rootdev -d) P=$(rootdev -s); cgpt p -i$(($(echo " |
| 323 | "${P#$D} | sed 's/^[^0-9]*//')-1)) $D;)"; |
| 324 | } else { |
| 325 | LOG(ERROR) << "ResetStatus failed"; |
| 326 | return 1; |
| 327 | } |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 328 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 329 | |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 330 | // Changes the current update over cellular network setting. |
| 331 | if (!FLAGS_update_over_cellular.empty()) { |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 332 | bool allowed = FLAGS_update_over_cellular == "yes"; |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 333 | if (!allowed && FLAGS_update_over_cellular != "no") { |
| 334 | LOG(ERROR) << "Unknown option: \"" << FLAGS_update_over_cellular |
| 335 | << "\". Please specify \"yes\" or \"no\"."; |
| 336 | } else { |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 337 | if (!client_->SetUpdateOverCellularPermission(allowed)) { |
Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 338 | LOG(ERROR) << "Error setting the update over cellular setting."; |
| 339 | return 1; |
| 340 | } |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 341 | } |
| 342 | } |
| 343 | |
| 344 | // Show the current update over cellular network setting. |
| 345 | if (FLAGS_show_update_over_cellular) { |
Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 346 | bool allowed; |
| 347 | |
| 348 | if (!client_->GetUpdateOverCellularPermission(&allowed)) { |
| 349 | LOG(ERROR) << "Error getting the update over cellular setting."; |
| 350 | return 1; |
| 351 | } |
| 352 | |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 353 | LOG(INFO) << "Current update over cellular network setting: " |
| 354 | << (allowed ? "ENABLED" : "DISABLED"); |
| 355 | } |
| 356 | |
Alex Deymo | d63fab3 | 2016-10-06 15:40:49 -0700 | [diff] [blame] | 357 | // Change/show the cohort hint. |
| 358 | bool set_cohort_hint = |
| 359 | base::CommandLine::ForCurrentProcess()->HasSwitch("cohort_hint"); |
| 360 | if (set_cohort_hint) { |
| 361 | LOG(INFO) << "Setting cohort hint to: \"" << FLAGS_cohort_hint << "\""; |
| 362 | if (!client_->SetCohortHint(FLAGS_cohort_hint)) { |
| 363 | LOG(ERROR) << "Error setting the cohort hint."; |
| 364 | return 1; |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | if (FLAGS_show_cohort_hint || set_cohort_hint) { |
| 369 | string cohort_hint; |
| 370 | if (!client_->GetCohortHint(&cohort_hint)) { |
| 371 | LOG(ERROR) << "Error getting the cohort hint."; |
| 372 | return 1; |
| 373 | } |
| 374 | |
| 375 | LOG(INFO) << "Current cohort hint: \"" << cohort_hint << "\""; |
| 376 | } |
| 377 | |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 378 | if (!FLAGS_powerwash && !FLAGS_rollback && FLAGS_channel.empty()) { |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 379 | LOG(ERROR) << "powerwash flag only makes sense rollback or channel change"; |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 380 | return 1; |
| 381 | } |
| 382 | |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 383 | // Change the P2P enabled setting. |
| 384 | if (!FLAGS_p2p_update.empty()) { |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 385 | bool enabled = FLAGS_p2p_update == "yes"; |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 386 | if (!enabled && FLAGS_p2p_update != "no") { |
| 387 | LOG(ERROR) << "Unknown option: \"" << FLAGS_p2p_update |
| 388 | << "\". Please specify \"yes\" or \"no\"."; |
| 389 | } else { |
Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 390 | if (!client_->SetP2PUpdatePermission(enabled)) { |
| 391 | LOG(ERROR) << "Error setting the peer-to-peer update setting."; |
| 392 | return 1; |
| 393 | } |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 394 | } |
| 395 | } |
| 396 | |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 397 | // Show the rollback availability. |
| 398 | if (FLAGS_can_rollback) { |
Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 399 | string rollback_partition; |
| 400 | |
| 401 | if (!client_->GetRollbackPartition(&rollback_partition)) { |
Sen Jiang | 771f648 | 2018-04-04 17:59:10 -0700 | [diff] [blame] | 402 | LOG(ERROR) << "Error while querying rollback partition availability."; |
Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 403 | return 1; |
| 404 | } |
| 405 | |
Chris Sosa | f5c0b9c | 2014-04-17 16:12:03 -0700 | [diff] [blame] | 406 | bool can_rollback = true; |
| 407 | if (rollback_partition.empty()) { |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 408 | rollback_partition = "UNAVAILABLE"; |
Chris Sosa | f5c0b9c | 2014-04-17 16:12:03 -0700 | [diff] [blame] | 409 | can_rollback = false; |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 410 | } else { |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 411 | rollback_partition = "AVAILABLE: " + rollback_partition; |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 412 | } |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 413 | |
| 414 | LOG(INFO) << "Rollback partition: " << rollback_partition; |
Chris Sosa | f5c0b9c | 2014-04-17 16:12:03 -0700 | [diff] [blame] | 415 | if (!can_rollback) { |
| 416 | return 1; |
| 417 | } |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 418 | } |
| 419 | |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 420 | // Show the current P2P enabled setting. |
| 421 | if (FLAGS_show_p2p_update) { |
Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 422 | bool enabled; |
| 423 | |
| 424 | if (!client_->GetP2PUpdatePermission(&enabled)) { |
| 425 | LOG(ERROR) << "Error getting the peer-to-peer update setting."; |
| 426 | return 1; |
| 427 | } |
| 428 | |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 429 | LOG(INFO) << "Current update using P2P setting: " |
| 430 | << (enabled ? "ENABLED" : "DISABLED"); |
| 431 | } |
| 432 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 433 | // First, update the target channel if requested. |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 434 | if (!FLAGS_channel.empty()) { |
| 435 | if (!client_->SetTargetChannel(FLAGS_channel, FLAGS_powerwash)) { |
| 436 | LOG(ERROR) << "Error setting the channel."; |
| 437 | return 1; |
| 438 | } |
| 439 | |
| 440 | LOG(INFO) << "Channel permanently set to: " << FLAGS_channel; |
| 441 | } |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 442 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 443 | // Show the current and target channels if requested. |
| 444 | if (FLAGS_show_channel) { |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 445 | string current_channel; |
| 446 | string target_channel; |
| 447 | |
| 448 | if (!client_->GetChannel(¤t_channel)) { |
| 449 | LOG(ERROR) << "Error getting the current channel."; |
| 450 | return 1; |
| 451 | } |
| 452 | |
| 453 | if (!client_->GetTargetChannel(&target_channel)) { |
| 454 | LOG(ERROR) << "Error getting the target channel."; |
| 455 | return 1; |
| 456 | } |
| 457 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 458 | LOG(INFO) << "Current Channel: " << current_channel; |
| 459 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 460 | if (!target_channel.empty()) |
| 461 | LOG(INFO) << "Target Channel (pending update): " << target_channel; |
Satoru Takabayashi | 583667b | 2010-10-27 13:09:57 +0900 | [diff] [blame] | 462 | } |
| 463 | |
Amin Hassani | 89b9a2d | 2018-04-20 16:01:45 -0700 | [diff] [blame] | 464 | bool do_update_request = FLAGS_check_for_update || FLAGS_update || |
| 465 | !FLAGS_app_version.empty() || |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 466 | !FLAGS_omaha_url.empty(); |
| 467 | if (FLAGS_update) FLAGS_follow = true; |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 468 | |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 469 | if (do_update_request && FLAGS_rollback) { |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 470 | LOG(ERROR) << "Incompatible flags specified with rollback." |
| 471 | << "Rollback should not include update-related flags."; |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 472 | return 1; |
| 473 | } |
| 474 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 475 | if (FLAGS_rollback) { |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 476 | LOG(INFO) << "Requesting rollback."; |
Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 477 | if (!client_->Rollback(FLAGS_powerwash)) { |
| 478 | LOG(ERROR) << "Rollback request failed."; |
| 479 | return 1; |
| 480 | } |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 481 | } |
| 482 | |
Xiaochu Liu | 88d9038 | 2018-08-29 16:09:11 -0700 | [diff] [blame] | 483 | if (FLAGS_install) { |
| 484 | // Parse DLC IDs. |
| 485 | vector<string> dlc_ids; |
| 486 | if (!FLAGS_dlc_ids.empty()) { |
| 487 | dlc_ids = base::SplitString( |
| 488 | FLAGS_dlc_ids, ":", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 489 | } |
| 490 | if (dlc_ids.empty()) { |
| 491 | LOG(ERROR) << "dlc_ids is empty:" << FLAGS_dlc_ids; |
| 492 | return 1; |
| 493 | } |
| 494 | if (!client_->AttemptInstall(FLAGS_omaha_url, dlc_ids)) { |
| 495 | LOG(ERROR) << "AttemptInstall failed."; |
| 496 | return 1; |
| 497 | } |
| 498 | return 0; |
| 499 | } else if (!FLAGS_dlc_ids.empty()) { |
| 500 | LOG(ERROR) << "dlc_ids is not empty while install is not set:" |
| 501 | << FLAGS_dlc_ids; |
| 502 | return 1; |
| 503 | } |
| 504 | |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 505 | // Initiate an update check, if necessary. |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 506 | if (do_update_request) { |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 507 | LOG_IF(WARNING, FLAGS_reboot) << "-reboot flag ignored."; |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 508 | string app_version = FLAGS_app_version; |
| 509 | if (FLAGS_update && app_version.empty()) { |
| 510 | app_version = "ForcedUpdate"; |
| 511 | LOG(INFO) << "Forcing an update by setting app_version to ForcedUpdate."; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 512 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 513 | LOG(INFO) << "Initiating update check and install."; |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 514 | if (!client_->AttemptUpdate(app_version, FLAGS_omaha_url, |
| 515 | FLAGS_interactive)) { |
| 516 | LOG(ERROR) << "Error checking for update."; |
| 517 | return 1; |
| 518 | } |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 519 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 520 | |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 521 | // These final options are all mutually exclusive with one another. |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 522 | if (FLAGS_follow + FLAGS_watch_for_updates + FLAGS_reboot + FLAGS_status + |
| 523 | FLAGS_is_reboot_needed + FLAGS_block_until_reboot_is_needed > |
| 524 | 1) { |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 525 | LOG(ERROR) << "Multiple exclusive options selected. " |
| 526 | << "Select only one of --follow, --watch_for_updates, --reboot, " |
David Zeuthen | 9d73a72 | 2014-04-04 14:52:46 -0700 | [diff] [blame] | 527 | << "--is_reboot_needed, --block_until_reboot_is_needed, " |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 528 | << "or --status."; |
| 529 | return 1; |
| 530 | } |
| 531 | |
| 532 | if (FLAGS_status) { |
| 533 | LOG(INFO) << "Querying Update Engine status..."; |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 534 | if (!ShowStatus()) { |
| 535 | LOG(ERROR) << "Failed to query status"; |
| 536 | return 1; |
| 537 | } |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 538 | return 0; |
| 539 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 540 | |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 541 | if (FLAGS_follow) { |
| 542 | LOG(INFO) << "Waiting for update to complete."; |
Alex Deymo | 9a06922 | 2016-03-02 16:14:42 -0800 | [diff] [blame] | 543 | auto handler = new UpdateWaitHandler(true, client_.get()); |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 544 | handlers_.emplace_back(handler); |
| 545 | client_->RegisterStatusUpdateHandler(handler); |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 546 | return kContinueRunning; |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 549 | if (FLAGS_watch_for_updates) { |
| 550 | LOG(INFO) << "Watching for status updates."; |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 551 | auto handler = new WatchingStatusUpdateHandler(); |
| 552 | handlers_.emplace_back(handler); |
| 553 | client_->RegisterStatusUpdateHandler(handler); |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 554 | return kContinueRunning; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 555 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 556 | |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 557 | if (FLAGS_reboot) { |
| 558 | LOG(INFO) << "Requesting a reboot..."; |
Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 559 | client_->RebootIfNeeded(); |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 560 | return 0; |
| 561 | } |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 562 | |
Alex Vakulenko | dea2eac | 2014-03-14 15:56:59 -0700 | [diff] [blame] | 563 | if (FLAGS_prev_version) { |
Casey Dahlin | ef36113 | 2015-12-17 13:02:37 -0800 | [diff] [blame] | 564 | string prev_version; |
| 565 | |
| 566 | if (!client_->GetPrevVersion(&prev_version)) { |
| 567 | LOG(ERROR) << "Error getting previous version."; |
| 568 | } else { |
| 569 | LOG(INFO) << "Previous version = " << prev_version; |
| 570 | } |
Alex Vakulenko | dea2eac | 2014-03-14 15:56:59 -0700 | [diff] [blame] | 571 | } |
| 572 | |
David Zeuthen | 9d73a72 | 2014-04-04 14:52:46 -0700 | [diff] [blame] | 573 | if (FLAGS_is_reboot_needed) { |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 574 | int ret = GetNeedReboot(); |
| 575 | |
| 576 | if (ret == 1) { |
| 577 | LOG(ERROR) << "Could not query the current operation."; |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 578 | } |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame] | 579 | |
| 580 | return ret; |
David Zeuthen | 9d73a72 | 2014-04-04 14:52:46 -0700 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | if (FLAGS_block_until_reboot_is_needed) { |
Alex Deymo | 9a06922 | 2016-03-02 16:14:42 -0800 | [diff] [blame] | 584 | auto handler = new UpdateWaitHandler(false, nullptr); |
Casey Dahlin | 97c8705 | 2016-01-06 14:33:55 -0800 | [diff] [blame] | 585 | handlers_.emplace_back(handler); |
| 586 | client_->RegisterStatusUpdateHandler(handler); |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 587 | return kContinueRunning; |
David Zeuthen | 9d73a72 | 2014-04-04 14:52:46 -0700 | [diff] [blame] | 588 | } |
| 589 | |
Shuqian Zhao | 2997173 | 2016-02-05 11:29:32 -0800 | [diff] [blame] | 590 | if (FLAGS_last_attempt_error) { |
| 591 | int last_attempt_error; |
| 592 | if (!client_->GetLastAttemptError(&last_attempt_error)) { |
| 593 | LOG(ERROR) << "Error getting last attempt error."; |
| 594 | } else { |
| 595 | ErrorCode code = static_cast<ErrorCode>(last_attempt_error); |
Alex Deymo | 9a06922 | 2016-03-02 16:14:42 -0800 | [diff] [blame] | 596 | printf( |
| 597 | "ERROR_CODE=%i\n" |
| 598 | "ERROR_MESSAGE=%s\n", |
| 599 | last_attempt_error, |
| 600 | ErrorCodeToString(code).c_str()); |
Shuqian Zhao | 2997173 | 2016-02-05 11:29:32 -0800 | [diff] [blame] | 601 | } |
Alex Deymo | 9a06922 | 2016-03-02 16:14:42 -0800 | [diff] [blame] | 602 | } |
Shuqian Zhao | 2997173 | 2016-02-05 11:29:32 -0800 | [diff] [blame] | 603 | |
Alex Deymo | b3fa53b | 2016-04-18 19:57:58 -0700 | [diff] [blame] | 604 | if (FLAGS_eol_status) { |
| 605 | int eol_status; |
| 606 | if (!client_->GetEolStatus(&eol_status)) { |
| 607 | LOG(ERROR) << "Error getting the end-of-life status."; |
| 608 | } else { |
| 609 | EolStatus eol_status_code = static_cast<EolStatus>(eol_status); |
| 610 | printf("EOL_STATUS=%s\n", EolStatusToString(eol_status_code)); |
| 611 | } |
| 612 | } |
| 613 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 614 | return 0; |
| 615 | } |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 616 | |
Alex Deymo | 690810b | 2016-01-19 16:11:40 -0800 | [diff] [blame] | 617 | void UpdateEngineClient::ProcessFlagsAndExit() { |
| 618 | int ret = ProcessFlags(); |
| 619 | if (ret != kContinueRunning) |
| 620 | QuitWithExitCode(ret); |
| 621 | } |
| 622 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 623 | } // namespace |
| 624 | |
| 625 | int main(int argc, char** argv) { |
| 626 | UpdateEngineClient client(argc, argv); |
| 627 | return client.Run(); |
| 628 | } |