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