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