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> |
| 23 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 24 | #include <base/bind.h> |
Alex Deymo | 8ce80d6 | 2015-01-27 15:10:43 -0800 | [diff] [blame] | 25 | #include <base/command_line.h> |
Alex Deymo | 44666f9 | 2014-07-22 20:29:24 -0700 | [diff] [blame] | 26 | #include <base/logging.h> |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 27 | #include <base/macros.h> |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 28 | #include <brillo/daemons/dbus_daemon.h> |
| 29 | #include <brillo/flag_helper.h> |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 30 | #include <dbus/bus.h> |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 31 | |
| 32 | #include "update_engine/client.h" |
| 33 | #include "update_engine/update_status.h" |
| 34 | #include "update_engine/dbus-constants.h" |
| 35 | #include "update_engine/dbus-proxies.h" |
| 36 | #include "update_status_utils.h" |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 37 | |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 38 | using std::string; |
Casey Dahlin | e844c1a | 2015-12-16 14:30:58 -0800 | [diff] [blame] | 39 | using std::unique_ptr; |
Alex Deymo | d6deb1d | 2015-08-28 15:54:37 -0700 | [diff] [blame] | 40 | using update_engine::kAttemptUpdateFlagNonInteractive; |
| 41 | using update_engine::kUpdateEngineServiceName; |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 42 | using chromeos_update_engine::UpdateStatusToString; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 43 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 44 | namespace { |
| 45 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 46 | // Constant to signal that we need to continue running the daemon after |
| 47 | // initialization. |
| 48 | const int kContinueRunning = -1; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 49 | |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 50 | class UpdateEngineClient : public brillo::DBusDaemon { |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 51 | public: |
Casey Dahlin | e844c1a | 2015-12-16 14:30:58 -0800 | [diff] [blame] | 52 | UpdateEngineClient(int argc, char** argv) : argc_(argc), argv_(argv) { |
| 53 | client_ = update_engine::UpdateEngineClient::CreateInstance(); |
| 54 | } |
| 55 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 56 | ~UpdateEngineClient() override = default; |
| 57 | |
| 58 | protected: |
| 59 | int OnInit() override { |
| 60 | int ret = DBusDaemon::OnInit(); |
| 61 | if (ret != EX_OK) |
| 62 | return ret; |
| 63 | if (!InitProxy()) |
| 64 | return 1; |
Alex Deymo | 13e0dd6 | 2015-06-30 23:11:44 -0700 | [diff] [blame] | 65 | // Wait for the UpdateEngine to be available or timeout. |
| 66 | proxy_->GetObjectProxy()->WaitForServiceToBeAvailable( |
| 67 | base::Bind(&UpdateEngineClient::OnServiceAvailable, |
| 68 | base::Unretained(this))); |
| 69 | base::MessageLoop::current()->PostDelayedTask( |
| 70 | FROM_HERE, |
| 71 | base::Bind(&UpdateEngineClient::OnServiceAvailableTimeout, |
| 72 | base::Unretained(this)), |
| 73 | base::TimeDelta::FromSeconds(10)); |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 74 | return EX_OK; |
Andrew de los Reyes | 68ab6ed | 2011-08-09 14:46:39 -0700 | [diff] [blame] | 75 | } |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 76 | |
| 77 | private: |
| 78 | bool InitProxy(); |
| 79 | |
Alex Deymo | 13e0dd6 | 2015-06-30 23:11:44 -0700 | [diff] [blame] | 80 | // Callback called when the UpdateEngine service becomes available. |
| 81 | void OnServiceAvailable(bool service_is_available); |
| 82 | |
| 83 | // Callback called when the UpdateEngine service doesn't become available |
| 84 | // after a timeout. |
| 85 | void OnServiceAvailableTimeout(); |
| 86 | |
| 87 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 88 | // Callback called when a StatusUpdate signal is received. |
| 89 | void OnStatusUpdateSignal(int64_t last_checked_time, |
| 90 | double progress, |
| 91 | const string& current_operation, |
| 92 | const string& new_version, |
| 93 | int64_t new_size); |
| 94 | // Callback called when the OnStatusUpdateSignal() handler is registered. |
| 95 | void OnStatusUpdateSignalRegistration(const string& interface, |
| 96 | const string& signal_name, |
| 97 | bool success); |
| 98 | |
| 99 | // Registers a callback that prints on stderr the received StatusUpdate |
| 100 | // signals. |
| 101 | // The daemon should continue running for this to work. |
| 102 | void WatchForUpdates(); |
| 103 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 104 | // Show the status of the update engine in stdout. |
| 105 | // Blocking call. Exits the program with error 1 in case of an error. |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 106 | bool ShowStatus(); |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 107 | |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 108 | // Return whether we need to reboot. 0 if reboot is needed, 1 if an error |
| 109 | // occurred, 2 if no reboot is needed. |
| 110 | int GetNeedReboot(); |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 111 | |
| 112 | void Rollback(bool rollback); |
| 113 | string GetRollbackPartition(); |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 114 | |
| 115 | // Reboot the device if a reboot is needed. |
| 116 | // Blocking call. Ignores failures. |
| 117 | void RebootIfNeeded(); |
| 118 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 119 | // Getter and setter for the updates over cellular connections. |
| 120 | // Blocking call. Exits the program with error 1 in case of an error. |
| 121 | void SetUpdateOverCellularPermission(bool allowed); |
| 122 | bool GetUpdateOverCellularPermission(); |
| 123 | |
| 124 | // Getter and setter for the updates from P2P permission. |
| 125 | // Blocking call. Exits the program with error 1 in case of an error. |
| 126 | void SetP2PUpdatePermission(bool enabled); |
| 127 | bool GetP2PUpdatePermission(); |
| 128 | |
| 129 | // This is similar to watching for updates but rather than registering |
| 130 | // a signal watch, actively poll the daemon just in case it stops |
| 131 | // sending notifications. |
| 132 | void WaitForUpdateComplete(); |
| 133 | void OnUpdateCompleteCheck(int64_t last_checked_time, |
| 134 | double progress, |
| 135 | const string& current_operation, |
| 136 | const string& new_version, |
| 137 | int64_t new_size); |
| 138 | |
| 139 | // Blocking call. Exits the program with error 1 in case of an error. |
| 140 | void ShowPrevVersion(); |
| 141 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 142 | // Blocks until a reboot is needed. If the reboot is needed, exits the program |
| 143 | // with 0. Otherwise it exits the program with 1 if an error occurs before |
| 144 | // the reboot is needed. |
| 145 | void WaitForRebootNeeded(); |
| 146 | void OnRebootNeededCheck(int64_t last_checked_time, |
| 147 | double progress, |
| 148 | const string& current_operation, |
| 149 | const string& new_version, |
| 150 | int64_t new_size); |
| 151 | // Callback called when the OnRebootNeededCheck() handler is registered. This |
| 152 | // is useful to check at this point if the reboot is needed, without loosing |
| 153 | // any StatusUpdate signals and avoiding the race condition. |
| 154 | void OnRebootNeededCheckRegistration(const string& interface, |
| 155 | const string& signal_name, |
| 156 | bool success); |
| 157 | |
| 158 | // Main method that parses and triggers all the actions based on the passed |
| 159 | // flags. |
| 160 | int ProcessFlags(); |
| 161 | |
| 162 | // DBus Proxy to the update_engine daemon object used for all the calls. |
| 163 | std::unique_ptr<org::chromium::UpdateEngineInterfaceProxy> proxy_; |
| 164 | |
| 165 | // Copy of argc and argv passed to main(). |
| 166 | int argc_; |
| 167 | char** argv_; |
| 168 | |
Casey Dahlin | e844c1a | 2015-12-16 14:30:58 -0800 | [diff] [blame] | 169 | // Library-based client |
| 170 | unique_ptr<update_engine::UpdateEngineClient> client_; |
| 171 | |
Alex Deymo | 13e0dd6 | 2015-06-30 23:11:44 -0700 | [diff] [blame] | 172 | // Tell whether the UpdateEngine service is available after startup. |
| 173 | bool service_is_available_{false}; |
| 174 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 175 | DISALLOW_COPY_AND_ASSIGN(UpdateEngineClient); |
| 176 | }; |
| 177 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 178 | bool UpdateEngineClient::InitProxy() { |
| 179 | proxy_.reset(new org::chromium::UpdateEngineInterfaceProxy(bus_)); |
| 180 | |
| 181 | if (!proxy_->GetObjectProxy()) { |
| 182 | LOG(ERROR) << "Error getting dbus proxy for " << kUpdateEngineServiceName; |
| 183 | return false; |
Richard Barnette | d793606 | 2013-01-18 13:38:51 -0800 | [diff] [blame] | 184 | } |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 185 | return true; |
| 186 | } |
| 187 | |
Alex Deymo | 13e0dd6 | 2015-06-30 23:11:44 -0700 | [diff] [blame] | 188 | void UpdateEngineClient::OnServiceAvailable(bool service_is_available) { |
| 189 | service_is_available_ = service_is_available; |
| 190 | if (!service_is_available) { |
| 191 | LOG(ERROR) << "UpdateEngineService not available."; |
| 192 | QuitWithExitCode(-1); |
| 193 | } |
| 194 | int ret = ProcessFlags(); |
| 195 | if (ret != kContinueRunning) |
| 196 | QuitWithExitCode(ret); |
| 197 | } |
| 198 | |
| 199 | void UpdateEngineClient::OnServiceAvailableTimeout() { |
| 200 | if (!service_is_available_) { |
| 201 | LOG(ERROR) << "Waiting for UpdateEngineService timeout. Is update_engine " |
| 202 | "daemon running?"; |
| 203 | QuitWithExitCode(-1); |
| 204 | } |
| 205 | } |
| 206 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 207 | void UpdateEngineClient::OnStatusUpdateSignal( |
| 208 | int64_t last_checked_time, |
| 209 | double progress, |
| 210 | const string& current_operation, |
| 211 | const string& new_version, |
| 212 | int64_t new_size) { |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 213 | LOG(INFO) << "Got status update:"; |
| 214 | LOG(INFO) << " last_checked_time: " << last_checked_time; |
| 215 | LOG(INFO) << " progress: " << progress; |
| 216 | LOG(INFO) << " current_operation: " << current_operation; |
| 217 | LOG(INFO) << " new_version: " << new_version; |
| 218 | LOG(INFO) << " new_size: " << new_size; |
| 219 | } |
| 220 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 221 | void UpdateEngineClient::OnStatusUpdateSignalRegistration( |
| 222 | const string& interface, |
| 223 | const string& signal_name, |
| 224 | bool success) { |
| 225 | VLOG(1) << "OnStatusUpdateSignalRegistration(" << interface << ", " |
| 226 | << signal_name << ", " << success << ");"; |
| 227 | if (!success) { |
| 228 | LOG(ERROR) << "Couldn't connect to the " << signal_name << " signal."; |
| 229 | exit(1); |
| 230 | } |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 233 | void UpdateEngineClient::WatchForUpdates() { |
| 234 | proxy_->RegisterStatusUpdateSignalHandler( |
| 235 | base::Bind(&UpdateEngineClient::OnStatusUpdateSignal, |
| 236 | base::Unretained(this)), |
| 237 | base::Bind(&UpdateEngineClient::OnStatusUpdateSignalRegistration, |
| 238 | base::Unretained(this))); |
| 239 | } |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 240 | |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 241 | bool UpdateEngineClient::ShowStatus() { |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 242 | int64_t last_checked_time = 0; |
| 243 | double progress = 0.0; |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 244 | update_engine::UpdateStatus current_op; |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 245 | string new_version; |
| 246 | int64_t new_size = 0; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 247 | |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 248 | if (!client_->GetStatus( |
| 249 | &last_checked_time, &progress, ¤t_op, &new_version, &new_size)) { |
| 250 | return false; |
| 251 | } |
| 252 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 253 | printf("LAST_CHECKED_TIME=%" PRIi64 "\nPROGRESS=%f\nCURRENT_OP=%s\n" |
| 254 | "NEW_VERSION=%s\nNEW_SIZE=%" PRIi64 "\n", |
| 255 | last_checked_time, |
| 256 | progress, |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 257 | UpdateStatusToString(current_op), |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 258 | new_version.c_str(), |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 259 | new_size); |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 260 | |
| 261 | return true; |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 262 | } |
| 263 | |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 264 | int UpdateEngineClient::GetNeedReboot() { |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 265 | int64_t last_checked_time = 0; |
| 266 | double progress = 0.0; |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 267 | update_engine::UpdateStatus current_op; |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 268 | string new_version; |
| 269 | int64_t new_size = 0; |
| 270 | |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 271 | if (!client_->GetStatus( |
| 272 | &last_checked_time, &progress, ¤t_op, &new_version, &new_size)) { |
| 273 | return 1; |
| 274 | } |
| 275 | |
| 276 | if (current_op == update_engine::UpdateStatus::UPDATED_NEED_REBOOT) { |
| 277 | return 0; |
| 278 | } |
| 279 | |
| 280 | return 2; |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | void UpdateEngineClient::Rollback(bool rollback) { |
| 284 | bool ret = proxy_->AttemptRollback(rollback, nullptr); |
| 285 | CHECK(ret) << "Rollback request failed."; |
| 286 | } |
| 287 | |
| 288 | string UpdateEngineClient::GetRollbackPartition() { |
| 289 | string rollback_partition; |
| 290 | bool ret = proxy_->GetRollbackPartition(&rollback_partition, nullptr); |
| 291 | CHECK(ret) << "Error while querying rollback partition availabilty."; |
| 292 | return rollback_partition; |
| 293 | } |
| 294 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 295 | void UpdateEngineClient::RebootIfNeeded() { |
| 296 | bool ret = proxy_->RebootIfNeeded(nullptr); |
| 297 | if (!ret) { |
| 298 | // Reboot error code doesn't necessarily mean that a reboot |
| 299 | // failed. For example, D-Bus may be shutdown before we receive the |
| 300 | // result. |
| 301 | LOG(INFO) << "RebootIfNeeded() failure ignored."; |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 302 | } |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 305 | void UpdateEngineClient::SetUpdateOverCellularPermission(bool allowed) { |
| 306 | bool ret = proxy_->SetUpdateOverCellularPermission(allowed, nullptr); |
| 307 | CHECK(ret) << "Error setting the update over cellular setting."; |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 308 | } |
| 309 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 310 | bool UpdateEngineClient::GetUpdateOverCellularPermission() { |
| 311 | bool allowed; |
| 312 | bool ret = proxy_->GetUpdateOverCellularPermission(&allowed, nullptr); |
| 313 | CHECK(ret) << "Error getting the update over cellular setting."; |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 314 | return allowed; |
| 315 | } |
| 316 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 317 | void UpdateEngineClient::SetP2PUpdatePermission(bool enabled) { |
| 318 | bool ret = proxy_->SetP2PUpdatePermission(enabled, nullptr); |
| 319 | CHECK(ret) << "Error setting the peer-to-peer update setting."; |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 320 | } |
| 321 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 322 | bool UpdateEngineClient::GetP2PUpdatePermission() { |
| 323 | bool enabled; |
| 324 | bool ret = proxy_->GetP2PUpdatePermission(&enabled, nullptr); |
| 325 | CHECK(ret) << "Error getting the peer-to-peer update setting."; |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 326 | return enabled; |
| 327 | } |
| 328 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 329 | void UpdateEngineClient::OnUpdateCompleteCheck( |
| 330 | int64_t /* last_checked_time */, |
| 331 | double /* progress */, |
| 332 | const string& current_operation, |
| 333 | const string& /* new_version */, |
| 334 | int64_t /* new_size */) { |
| 335 | if (current_operation == update_engine::kUpdateStatusIdle) { |
| 336 | LOG(ERROR) << "Update failed, current operations is " << current_operation; |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 337 | exit(1); |
| 338 | } |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 339 | if (current_operation == update_engine::kUpdateStatusUpdatedNeedReboot) { |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 340 | LOG(INFO) << "Update succeeded -- reboot needed."; |
| 341 | exit(0); |
| 342 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 345 | void UpdateEngineClient::WaitForUpdateComplete() { |
| 346 | proxy_->RegisterStatusUpdateSignalHandler( |
| 347 | base::Bind(&UpdateEngineClient::OnUpdateCompleteCheck, |
| 348 | base::Unretained(this)), |
| 349 | base::Bind(&UpdateEngineClient::OnStatusUpdateSignalRegistration, |
| 350 | base::Unretained(this))); |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 353 | void UpdateEngineClient::ShowPrevVersion() { |
| 354 | string prev_version = nullptr; |
Alex Vakulenko | dea2eac | 2014-03-14 15:56:59 -0700 | [diff] [blame] | 355 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 356 | bool ret = proxy_->GetPrevVersion(&prev_version, nullptr);; |
| 357 | if (!ret) { |
| 358 | LOG(ERROR) << "Error getting previous version."; |
Alex Vakulenko | dea2eac | 2014-03-14 15:56:59 -0700 | [diff] [blame] | 359 | } else { |
| 360 | LOG(INFO) << "Previous version = " << prev_version; |
Alex Vakulenko | dea2eac | 2014-03-14 15:56:59 -0700 | [diff] [blame] | 361 | } |
| 362 | } |
| 363 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 364 | void UpdateEngineClient::OnRebootNeededCheck( |
| 365 | int64_t /* last_checked_time */, |
| 366 | double /* progress */, |
| 367 | const string& current_operation, |
| 368 | const string& /* new_version */, |
| 369 | int64_t /* new_size */) { |
| 370 | if (current_operation == update_engine::kUpdateStatusUpdatedNeedReboot) { |
| 371 | LOG(INFO) << "Reboot needed."; |
| 372 | exit(0); |
David Zeuthen | 9d73a72 | 2014-04-04 14:52:46 -0700 | [diff] [blame] | 373 | } |
| 374 | } |
| 375 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 376 | void UpdateEngineClient::OnRebootNeededCheckRegistration( |
| 377 | const string& interface, |
| 378 | const string& signal_name, |
| 379 | bool success) { |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 380 | int got = GetNeedReboot(); |
| 381 | |
| 382 | if (got == 1) { |
| 383 | LOG(ERROR) << "Could not query the current operation."; |
| 384 | exit(1); |
| 385 | } |
| 386 | |
| 387 | if (got == 0) { |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 388 | exit(0); |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 389 | } |
| 390 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 391 | if (!success) { |
| 392 | LOG(ERROR) << "Couldn't connect to the " << signal_name << " signal."; |
| 393 | exit(1); |
| 394 | } |
David Zeuthen | 9d73a72 | 2014-04-04 14:52:46 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | // Blocks until a reboot is needed. Returns true if waiting succeeded, |
| 398 | // false if an error occurred. |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 399 | void UpdateEngineClient::WaitForRebootNeeded() { |
| 400 | proxy_->RegisterStatusUpdateSignalHandler( |
| 401 | base::Bind(&UpdateEngineClient::OnUpdateCompleteCheck, |
| 402 | base::Unretained(this)), |
| 403 | base::Bind(&UpdateEngineClient::OnStatusUpdateSignalRegistration, |
| 404 | base::Unretained(this))); |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 405 | int got = GetNeedReboot(); |
| 406 | |
| 407 | if (got == 1) { |
| 408 | LOG(ERROR) << "Could not query the current operation."; |
| 409 | exit(1); |
| 410 | } |
| 411 | |
| 412 | if (got == 0) |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 413 | exit(0); |
David Zeuthen | 9d73a72 | 2014-04-04 14:52:46 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 416 | int UpdateEngineClient::ProcessFlags() { |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 417 | DEFINE_string(app_version, "", "Force the current app version."); |
| 418 | DEFINE_string(channel, "", |
| 419 | "Set the target channel. The device will be powerwashed if the " |
| 420 | "target channel is more stable than the current channel unless " |
| 421 | "--nopowerwash is specified."); |
| 422 | DEFINE_bool(check_for_update, false, "Initiate check for updates."); |
| 423 | DEFINE_bool(follow, false, "Wait for any update operations to complete." |
| 424 | "Exit status is 0 if the update succeeded, and 1 otherwise."); |
| 425 | DEFINE_bool(interactive, true, "Mark the update request as interactive."); |
| 426 | DEFINE_string(omaha_url, "", "The URL of the Omaha update server."); |
| 427 | DEFINE_string(p2p_update, "", |
| 428 | "Enables (\"yes\") or disables (\"no\") the peer-to-peer update" |
| 429 | " sharing."); |
| 430 | DEFINE_bool(powerwash, true, "When performing rollback or channel change, " |
| 431 | "do a powerwash or allow it respectively."); |
| 432 | DEFINE_bool(reboot, false, "Initiate a reboot if needed."); |
| 433 | DEFINE_bool(is_reboot_needed, false, "Exit status 0 if reboot is needed, " |
| 434 | "2 if reboot is not needed or 1 if an error occurred."); |
| 435 | DEFINE_bool(block_until_reboot_is_needed, false, "Blocks until reboot is " |
| 436 | "needed. Returns non-zero exit status if an error occurred."); |
| 437 | 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] | 438 | DEFINE_bool(rollback, false, |
| 439 | "Perform a rollback to the previous partition. The device will " |
| 440 | "be powerwashed unless --nopowerwash is specified."); |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 441 | DEFINE_bool(can_rollback, false, "Shows whether rollback partition " |
| 442 | "is available."); |
| 443 | DEFINE_bool(show_channel, false, "Show the current and target channels."); |
| 444 | DEFINE_bool(show_p2p_update, false, |
| 445 | "Show the current setting for peer-to-peer update sharing."); |
| 446 | DEFINE_bool(show_update_over_cellular, false, |
| 447 | "Show the current setting for updates over cellular networks."); |
| 448 | DEFINE_bool(status, false, "Print the status to stdout."); |
| 449 | DEFINE_bool(update, false, "Forces an update and waits for it to complete. " |
| 450 | "Implies --follow."); |
| 451 | DEFINE_string(update_over_cellular, "", |
| 452 | "Enables (\"yes\") or disables (\"no\") the updates over " |
| 453 | "cellular networks."); |
| 454 | DEFINE_bool(watch_for_updates, false, |
| 455 | "Listen for status updates and print them to the screen."); |
| 456 | DEFINE_bool(prev_version, false, |
| 457 | "Show the previous OS version used before the update reboot."); |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 458 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 459 | // Boilerplate init commands. |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 460 | base::CommandLine::Init(argc_, argv_); |
Alex Vakulenko | 3f39d5c | 2015-10-13 09:27:13 -0700 | [diff] [blame] | 461 | brillo::FlagHelper::Init(argc_, argv_, "Chromium OS Update Engine Client"); |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 462 | |
Alex Deymo | 8ce80d6 | 2015-01-27 15:10:43 -0800 | [diff] [blame] | 463 | // Ensure there are no positional arguments. |
| 464 | const std::vector<string> positional_args = |
| 465 | base::CommandLine::ForCurrentProcess()->GetArgs(); |
| 466 | if (!positional_args.empty()) { |
| 467 | LOG(ERROR) << "Found a positional argument '" << positional_args.front() |
| 468 | << "'. If you want to pass a value to a flag, pass it as " |
| 469 | "--flag=value."; |
| 470 | return 1; |
| 471 | } |
| 472 | |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 473 | // Update the status if requested. |
| 474 | if (FLAGS_reset_status) { |
| 475 | LOG(INFO) << "Setting Update Engine status to idle ..."; |
Casey Dahlin | e844c1a | 2015-12-16 14:30:58 -0800 | [diff] [blame] | 476 | |
| 477 | if (client_->ResetStatus()) { |
| 478 | LOG(INFO) << "ResetStatus succeeded; to undo partition table changes " |
| 479 | "run:\n" |
| 480 | "(D=$(rootdev -d) P=$(rootdev -s); cgpt p -i$(($(echo " |
| 481 | "${P#$D} | sed 's/^[^0-9]*//')-1)) $D;)"; |
| 482 | } else { |
| 483 | LOG(ERROR) << "ResetStatus failed"; |
| 484 | return 1; |
| 485 | } |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 486 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 487 | |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 488 | // Changes the current update over cellular network setting. |
| 489 | if (!FLAGS_update_over_cellular.empty()) { |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 490 | bool allowed = FLAGS_update_over_cellular == "yes"; |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 491 | if (!allowed && FLAGS_update_over_cellular != "no") { |
| 492 | LOG(ERROR) << "Unknown option: \"" << FLAGS_update_over_cellular |
| 493 | << "\". Please specify \"yes\" or \"no\"."; |
| 494 | } else { |
| 495 | SetUpdateOverCellularPermission(allowed); |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | // Show the current update over cellular network setting. |
| 500 | if (FLAGS_show_update_over_cellular) { |
| 501 | bool allowed = GetUpdateOverCellularPermission(); |
| 502 | LOG(INFO) << "Current update over cellular network setting: " |
| 503 | << (allowed ? "ENABLED" : "DISABLED"); |
| 504 | } |
| 505 | |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 506 | if (!FLAGS_powerwash && !FLAGS_rollback && FLAGS_channel.empty()) { |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 507 | LOG(ERROR) << "powerwash flag only makes sense rollback or channel change"; |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 508 | return 1; |
| 509 | } |
| 510 | |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 511 | // Change the P2P enabled setting. |
| 512 | if (!FLAGS_p2p_update.empty()) { |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 513 | bool enabled = FLAGS_p2p_update == "yes"; |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 514 | if (!enabled && FLAGS_p2p_update != "no") { |
| 515 | LOG(ERROR) << "Unknown option: \"" << FLAGS_p2p_update |
| 516 | << "\". Please specify \"yes\" or \"no\"."; |
| 517 | } else { |
| 518 | SetP2PUpdatePermission(enabled); |
| 519 | } |
| 520 | } |
| 521 | |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 522 | // Show the rollback availability. |
| 523 | if (FLAGS_can_rollback) { |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 524 | string rollback_partition = GetRollbackPartition(); |
Chris Sosa | f5c0b9c | 2014-04-17 16:12:03 -0700 | [diff] [blame] | 525 | bool can_rollback = true; |
| 526 | if (rollback_partition.empty()) { |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 527 | rollback_partition = "UNAVAILABLE"; |
Chris Sosa | f5c0b9c | 2014-04-17 16:12:03 -0700 | [diff] [blame] | 528 | can_rollback = false; |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 529 | } else { |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 530 | rollback_partition = "AVAILABLE: " + rollback_partition; |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 531 | } |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 532 | |
| 533 | LOG(INFO) << "Rollback partition: " << rollback_partition; |
Chris Sosa | f5c0b9c | 2014-04-17 16:12:03 -0700 | [diff] [blame] | 534 | if (!can_rollback) { |
| 535 | return 1; |
| 536 | } |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 537 | } |
| 538 | |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 539 | // Show the current P2P enabled setting. |
| 540 | if (FLAGS_show_p2p_update) { |
| 541 | bool enabled = GetP2PUpdatePermission(); |
| 542 | LOG(INFO) << "Current update using P2P setting: " |
| 543 | << (enabled ? "ENABLED" : "DISABLED"); |
| 544 | } |
| 545 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 546 | // First, update the target channel if requested. |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 547 | if (!FLAGS_channel.empty()) { |
| 548 | if (!client_->SetTargetChannel(FLAGS_channel, FLAGS_powerwash)) { |
| 549 | LOG(ERROR) << "Error setting the channel."; |
| 550 | return 1; |
| 551 | } |
| 552 | |
| 553 | LOG(INFO) << "Channel permanently set to: " << FLAGS_channel; |
| 554 | } |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 555 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 556 | // Show the current and target channels if requested. |
| 557 | if (FLAGS_show_channel) { |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 558 | string current_channel; |
| 559 | string target_channel; |
| 560 | |
| 561 | if (!client_->GetChannel(¤t_channel)) { |
| 562 | LOG(ERROR) << "Error getting the current channel."; |
| 563 | return 1; |
| 564 | } |
| 565 | |
| 566 | if (!client_->GetTargetChannel(&target_channel)) { |
| 567 | LOG(ERROR) << "Error getting the target channel."; |
| 568 | return 1; |
| 569 | } |
| 570 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 571 | LOG(INFO) << "Current Channel: " << current_channel; |
| 572 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 573 | if (!target_channel.empty()) |
| 574 | LOG(INFO) << "Target Channel (pending update): " << target_channel; |
Satoru Takabayashi | 583667b | 2010-10-27 13:09:57 +0900 | [diff] [blame] | 575 | } |
| 576 | |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 577 | bool do_update_request = FLAGS_check_for_update | FLAGS_update | |
| 578 | !FLAGS_app_version.empty() | !FLAGS_omaha_url.empty(); |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 579 | if (FLAGS_update) |
| 580 | FLAGS_follow = true; |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 581 | |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 582 | if (do_update_request && FLAGS_rollback) { |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 583 | LOG(ERROR) << "Incompatible flags specified with rollback." |
| 584 | << "Rollback should not include update-related flags."; |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 585 | return 1; |
| 586 | } |
| 587 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 588 | if (FLAGS_rollback) { |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 589 | LOG(INFO) << "Requesting rollback."; |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 590 | Rollback(FLAGS_powerwash); |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 591 | } |
| 592 | |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 593 | // Initiate an update check, if necessary. |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 594 | if (do_update_request) { |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 595 | LOG_IF(WARNING, FLAGS_reboot) << "-reboot flag ignored."; |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 596 | string app_version = FLAGS_app_version; |
| 597 | if (FLAGS_update && app_version.empty()) { |
| 598 | app_version = "ForcedUpdate"; |
| 599 | 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] | 600 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 601 | LOG(INFO) << "Initiating update check and install."; |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 602 | if (!client_->AttemptUpdate(app_version, FLAGS_omaha_url, |
| 603 | FLAGS_interactive)) { |
| 604 | LOG(ERROR) << "Error checking for update."; |
| 605 | return 1; |
| 606 | } |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 607 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 608 | |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 609 | // These final options are all mutually exclusive with one another. |
David Zeuthen | 9d73a72 | 2014-04-04 14:52:46 -0700 | [diff] [blame] | 610 | if (FLAGS_follow + FLAGS_watch_for_updates + FLAGS_reboot + |
| 611 | FLAGS_status + FLAGS_is_reboot_needed + |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 612 | FLAGS_block_until_reboot_is_needed > 1) { |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 613 | LOG(ERROR) << "Multiple exclusive options selected. " |
| 614 | << "Select only one of --follow, --watch_for_updates, --reboot, " |
David Zeuthen | 9d73a72 | 2014-04-04 14:52:46 -0700 | [diff] [blame] | 615 | << "--is_reboot_needed, --block_until_reboot_is_needed, " |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 616 | << "or --status."; |
| 617 | return 1; |
| 618 | } |
| 619 | |
| 620 | if (FLAGS_status) { |
| 621 | LOG(INFO) << "Querying Update Engine status..."; |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 622 | if (!ShowStatus()) { |
| 623 | LOG(ERROR) << "Failed to query status"; |
| 624 | return 1; |
| 625 | } |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 626 | return 0; |
| 627 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 628 | |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 629 | if (FLAGS_follow) { |
| 630 | LOG(INFO) << "Waiting for update to complete."; |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 631 | WaitForUpdateComplete(); |
| 632 | return kContinueRunning; |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 633 | } |
| 634 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 635 | if (FLAGS_watch_for_updates) { |
| 636 | LOG(INFO) << "Watching for status updates."; |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 637 | WatchForUpdates(); |
| 638 | return kContinueRunning; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 639 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 640 | |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 641 | if (FLAGS_reboot) { |
| 642 | LOG(INFO) << "Requesting a reboot..."; |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 643 | RebootIfNeeded(); |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 644 | return 0; |
| 645 | } |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 646 | |
Alex Vakulenko | dea2eac | 2014-03-14 15:56:59 -0700 | [diff] [blame] | 647 | if (FLAGS_prev_version) { |
| 648 | ShowPrevVersion(); |
| 649 | } |
| 650 | |
David Zeuthen | 9d73a72 | 2014-04-04 14:52:46 -0700 | [diff] [blame] | 651 | if (FLAGS_is_reboot_needed) { |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 652 | int ret = GetNeedReboot(); |
| 653 | |
| 654 | if (ret == 1) { |
| 655 | LOG(ERROR) << "Could not query the current operation."; |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 656 | } |
Casey Dahlin | 87ab88e | 2015-12-16 17:58:05 -0800 | [diff] [blame^] | 657 | |
| 658 | return ret; |
David Zeuthen | 9d73a72 | 2014-04-04 14:52:46 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | if (FLAGS_block_until_reboot_is_needed) { |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 662 | WaitForRebootNeeded(); |
| 663 | return kContinueRunning; |
David Zeuthen | 9d73a72 | 2014-04-04 14:52:46 -0700 | [diff] [blame] | 664 | } |
| 665 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 666 | return 0; |
| 667 | } |
Alex Deymo | 72aa002 | 2015-06-19 21:16:49 -0700 | [diff] [blame] | 668 | |
| 669 | } // namespace |
| 670 | |
| 671 | int main(int argc, char** argv) { |
| 672 | UpdateEngineClient client(argc, argv); |
| 673 | return client.Run(); |
| 674 | } |