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