Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 5 | #include <string> |
| 6 | |
Alex Deymo | 8ce80d6 | 2015-01-27 15:10:43 -0800 | [diff] [blame^] | 7 | #include <base/command_line.h> |
Alex Deymo | 44666f9 | 2014-07-22 20:29:24 -0700 | [diff] [blame] | 8 | #include <base/logging.h> |
David Zeuthen | 9d73a72 | 2014-04-04 14:52:46 -0700 | [diff] [blame] | 9 | #include <chromeos/dbus/service_constants.h> |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 10 | #include <chromeos/flag_helper.h> |
Ben Chan | 46bf5c8 | 2013-06-24 11:17:41 -0700 | [diff] [blame] | 11 | #include <dbus/dbus.h> |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 12 | #include <glib.h> |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 13 | #include <inttypes.h> |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 14 | |
| 15 | #include "update_engine/dbus_constants.h" |
Alex Deymo | 44666f9 | 2014-07-22 20:29:24 -0700 | [diff] [blame] | 16 | #include "update_engine/glib_utils.h" |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 17 | |
| 18 | extern "C" { |
| 19 | #include "update_engine/update_engine.dbusclient.h" |
| 20 | } |
| 21 | |
David Zeuthen | 75a4c3e | 2013-09-06 11:36:59 -0700 | [diff] [blame] | 22 | using chromeos_update_engine::AttemptUpdateFlags; |
| 23 | using chromeos_update_engine::kAttemptUpdateFlagNonInteractive; |
Alex Deymo | 44666f9 | 2014-07-22 20:29:24 -0700 | [diff] [blame] | 24 | using chromeos_update_engine::kUpdateEngineServiceInterface; |
| 25 | using chromeos_update_engine::kUpdateEngineServiceName; |
| 26 | using chromeos_update_engine::kUpdateEngineServicePath; |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 27 | using chromeos_update_engine::utils::GetAndFreeGError; |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 28 | using std::string; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 29 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 30 | namespace { |
| 31 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 32 | bool GetProxy(DBusGProxy** out_proxy) { |
| 33 | DBusGConnection* bus; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 34 | DBusGProxy* proxy = nullptr; |
| 35 | GError* error = nullptr; |
Andrew de los Reyes | 68ab6ed | 2011-08-09 14:46:39 -0700 | [diff] [blame] | 36 | const int kTries = 4; |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 37 | const int kRetrySeconds = 10; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 38 | |
| 39 | bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 40 | if (bus == nullptr) { |
Richard Barnette | d793606 | 2013-01-18 13:38:51 -0800 | [diff] [blame] | 41 | LOG(ERROR) << "Failed to get bus: " << GetAndFreeGError(&error); |
| 42 | exit(1); |
| 43 | } |
Andrew de los Reyes | 68ab6ed | 2011-08-09 14:46:39 -0700 | [diff] [blame] | 44 | for (int i = 0; !proxy && i < kTries; ++i) { |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 45 | if (i > 0) { |
| 46 | LOG(INFO) << "Retrying to get dbus proxy. Try " |
| 47 | << (i + 1) << "/" << kTries; |
Gilad Arnold | 8e3f126 | 2013-01-08 14:59:54 -0800 | [diff] [blame] | 48 | g_usleep(kRetrySeconds * G_USEC_PER_SEC); |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 49 | } |
Andrew de los Reyes | 68ab6ed | 2011-08-09 14:46:39 -0700 | [diff] [blame] | 50 | proxy = dbus_g_proxy_new_for_name_owner(bus, |
| 51 | kUpdateEngineServiceName, |
| 52 | kUpdateEngineServicePath, |
| 53 | kUpdateEngineServiceInterface, |
| 54 | &error); |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 55 | LOG_IF(WARNING, !proxy) << "Error getting dbus proxy for " |
| 56 | << kUpdateEngineServiceName << ": " |
| 57 | << GetAndFreeGError(&error); |
Andrew de los Reyes | 68ab6ed | 2011-08-09 14:46:39 -0700 | [diff] [blame] | 58 | } |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 59 | if (proxy == nullptr) { |
Richard Barnette | d793606 | 2013-01-18 13:38:51 -0800 | [diff] [blame] | 60 | LOG(ERROR) << "Giving up -- unable to get dbus proxy for " |
| 61 | << kUpdateEngineServiceName; |
| 62 | exit(1); |
| 63 | } |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 64 | *out_proxy = proxy; |
| 65 | return true; |
| 66 | } |
| 67 | |
| 68 | static void StatusUpdateSignalHandler(DBusGProxy* proxy, |
| 69 | int64_t last_checked_time, |
| 70 | double progress, |
| 71 | gchar* current_operation, |
| 72 | gchar* new_version, |
| 73 | int64_t new_size, |
| 74 | void* user_data) { |
| 75 | LOG(INFO) << "Got status update:"; |
| 76 | LOG(INFO) << " last_checked_time: " << last_checked_time; |
| 77 | LOG(INFO) << " progress: " << progress; |
| 78 | LOG(INFO) << " current_operation: " << current_operation; |
| 79 | LOG(INFO) << " new_version: " << new_version; |
| 80 | LOG(INFO) << " new_size: " << new_size; |
| 81 | } |
| 82 | |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 83 | bool ResetStatus() { |
| 84 | DBusGProxy* proxy; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 85 | GError* error = nullptr; |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 86 | |
| 87 | CHECK(GetProxy(&proxy)); |
| 88 | |
Alex Deymo | 36dc2f3 | 2013-08-29 15:45:06 -0700 | [diff] [blame] | 89 | gboolean rc = update_engine_client_reset_status(proxy, &error); |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 90 | return rc; |
| 91 | } |
| 92 | |
| 93 | |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 94 | // If |op| is non-null, sets it to the current operation string or an |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 95 | // empty string if unable to obtain the current status. |
| 96 | bool GetStatus(string* op) { |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 97 | DBusGProxy* proxy; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 98 | GError* error = nullptr; |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 99 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 100 | CHECK(GetProxy(&proxy)); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 101 | |
| 102 | gint64 last_checked_time = 0; |
| 103 | gdouble progress = 0.0; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 104 | char* current_op = nullptr; |
| 105 | char* new_version = nullptr; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 106 | gint64 new_size = 0; |
| 107 | |
Alex Deymo | 36dc2f3 | 2013-08-29 15:45:06 -0700 | [diff] [blame] | 108 | gboolean rc = update_engine_client_get_status(proxy, |
| 109 | &last_checked_time, |
| 110 | &progress, |
| 111 | ¤t_op, |
| 112 | &new_version, |
| 113 | &new_size, |
| 114 | &error); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 115 | if (rc == FALSE) { |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 116 | LOG(INFO) << "Error getting status: " << GetAndFreeGError(&error); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 117 | } |
| 118 | printf("LAST_CHECKED_TIME=%" PRIi64 "\nPROGRESS=%f\nCURRENT_OP=%s\n" |
| 119 | "NEW_VERSION=%s\nNEW_SIZE=%" PRIi64 "\n", |
| 120 | last_checked_time, |
| 121 | progress, |
| 122 | current_op, |
| 123 | new_version, |
| 124 | new_size); |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 125 | if (op) { |
| 126 | *op = current_op ? current_op : ""; |
| 127 | } |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 128 | return true; |
| 129 | } |
| 130 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 131 | // Should never return. |
| 132 | void WatchForUpdates() { |
| 133 | DBusGProxy* proxy; |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 134 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 135 | CHECK(GetProxy(&proxy)); |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 136 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 137 | // Register marshaller |
| 138 | dbus_g_object_register_marshaller( |
David Zeuthen | 7cb12f9 | 2014-04-08 10:35:39 -0700 | [diff] [blame] | 139 | g_cclosure_marshal_generic, |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 140 | G_TYPE_NONE, |
| 141 | G_TYPE_INT64, |
| 142 | G_TYPE_DOUBLE, |
| 143 | G_TYPE_STRING, |
| 144 | G_TYPE_STRING, |
| 145 | G_TYPE_INT64, |
| 146 | G_TYPE_INVALID); |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 147 | |
| 148 | static const char kStatusUpdate[] = "StatusUpdate"; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 149 | dbus_g_proxy_add_signal(proxy, |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 150 | kStatusUpdate, |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 151 | G_TYPE_INT64, |
| 152 | G_TYPE_DOUBLE, |
| 153 | G_TYPE_STRING, |
| 154 | G_TYPE_STRING, |
| 155 | G_TYPE_INT64, |
| 156 | G_TYPE_INVALID); |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 157 | GMainLoop* loop = g_main_loop_new(nullptr, TRUE); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 158 | dbus_g_proxy_connect_signal(proxy, |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 159 | kStatusUpdate, |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 160 | G_CALLBACK(StatusUpdateSignalHandler), |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 161 | nullptr, |
| 162 | nullptr); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 163 | g_main_loop_run(loop); |
| 164 | g_main_loop_unref(loop); |
| 165 | } |
| 166 | |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 167 | bool Rollback(bool rollback) { |
| 168 | DBusGProxy* proxy; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 169 | GError* error = nullptr; |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 170 | |
| 171 | CHECK(GetProxy(&proxy)); |
| 172 | |
Alex Deymo | 36dc2f3 | 2013-08-29 15:45:06 -0700 | [diff] [blame] | 173 | gboolean rc = update_engine_client_attempt_rollback(proxy, |
| 174 | rollback, |
| 175 | &error); |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 176 | CHECK_EQ(rc, TRUE) << "Error with rollback request: " |
| 177 | << GetAndFreeGError(&error); |
| 178 | return true; |
| 179 | } |
| 180 | |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 181 | string GetRollbackPartition() { |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 182 | DBusGProxy* proxy; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 183 | GError* error = nullptr; |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 184 | |
| 185 | CHECK(GetProxy(&proxy)); |
| 186 | |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 187 | char* rollback_partition = nullptr; |
| 188 | gboolean rc = update_engine_client_get_rollback_partition(proxy, |
| 189 | &rollback_partition, |
| 190 | &error); |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 191 | CHECK_EQ(rc, TRUE) << "Error while querying rollback partition availabilty: " |
| 192 | << GetAndFreeGError(&error); |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 193 | string partition = rollback_partition; |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 194 | g_free(rollback_partition); |
| 195 | return partition; |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 196 | } |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 197 | |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 198 | string GetKernelDevices() { |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 199 | DBusGProxy* proxy; |
| 200 | GError* error = nullptr; |
| 201 | |
| 202 | CHECK(GetProxy(&proxy)); |
| 203 | |
| 204 | char* kernel_devices = nullptr; |
| 205 | gboolean rc = update_engine_client_get_kernel_devices(proxy, |
| 206 | &kernel_devices, |
| 207 | &error); |
| 208 | CHECK_EQ(rc, TRUE) << "Error while getting a list of kernel devices: " |
| 209 | << GetAndFreeGError(&error); |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 210 | string devices = kernel_devices; |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 211 | g_free(kernel_devices); |
| 212 | return devices; |
| 213 | } |
| 214 | |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 215 | bool CheckForUpdates(const string& app_version, |
| 216 | const string& omaha_url, |
| 217 | bool interactive) { |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 218 | DBusGProxy* proxy; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 219 | GError* error = nullptr; |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 220 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 221 | CHECK(GetProxy(&proxy)); |
| 222 | |
David Zeuthen | 75a4c3e | 2013-09-06 11:36:59 -0700 | [diff] [blame] | 223 | AttemptUpdateFlags flags = static_cast<AttemptUpdateFlags>( |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 224 | interactive ? 0 : kAttemptUpdateFlagNonInteractive); |
David Zeuthen | 75a4c3e | 2013-09-06 11:36:59 -0700 | [diff] [blame] | 225 | gboolean rc = |
| 226 | update_engine_client_attempt_update_with_flags(proxy, |
| 227 | app_version.c_str(), |
| 228 | omaha_url.c_str(), |
| 229 | static_cast<gint>(flags), |
| 230 | &error); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 231 | CHECK_EQ(rc, TRUE) << "Error checking for update: " |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 232 | << GetAndFreeGError(&error); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 233 | return true; |
| 234 | } |
| 235 | |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 236 | bool RebootIfNeeded() { |
| 237 | DBusGProxy* proxy; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 238 | GError* error = nullptr; |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 239 | |
| 240 | CHECK(GetProxy(&proxy)); |
| 241 | |
| 242 | gboolean rc = |
Alex Deymo | 36dc2f3 | 2013-08-29 15:45:06 -0700 | [diff] [blame] | 243 | update_engine_client_reboot_if_needed(proxy, &error); |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 244 | // Reboot error code doesn't necessarily mean that a reboot |
| 245 | // failed. For example, D-Bus may be shutdown before we receive the |
| 246 | // result. |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 247 | LOG_IF(INFO, !rc) << "Reboot error message: " << GetAndFreeGError(&error); |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 248 | return true; |
| 249 | } |
| 250 | |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 251 | void SetTargetChannel(const string& target_channel, bool allow_powerwash) { |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 252 | DBusGProxy* proxy; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 253 | GError* error = nullptr; |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 254 | |
| 255 | CHECK(GetProxy(&proxy)); |
| 256 | |
Alex Deymo | 36dc2f3 | 2013-08-29 15:45:06 -0700 | [diff] [blame] | 257 | gboolean rc = update_engine_client_set_channel(proxy, |
| 258 | target_channel.c_str(), |
| 259 | allow_powerwash, |
| 260 | &error); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 261 | CHECK_EQ(rc, true) << "Error setting the channel: " |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 262 | << GetAndFreeGError(&error); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 263 | LOG(INFO) << "Channel permanently set to: " << target_channel; |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 266 | string GetChannel(bool get_current_channel) { |
Satoru Takabayashi | 583667b | 2010-10-27 13:09:57 +0900 | [diff] [blame] | 267 | DBusGProxy* proxy; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 268 | GError* error = nullptr; |
Satoru Takabayashi | 583667b | 2010-10-27 13:09:57 +0900 | [diff] [blame] | 269 | |
| 270 | CHECK(GetProxy(&proxy)); |
| 271 | |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 272 | char* channel = nullptr; |
Alex Deymo | 36dc2f3 | 2013-08-29 15:45:06 -0700 | [diff] [blame] | 273 | gboolean rc = update_engine_client_get_channel(proxy, |
| 274 | get_current_channel, |
| 275 | &channel, |
| 276 | &error); |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 277 | CHECK_EQ(rc, true) << "Error getting the channel: " |
| 278 | << GetAndFreeGError(&error); |
| 279 | string output = channel; |
| 280 | g_free(channel); |
Satoru Takabayashi | 583667b | 2010-10-27 13:09:57 +0900 | [diff] [blame] | 281 | return output; |
| 282 | } |
| 283 | |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 284 | void SetUpdateOverCellularPermission(gboolean allowed) { |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 285 | DBusGProxy* proxy; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 286 | GError* error = nullptr; |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 287 | |
| 288 | CHECK(GetProxy(&proxy)); |
| 289 | |
Alex Deymo | 36dc2f3 | 2013-08-29 15:45:06 -0700 | [diff] [blame] | 290 | gboolean rc = update_engine_client_set_update_over_cellular_permission( |
| 291 | proxy, |
| 292 | allowed, |
| 293 | &error); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 294 | CHECK_EQ(rc, true) << "Error setting the update over cellular setting: " |
| 295 | << GetAndFreeGError(&error); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | bool GetUpdateOverCellularPermission() { |
| 299 | DBusGProxy* proxy; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 300 | GError* error = nullptr; |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 301 | |
| 302 | CHECK(GetProxy(&proxy)); |
| 303 | |
| 304 | gboolean allowed; |
Alex Deymo | 36dc2f3 | 2013-08-29 15:45:06 -0700 | [diff] [blame] | 305 | gboolean rc = update_engine_client_get_update_over_cellular_permission( |
| 306 | proxy, |
| 307 | &allowed, |
| 308 | &error); |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 309 | CHECK_EQ(rc, true) << "Error getting the update over cellular setting: " |
| 310 | << GetAndFreeGError(&error); |
| 311 | return allowed; |
| 312 | } |
| 313 | |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 314 | void SetP2PUpdatePermission(gboolean enabled) { |
| 315 | DBusGProxy* proxy; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 316 | GError* error = nullptr; |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 317 | |
| 318 | CHECK(GetProxy(&proxy)); |
| 319 | |
Alex Deymo | 36dc2f3 | 2013-08-29 15:45:06 -0700 | [diff] [blame] | 320 | gboolean rc = update_engine_client_set_p2p_update_permission( |
| 321 | proxy, |
| 322 | enabled, |
| 323 | &error); |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 324 | CHECK_EQ(rc, true) << "Error setting the peer-to-peer update setting: " |
| 325 | << GetAndFreeGError(&error); |
| 326 | } |
| 327 | |
| 328 | bool GetP2PUpdatePermission() { |
| 329 | DBusGProxy* proxy; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 330 | GError* error = nullptr; |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 331 | |
| 332 | CHECK(GetProxy(&proxy)); |
| 333 | |
| 334 | gboolean enabled; |
Alex Deymo | 36dc2f3 | 2013-08-29 15:45:06 -0700 | [diff] [blame] | 335 | gboolean rc = update_engine_client_get_p2p_update_permission( |
| 336 | proxy, |
| 337 | &enabled, |
| 338 | &error); |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 339 | CHECK_EQ(rc, true) << "Error getting the peer-to-peer update setting: " |
| 340 | << GetAndFreeGError(&error); |
| 341 | return enabled; |
| 342 | } |
| 343 | |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 344 | static gboolean CompleteUpdateSource(gpointer data) { |
| 345 | string current_op; |
| 346 | if (!GetStatus(¤t_op) || current_op == "UPDATE_STATUS_IDLE") { |
| 347 | LOG(ERROR) << "Update failed."; |
| 348 | exit(1); |
| 349 | } |
| 350 | if (current_op == "UPDATE_STATUS_UPDATED_NEED_REBOOT") { |
| 351 | LOG(INFO) << "Update succeeded -- reboot needed."; |
| 352 | exit(0); |
| 353 | } |
| 354 | return TRUE; |
| 355 | } |
| 356 | |
| 357 | // This is similar to watching for updates but rather than registering |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 358 | // a signal watch, actively poll the daemon just in case it stops |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 359 | // sending notifications. |
| 360 | void CompleteUpdate() { |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 361 | GMainLoop* loop = g_main_loop_new(nullptr, TRUE); |
| 362 | g_timeout_add_seconds(5, CompleteUpdateSource, nullptr); |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 363 | g_main_loop_run(loop); |
| 364 | g_main_loop_unref(loop); |
| 365 | } |
| 366 | |
Alex Vakulenko | dea2eac | 2014-03-14 15:56:59 -0700 | [diff] [blame] | 367 | void ShowPrevVersion() { |
| 368 | DBusGProxy* proxy; |
| 369 | GError* error = nullptr; |
| 370 | |
| 371 | CHECK(GetProxy(&proxy)); |
| 372 | |
| 373 | char* prev_version = nullptr; |
| 374 | |
| 375 | gboolean rc = update_engine_client_get_prev_version(proxy, |
| 376 | &prev_version, |
| 377 | &error); |
| 378 | if (!rc) { |
| 379 | LOG(ERROR) << "Error getting previous version: " |
| 380 | << GetAndFreeGError(&error); |
| 381 | } else { |
| 382 | LOG(INFO) << "Previous version = " << prev_version; |
| 383 | g_free(prev_version); |
| 384 | } |
| 385 | } |
| 386 | |
David Zeuthen | 9d73a72 | 2014-04-04 14:52:46 -0700 | [diff] [blame] | 387 | bool CheckIfRebootIsNeeded(DBusGProxy *proxy, bool *out_reboot_needed) { |
| 388 | gint64 last_checked_time = 0; |
| 389 | gdouble progress = 0.0; |
| 390 | char* current_op = nullptr; |
| 391 | char* new_version = nullptr; |
| 392 | gint64 new_size = 0; |
| 393 | GError* error = nullptr; |
| 394 | |
| 395 | if (!update_engine_client_get_status(proxy, |
| 396 | &last_checked_time, |
| 397 | &progress, |
| 398 | ¤t_op, |
| 399 | &new_version, |
| 400 | &new_size, |
| 401 | &error)) { |
| 402 | LOG(INFO) << "Error getting status: " << GetAndFreeGError(&error); |
| 403 | return false; |
| 404 | } |
| 405 | *out_reboot_needed = |
| 406 | (g_strcmp0(current_op, |
| 407 | update_engine::kUpdateStatusUpdatedNeedReboot) == 0); |
| 408 | g_free(current_op); |
| 409 | g_free(new_version); |
| 410 | return true; |
| 411 | } |
| 412 | |
| 413 | // Determines if reboot is needed. The result is returned in |
| 414 | // |out_reboot_needed|. Returns true if the check succeeded, false |
| 415 | // otherwise. |
| 416 | bool IsRebootNeeded(bool *out_reboot_needed) { |
| 417 | DBusGProxy* proxy = nullptr; |
| 418 | CHECK(GetProxy(&proxy)); |
| 419 | bool ret = CheckIfRebootIsNeeded(proxy, out_reboot_needed); |
| 420 | g_object_unref(proxy); |
| 421 | return ret; |
| 422 | } |
| 423 | |
| 424 | static void OnBlockUntilRebootStatusCallback( |
| 425 | DBusGProxy* proxy, |
| 426 | int64_t last_checked_time, |
| 427 | double progress, |
| 428 | const gchar* current_operation, |
| 429 | const gchar* new_version, |
| 430 | int64_t new_size, |
| 431 | void* user_data) { |
| 432 | GMainLoop *loop = reinterpret_cast<GMainLoop*>(user_data); |
| 433 | if (g_strcmp0(current_operation, |
| 434 | update_engine::kUpdateStatusUpdatedNeedReboot) == 0) { |
| 435 | g_main_loop_quit(loop); |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | bool CheckRebootNeeded(DBusGProxy *proxy, GMainLoop *loop) { |
| 440 | bool reboot_needed; |
| 441 | if (!CheckIfRebootIsNeeded(proxy, &reboot_needed)) |
| 442 | return false; |
| 443 | if (reboot_needed) |
| 444 | return true; |
| 445 | // This will block until OnBlockUntilRebootStatusCallback() calls |
| 446 | // g_main_loop_quit(). |
| 447 | g_main_loop_run(loop); |
| 448 | return true; |
| 449 | } |
| 450 | |
| 451 | // Blocks until a reboot is needed. Returns true if waiting succeeded, |
| 452 | // false if an error occurred. |
| 453 | bool BlockUntilRebootIsNeeded() { |
| 454 | // The basic idea is to get a proxy, listen to signals and only then |
| 455 | // check the status. If no reboot is needed, just sit and wait for |
| 456 | // the StatusUpdate signal to convey that a reboot is pending. |
| 457 | DBusGProxy* proxy = nullptr; |
| 458 | CHECK(GetProxy(&proxy)); |
| 459 | dbus_g_object_register_marshaller( |
| 460 | g_cclosure_marshal_generic, |
| 461 | G_TYPE_NONE, |
| 462 | G_TYPE_INT64, |
| 463 | G_TYPE_DOUBLE, |
| 464 | G_TYPE_STRING, |
| 465 | G_TYPE_STRING, |
| 466 | G_TYPE_INT64, |
| 467 | G_TYPE_INVALID); |
| 468 | dbus_g_proxy_add_signal(proxy, |
| 469 | update_engine::kStatusUpdate, // Signal name. |
| 470 | G_TYPE_INT64, |
| 471 | G_TYPE_DOUBLE, |
| 472 | G_TYPE_STRING, |
| 473 | G_TYPE_STRING, |
| 474 | G_TYPE_INT64, |
| 475 | G_TYPE_INVALID); |
| 476 | GMainLoop* loop = g_main_loop_new(nullptr, TRUE); |
| 477 | dbus_g_proxy_connect_signal(proxy, |
| 478 | update_engine::kStatusUpdate, |
| 479 | G_CALLBACK(OnBlockUntilRebootStatusCallback), |
| 480 | loop, |
| 481 | nullptr); // free_data_func. |
| 482 | |
| 483 | bool ret = CheckRebootNeeded(proxy, loop); |
| 484 | |
| 485 | dbus_g_proxy_disconnect_signal(proxy, |
| 486 | update_engine::kStatusUpdate, |
| 487 | G_CALLBACK(OnBlockUntilRebootStatusCallback), |
| 488 | loop); |
| 489 | g_main_loop_unref(loop); |
| 490 | g_object_unref(proxy); |
| 491 | return ret; |
| 492 | } |
| 493 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 494 | } // namespace |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 495 | |
| 496 | int main(int argc, char** argv) { |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 497 | DEFINE_string(app_version, "", "Force the current app version."); |
| 498 | DEFINE_string(channel, "", |
| 499 | "Set the target channel. The device will be powerwashed if the " |
| 500 | "target channel is more stable than the current channel unless " |
| 501 | "--nopowerwash is specified."); |
| 502 | DEFINE_bool(check_for_update, false, "Initiate check for updates."); |
| 503 | DEFINE_bool(follow, false, "Wait for any update operations to complete." |
| 504 | "Exit status is 0 if the update succeeded, and 1 otherwise."); |
| 505 | DEFINE_bool(interactive, true, "Mark the update request as interactive."); |
| 506 | DEFINE_string(omaha_url, "", "The URL of the Omaha update server."); |
| 507 | DEFINE_string(p2p_update, "", |
| 508 | "Enables (\"yes\") or disables (\"no\") the peer-to-peer update" |
| 509 | " sharing."); |
| 510 | DEFINE_bool(powerwash, true, "When performing rollback or channel change, " |
| 511 | "do a powerwash or allow it respectively."); |
| 512 | DEFINE_bool(reboot, false, "Initiate a reboot if needed."); |
| 513 | DEFINE_bool(is_reboot_needed, false, "Exit status 0 if reboot is needed, " |
| 514 | "2 if reboot is not needed or 1 if an error occurred."); |
| 515 | DEFINE_bool(block_until_reboot_is_needed, false, "Blocks until reboot is " |
| 516 | "needed. Returns non-zero exit status if an error occurred."); |
| 517 | 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] | 518 | DEFINE_bool(rollback, false, |
| 519 | "Perform a rollback to the previous partition. The device will " |
| 520 | "be powerwashed unless --nopowerwash is specified."); |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 521 | DEFINE_bool(can_rollback, false, "Shows whether rollback partition " |
| 522 | "is available."); |
| 523 | DEFINE_bool(show_channel, false, "Show the current and target channels."); |
| 524 | DEFINE_bool(show_p2p_update, false, |
| 525 | "Show the current setting for peer-to-peer update sharing."); |
| 526 | DEFINE_bool(show_update_over_cellular, false, |
| 527 | "Show the current setting for updates over cellular networks."); |
| 528 | DEFINE_bool(status, false, "Print the status to stdout."); |
| 529 | DEFINE_bool(update, false, "Forces an update and waits for it to complete. " |
| 530 | "Implies --follow."); |
| 531 | DEFINE_string(update_over_cellular, "", |
| 532 | "Enables (\"yes\") or disables (\"no\") the updates over " |
| 533 | "cellular networks."); |
| 534 | DEFINE_bool(watch_for_updates, false, |
| 535 | "Listen for status updates and print them to the screen."); |
| 536 | DEFINE_bool(prev_version, false, |
| 537 | "Show the previous OS version used before the update reboot."); |
| 538 | DEFINE_bool(show_kernels, false, "Show the list of kernel patritions and " |
| 539 | "whether each of them is bootable or not"); |
| 540 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 541 | // Boilerplate init commands. |
| 542 | g_type_init(); |
Ben Chan | 46bf5c8 | 2013-06-24 11:17:41 -0700 | [diff] [blame] | 543 | dbus_threads_init_default(); |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 544 | chromeos::FlagHelper::Init(argc, argv, "Chromium OS Update Engine Client"); |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 545 | |
Alex Deymo | 8ce80d6 | 2015-01-27 15:10:43 -0800 | [diff] [blame^] | 546 | // Ensure there are no positional arguments. |
| 547 | const std::vector<string> positional_args = |
| 548 | base::CommandLine::ForCurrentProcess()->GetArgs(); |
| 549 | if (!positional_args.empty()) { |
| 550 | LOG(ERROR) << "Found a positional argument '" << positional_args.front() |
| 551 | << "'. If you want to pass a value to a flag, pass it as " |
| 552 | "--flag=value."; |
| 553 | return 1; |
| 554 | } |
| 555 | |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 556 | // Update the status if requested. |
| 557 | if (FLAGS_reset_status) { |
| 558 | LOG(INFO) << "Setting Update Engine status to idle ..."; |
| 559 | if (!ResetStatus()) { |
| 560 | LOG(ERROR) << "ResetStatus failed."; |
| 561 | return 1; |
| 562 | } |
Gilad Arnold | 50c6063 | 2013-01-25 10:27:19 -0800 | [diff] [blame] | 563 | LOG(INFO) << "ResetStatus succeeded; to undo partition table changes run:\n" |
| 564 | "(D=$(rootdev -d) P=$(rootdev -s); cgpt p -i$(($(echo ${P#$D} " |
| 565 | "| sed 's/^[^0-9]*//')-1)) $D;)"; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 566 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 567 | |
Alex Deymo | f4867c4 | 2013-06-28 14:41:39 -0700 | [diff] [blame] | 568 | // Changes the current update over cellular network setting. |
| 569 | if (!FLAGS_update_over_cellular.empty()) { |
| 570 | gboolean allowed = FLAGS_update_over_cellular == "yes"; |
| 571 | if (!allowed && FLAGS_update_over_cellular != "no") { |
| 572 | LOG(ERROR) << "Unknown option: \"" << FLAGS_update_over_cellular |
| 573 | << "\". Please specify \"yes\" or \"no\"."; |
| 574 | } else { |
| 575 | SetUpdateOverCellularPermission(allowed); |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | // Show the current update over cellular network setting. |
| 580 | if (FLAGS_show_update_over_cellular) { |
| 581 | bool allowed = GetUpdateOverCellularPermission(); |
| 582 | LOG(INFO) << "Current update over cellular network setting: " |
| 583 | << (allowed ? "ENABLED" : "DISABLED"); |
| 584 | } |
| 585 | |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 586 | if (!FLAGS_powerwash && !FLAGS_rollback && FLAGS_channel.empty()) { |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 587 | LOG(ERROR) << "powerwash flag only makes sense rollback or channel change"; |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 588 | return 1; |
| 589 | } |
| 590 | |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 591 | // Change the P2P enabled setting. |
| 592 | if (!FLAGS_p2p_update.empty()) { |
| 593 | gboolean enabled = FLAGS_p2p_update == "yes"; |
| 594 | if (!enabled && FLAGS_p2p_update != "no") { |
| 595 | LOG(ERROR) << "Unknown option: \"" << FLAGS_p2p_update |
| 596 | << "\". Please specify \"yes\" or \"no\"."; |
| 597 | } else { |
| 598 | SetP2PUpdatePermission(enabled); |
| 599 | } |
| 600 | } |
| 601 | |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 602 | // Show the rollback availability. |
| 603 | if (FLAGS_can_rollback) { |
Alex Deymo | f329b93 | 2014-10-30 01:37:48 -0700 | [diff] [blame] | 604 | string rollback_partition = GetRollbackPartition(); |
Chris Sosa | f5c0b9c | 2014-04-17 16:12:03 -0700 | [diff] [blame] | 605 | bool can_rollback = true; |
| 606 | if (rollback_partition.empty()) { |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 607 | rollback_partition = "UNAVAILABLE"; |
Chris Sosa | f5c0b9c | 2014-04-17 16:12:03 -0700 | [diff] [blame] | 608 | can_rollback = false; |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 609 | } else { |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 610 | rollback_partition = "AVAILABLE: " + rollback_partition; |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 611 | } |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 612 | |
| 613 | LOG(INFO) << "Rollback partition: " << rollback_partition; |
Chris Sosa | f5c0b9c | 2014-04-17 16:12:03 -0700 | [diff] [blame] | 614 | if (!can_rollback) { |
| 615 | return 1; |
| 616 | } |
Alex Vakulenko | 59e253e | 2014-02-24 10:40:21 -0800 | [diff] [blame] | 617 | } |
| 618 | |
Alex Deymo | 5fdf776 | 2013-07-17 20:01:40 -0700 | [diff] [blame] | 619 | // Show the current P2P enabled setting. |
| 620 | if (FLAGS_show_p2p_update) { |
| 621 | bool enabled = GetP2PUpdatePermission(); |
| 622 | LOG(INFO) << "Current update using P2P setting: " |
| 623 | << (enabled ? "ENABLED" : "DISABLED"); |
| 624 | } |
| 625 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 626 | // First, update the target channel if requested. |
| 627 | if (!FLAGS_channel.empty()) |
Chris Sosa | cb7fa88 | 2013-07-25 17:02:59 -0700 | [diff] [blame] | 628 | SetTargetChannel(FLAGS_channel, FLAGS_powerwash); |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 629 | |
Jay Srinivasan | ae4697c | 2013-03-18 17:08:08 -0700 | [diff] [blame] | 630 | // Show the current and target channels if requested. |
| 631 | if (FLAGS_show_channel) { |
| 632 | string current_channel = GetChannel(true); |
| 633 | LOG(INFO) << "Current Channel: " << current_channel; |
| 634 | |
| 635 | string target_channel = GetChannel(false); |
| 636 | if (!target_channel.empty()) |
| 637 | LOG(INFO) << "Target Channel (pending update): " << target_channel; |
Satoru Takabayashi | 583667b | 2010-10-27 13:09:57 +0900 | [diff] [blame] | 638 | } |
| 639 | |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 640 | bool do_update_request = FLAGS_check_for_update | FLAGS_update | |
| 641 | !FLAGS_app_version.empty() | !FLAGS_omaha_url.empty(); |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 642 | if (FLAGS_update) |
| 643 | FLAGS_follow = true; |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 644 | |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 645 | if (do_update_request && FLAGS_rollback) { |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 646 | LOG(ERROR) << "Incompatible flags specified with rollback." |
| 647 | << "Rollback should not include update-related flags."; |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 648 | return 1; |
| 649 | } |
| 650 | |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 651 | if (FLAGS_rollback) { |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 652 | LOG(INFO) << "Requesting rollback."; |
| 653 | CHECK(Rollback(FLAGS_powerwash)) << "Request for rollback failed."; |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 654 | } |
| 655 | |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 656 | // Initiate an update check, if necessary. |
Chris Sosa | d317e40 | 2013-06-12 13:47:09 -0700 | [diff] [blame] | 657 | if (do_update_request) { |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 658 | LOG_IF(WARNING, FLAGS_reboot) << "-reboot flag ignored."; |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 659 | string app_version = FLAGS_app_version; |
| 660 | if (FLAGS_update && app_version.empty()) { |
| 661 | app_version = "ForcedUpdate"; |
| 662 | 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] | 663 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 664 | LOG(INFO) << "Initiating update check and install."; |
Steve Fung | 97b6f5a | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 665 | CHECK(CheckForUpdates(app_version, FLAGS_omaha_url, FLAGS_interactive)) |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 666 | << "Update check/initiate update failed."; |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 667 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 668 | |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 669 | // These final options are all mutually exclusive with one another. |
David Zeuthen | 9d73a72 | 2014-04-04 14:52:46 -0700 | [diff] [blame] | 670 | if (FLAGS_follow + FLAGS_watch_for_updates + FLAGS_reboot + |
| 671 | FLAGS_status + FLAGS_is_reboot_needed + |
Alex Vakulenko | d2779df | 2014-06-16 13:19:00 -0700 | [diff] [blame] | 672 | FLAGS_block_until_reboot_is_needed > 1) { |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 673 | LOG(ERROR) << "Multiple exclusive options selected. " |
| 674 | << "Select only one of --follow, --watch_for_updates, --reboot, " |
David Zeuthen | 9d73a72 | 2014-04-04 14:52:46 -0700 | [diff] [blame] | 675 | << "--is_reboot_needed, --block_until_reboot_is_needed, " |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 676 | << "or --status."; |
| 677 | return 1; |
| 678 | } |
| 679 | |
| 680 | if (FLAGS_status) { |
| 681 | LOG(INFO) << "Querying Update Engine status..."; |
Alex Vakulenko | 88b591f | 2014-08-28 16:48:57 -0700 | [diff] [blame] | 682 | if (!GetStatus(nullptr)) { |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 683 | LOG(ERROR) << "GetStatus failed."; |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 684 | return 1; |
| 685 | } |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 686 | return 0; |
| 687 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 688 | |
Chris Sosa | 192449e | 2013-10-28 14:16:19 -0700 | [diff] [blame] | 689 | if (FLAGS_follow) { |
| 690 | LOG(INFO) << "Waiting for update to complete."; |
| 691 | CompleteUpdate(); // Should never return. |
| 692 | return 1; |
| 693 | } |
| 694 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 695 | if (FLAGS_watch_for_updates) { |
| 696 | LOG(INFO) << "Watching for status updates."; |
| 697 | WatchForUpdates(); // Should never return. |
| 698 | return 1; |
| 699 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 700 | |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 701 | if (FLAGS_reboot) { |
| 702 | LOG(INFO) << "Requesting a reboot..."; |
| 703 | CHECK(RebootIfNeeded()); |
| 704 | return 0; |
| 705 | } |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 706 | |
Alex Vakulenko | dea2eac | 2014-03-14 15:56:59 -0700 | [diff] [blame] | 707 | if (FLAGS_prev_version) { |
| 708 | ShowPrevVersion(); |
| 709 | } |
| 710 | |
Alex Vakulenko | 2bddadd | 2014-03-27 13:23:46 -0700 | [diff] [blame] | 711 | if (FLAGS_show_kernels) { |
| 712 | LOG(INFO) << "Kernel partitions:\n" |
| 713 | << GetKernelDevices(); |
| 714 | } |
| 715 | |
David Zeuthen | 9d73a72 | 2014-04-04 14:52:46 -0700 | [diff] [blame] | 716 | if (FLAGS_is_reboot_needed) { |
| 717 | bool reboot_needed = false; |
| 718 | if (!IsRebootNeeded(&reboot_needed)) |
| 719 | return 1; |
| 720 | else if (!reboot_needed) |
| 721 | return 2; |
| 722 | } |
| 723 | |
| 724 | if (FLAGS_block_until_reboot_is_needed) { |
| 725 | if (!BlockUntilRebootIsNeeded()) |
| 726 | return 1; |
| 727 | } |
| 728 | |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 729 | LOG(INFO) << "Done."; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 730 | return 0; |
| 731 | } |