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 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 7 | #include <gflags/gflags.h> |
| 8 | #include <glib.h> |
| 9 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 10 | #include "update_engine/marshal.glibmarshal.h" |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 11 | #include "update_engine/dbus_constants.h" |
| 12 | #include "update_engine/subprocess.h" |
| 13 | #include "update_engine/utils.h" |
| 14 | |
| 15 | extern "C" { |
| 16 | #include "update_engine/update_engine.dbusclient.h" |
| 17 | } |
| 18 | |
| 19 | using chromeos_update_engine::kUpdateEngineServiceName; |
| 20 | using chromeos_update_engine::kUpdateEngineServicePath; |
| 21 | using chromeos_update_engine::kUpdateEngineServiceInterface; |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 22 | using chromeos_update_engine::utils::GetAndFreeGError; |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 23 | using std::string; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 24 | |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 25 | DEFINE_string(app_version, "", "Force the current app version."); |
| 26 | DEFINE_bool(check_for_update, false, "Initiate check for updates."); |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 27 | DEFINE_string(omaha_url, "", "The URL of the Omaha update server."); |
| 28 | DEFINE_bool(reboot, false, "Initiate a reboot if needed."); |
Satoru Takabayashi | 583667b | 2010-10-27 13:09:57 +0900 | [diff] [blame] | 29 | DEFINE_bool(show_track, false, "Show the update track."); |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 30 | DEFINE_bool(status, false, "Print the status to stdout."); |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 31 | DEFINE_bool(reset_status, false, "Sets the status in update_engine to idle."); |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 32 | DEFINE_string(track, "", "Permanently change the update track."); |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 33 | DEFINE_bool(update, false, "Forces an update and waits for its completion. " |
| 34 | "Exit status is 0 if the update succeeded, and 1 otherwise."); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 35 | DEFINE_bool(watch_for_updates, false, |
| 36 | "Listen for status updates and print them to the screen."); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 37 | |
| 38 | namespace { |
| 39 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 40 | bool GetProxy(DBusGProxy** out_proxy) { |
| 41 | DBusGConnection* bus; |
Andrew de los Reyes | 68ab6ed | 2011-08-09 14:46:39 -0700 | [diff] [blame] | 42 | DBusGProxy* proxy = NULL; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 43 | GError* error = NULL; |
Andrew de los Reyes | 68ab6ed | 2011-08-09 14:46:39 -0700 | [diff] [blame] | 44 | const int kTries = 4; |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 45 | const int kRetrySeconds = 10; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 46 | |
| 47 | bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); |
Richard Barnette | d793606 | 2013-01-18 13:38:51 -0800 | [diff] [blame] | 48 | if (bus == NULL) { |
| 49 | LOG(ERROR) << "Failed to get bus: " << GetAndFreeGError(&error); |
| 50 | exit(1); |
| 51 | } |
Andrew de los Reyes | 68ab6ed | 2011-08-09 14:46:39 -0700 | [diff] [blame] | 52 | for (int i = 0; !proxy && i < kTries; ++i) { |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 53 | if (i > 0) { |
| 54 | LOG(INFO) << "Retrying to get dbus proxy. Try " |
| 55 | << (i + 1) << "/" << kTries; |
Gilad Arnold | 8e3f126 | 2013-01-08 14:59:54 -0800 | [diff] [blame] | 56 | g_usleep(kRetrySeconds * G_USEC_PER_SEC); |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 57 | } |
Andrew de los Reyes | 68ab6ed | 2011-08-09 14:46:39 -0700 | [diff] [blame] | 58 | proxy = dbus_g_proxy_new_for_name_owner(bus, |
| 59 | kUpdateEngineServiceName, |
| 60 | kUpdateEngineServicePath, |
| 61 | kUpdateEngineServiceInterface, |
| 62 | &error); |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 63 | LOG_IF(WARNING, !proxy) << "Error getting dbus proxy for " |
| 64 | << kUpdateEngineServiceName << ": " |
| 65 | << GetAndFreeGError(&error); |
Andrew de los Reyes | 68ab6ed | 2011-08-09 14:46:39 -0700 | [diff] [blame] | 66 | } |
Richard Barnette | d793606 | 2013-01-18 13:38:51 -0800 | [diff] [blame] | 67 | if (proxy == NULL) { |
| 68 | LOG(ERROR) << "Giving up -- unable to get dbus proxy for " |
| 69 | << kUpdateEngineServiceName; |
| 70 | exit(1); |
| 71 | } |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 72 | *out_proxy = proxy; |
| 73 | return true; |
| 74 | } |
| 75 | |
| 76 | static void StatusUpdateSignalHandler(DBusGProxy* proxy, |
| 77 | int64_t last_checked_time, |
| 78 | double progress, |
| 79 | gchar* current_operation, |
| 80 | gchar* new_version, |
| 81 | int64_t new_size, |
| 82 | void* user_data) { |
| 83 | LOG(INFO) << "Got status update:"; |
| 84 | LOG(INFO) << " last_checked_time: " << last_checked_time; |
| 85 | LOG(INFO) << " progress: " << progress; |
| 86 | LOG(INFO) << " current_operation: " << current_operation; |
| 87 | LOG(INFO) << " new_version: " << new_version; |
| 88 | LOG(INFO) << " new_size: " << new_size; |
| 89 | } |
| 90 | |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 91 | bool ResetStatus() { |
| 92 | DBusGProxy* proxy; |
| 93 | GError* error = NULL; |
| 94 | |
| 95 | CHECK(GetProxy(&proxy)); |
| 96 | |
| 97 | gboolean rc = |
| 98 | org_chromium_UpdateEngineInterface_reset_status(proxy, &error); |
| 99 | return rc; |
| 100 | } |
| 101 | |
| 102 | |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 103 | // If |op| is non-NULL, sets it to the current operation string or an |
| 104 | // empty string if unable to obtain the current status. |
| 105 | bool GetStatus(string* op) { |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 106 | DBusGProxy* proxy; |
| 107 | GError* error = NULL; |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 108 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 109 | CHECK(GetProxy(&proxy)); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 110 | |
| 111 | gint64 last_checked_time = 0; |
| 112 | gdouble progress = 0.0; |
| 113 | char* current_op = NULL; |
| 114 | char* new_version = NULL; |
| 115 | gint64 new_size = 0; |
| 116 | |
| 117 | gboolean rc = org_chromium_UpdateEngineInterface_get_status( |
| 118 | proxy, |
| 119 | &last_checked_time, |
| 120 | &progress, |
| 121 | ¤t_op, |
| 122 | &new_version, |
| 123 | &new_size, |
| 124 | &error); |
| 125 | if (rc == FALSE) { |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 126 | LOG(INFO) << "Error getting status: " << GetAndFreeGError(&error); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 127 | } |
| 128 | printf("LAST_CHECKED_TIME=%" PRIi64 "\nPROGRESS=%f\nCURRENT_OP=%s\n" |
| 129 | "NEW_VERSION=%s\nNEW_SIZE=%" PRIi64 "\n", |
| 130 | last_checked_time, |
| 131 | progress, |
| 132 | current_op, |
| 133 | new_version, |
| 134 | new_size); |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 135 | if (op) { |
| 136 | *op = current_op ? current_op : ""; |
| 137 | } |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 138 | return true; |
| 139 | } |
| 140 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 141 | // Should never return. |
| 142 | void WatchForUpdates() { |
| 143 | DBusGProxy* proxy; |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 144 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 145 | CHECK(GetProxy(&proxy)); |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 146 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 147 | // Register marshaller |
| 148 | dbus_g_object_register_marshaller( |
| 149 | update_engine_VOID__INT64_DOUBLE_STRING_STRING_INT64, |
| 150 | G_TYPE_NONE, |
| 151 | G_TYPE_INT64, |
| 152 | G_TYPE_DOUBLE, |
| 153 | G_TYPE_STRING, |
| 154 | G_TYPE_STRING, |
| 155 | G_TYPE_INT64, |
| 156 | G_TYPE_INVALID); |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 157 | |
| 158 | static const char kStatusUpdate[] = "StatusUpdate"; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 159 | dbus_g_proxy_add_signal(proxy, |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 160 | kStatusUpdate, |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 161 | G_TYPE_INT64, |
| 162 | G_TYPE_DOUBLE, |
| 163 | G_TYPE_STRING, |
| 164 | G_TYPE_STRING, |
| 165 | G_TYPE_INT64, |
| 166 | G_TYPE_INVALID); |
| 167 | GMainLoop* loop = g_main_loop_new (NULL, TRUE); |
| 168 | dbus_g_proxy_connect_signal(proxy, |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 169 | kStatusUpdate, |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 170 | G_CALLBACK(StatusUpdateSignalHandler), |
| 171 | NULL, |
| 172 | NULL); |
| 173 | g_main_loop_run(loop); |
| 174 | g_main_loop_unref(loop); |
| 175 | } |
| 176 | |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 177 | bool CheckForUpdates(const string& app_version, const string& omaha_url) { |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 178 | DBusGProxy* proxy; |
| 179 | GError* error = NULL; |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 180 | |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 181 | CHECK(GetProxy(&proxy)); |
| 182 | |
| 183 | gboolean rc = |
Darin Petkov | 5a7f565 | 2010-07-22 21:40:09 -0700 | [diff] [blame] | 184 | org_chromium_UpdateEngineInterface_attempt_update(proxy, |
| 185 | app_version.c_str(), |
| 186 | omaha_url.c_str(), |
| 187 | &error); |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 188 | CHECK_EQ(rc, TRUE) << "Error checking for update: " |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 189 | << GetAndFreeGError(&error); |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 190 | return true; |
| 191 | } |
| 192 | |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 193 | bool RebootIfNeeded() { |
| 194 | DBusGProxy* proxy; |
| 195 | GError* error = NULL; |
| 196 | |
| 197 | CHECK(GetProxy(&proxy)); |
| 198 | |
| 199 | gboolean rc = |
| 200 | org_chromium_UpdateEngineInterface_reboot_if_needed(proxy, &error); |
| 201 | // Reboot error code doesn't necessarily mean that a reboot |
| 202 | // failed. For example, D-Bus may be shutdown before we receive the |
| 203 | // result. |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 204 | LOG_IF(INFO, !rc) << "Reboot error message: " << GetAndFreeGError(&error); |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 205 | return true; |
| 206 | } |
| 207 | |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 208 | void SetTrack(const string& track) { |
| 209 | DBusGProxy* proxy; |
| 210 | GError* error = NULL; |
| 211 | |
| 212 | CHECK(GetProxy(&proxy)); |
| 213 | |
| 214 | gboolean rc = |
| 215 | org_chromium_UpdateEngineInterface_set_track(proxy, |
| 216 | track.c_str(), |
| 217 | &error); |
| 218 | CHECK_EQ(rc, true) << "Error setting the track: " |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 219 | << GetAndFreeGError(&error); |
Darin Petkov | 49d9132 | 2010-10-25 16:34:58 -0700 | [diff] [blame] | 220 | LOG(INFO) << "Track permanently set to: " << track; |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 221 | } |
| 222 | |
Satoru Takabayashi | 583667b | 2010-10-27 13:09:57 +0900 | [diff] [blame] | 223 | string GetTrack() { |
| 224 | DBusGProxy* proxy; |
| 225 | GError* error = NULL; |
| 226 | |
| 227 | CHECK(GetProxy(&proxy)); |
| 228 | |
| 229 | char* track = NULL; |
| 230 | gboolean rc = |
| 231 | org_chromium_UpdateEngineInterface_get_track(proxy, |
| 232 | &track, |
| 233 | &error); |
Darin Petkov | a0b9e77 | 2011-10-06 05:05:56 -0700 | [diff] [blame] | 234 | CHECK_EQ(rc, true) << "Error getting the track: " << GetAndFreeGError(&error); |
Satoru Takabayashi | 583667b | 2010-10-27 13:09:57 +0900 | [diff] [blame] | 235 | string output = track; |
| 236 | g_free(track); |
| 237 | return output; |
| 238 | } |
| 239 | |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 240 | static gboolean CompleteUpdateSource(gpointer data) { |
| 241 | string current_op; |
| 242 | if (!GetStatus(¤t_op) || current_op == "UPDATE_STATUS_IDLE") { |
| 243 | LOG(ERROR) << "Update failed."; |
| 244 | exit(1); |
| 245 | } |
| 246 | if (current_op == "UPDATE_STATUS_UPDATED_NEED_REBOOT") { |
| 247 | LOG(INFO) << "Update succeeded -- reboot needed."; |
| 248 | exit(0); |
| 249 | } |
| 250 | return TRUE; |
| 251 | } |
| 252 | |
| 253 | // This is similar to watching for updates but rather than registering |
| 254 | // a signal watch, activelly poll the daemon just in case it stops |
| 255 | // sending notifications. |
| 256 | void CompleteUpdate() { |
| 257 | GMainLoop* loop = g_main_loop_new (NULL, TRUE); |
| 258 | g_timeout_add_seconds(5, CompleteUpdateSource, NULL); |
| 259 | g_main_loop_run(loop); |
| 260 | g_main_loop_unref(loop); |
| 261 | } |
| 262 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 263 | } // namespace {} |
| 264 | |
| 265 | int main(int argc, char** argv) { |
| 266 | // Boilerplate init commands. |
| 267 | g_type_init(); |
| 268 | g_thread_init(NULL); |
| 269 | dbus_g_thread_init(); |
| 270 | chromeos_update_engine::Subprocess::Init(); |
| 271 | google::ParseCommandLineFlags(&argc, &argv, true); |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 272 | |
Jay Srinivasan | c1ba09a | 2012-08-14 14:15:57 -0700 | [diff] [blame] | 273 | // Update the status if requested. |
| 274 | if (FLAGS_reset_status) { |
| 275 | LOG(INFO) << "Setting Update Engine status to idle ..."; |
| 276 | if (!ResetStatus()) { |
| 277 | LOG(ERROR) << "ResetStatus failed."; |
| 278 | return 1; |
| 279 | } |
| 280 | |
| 281 | LOG(INFO) << "ResetStatus succeeded."; |
| 282 | return 0; |
| 283 | } |
| 284 | |
| 285 | |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 286 | if (FLAGS_status) { |
| 287 | LOG(INFO) << "Querying Update Engine status..."; |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 288 | if (!GetStatus(NULL)) { |
| 289 | LOG(FATAL) << "GetStatus failed."; |
| 290 | return 1; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 291 | } |
| 292 | return 0; |
| 293 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 294 | |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 295 | // First, update the track if requested. |
| 296 | if (!FLAGS_track.empty()) { |
| 297 | SetTrack(FLAGS_track); |
| 298 | } |
| 299 | |
Satoru Takabayashi | 583667b | 2010-10-27 13:09:57 +0900 | [diff] [blame] | 300 | // Show the track if requested. |
| 301 | if (FLAGS_show_track) { |
| 302 | LOG(INFO) << "Track: " << GetTrack(); |
| 303 | } |
| 304 | |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 305 | // Initiate an update check, if necessary. |
| 306 | if (FLAGS_check_for_update || |
| 307 | FLAGS_update || |
| 308 | !FLAGS_app_version.empty() || |
| 309 | !FLAGS_omaha_url.empty()) { |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 310 | LOG_IF(WARNING, FLAGS_reboot) << "-reboot flag ignored."; |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 311 | string app_version = FLAGS_app_version; |
| 312 | if (FLAGS_update && app_version.empty()) { |
| 313 | app_version = "ForcedUpdate"; |
| 314 | 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] | 315 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 316 | LOG(INFO) << "Initiating update check and install."; |
| 317 | CHECK(CheckForUpdates(app_version, FLAGS_omaha_url)) |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 318 | << "Update check/initiate update failed."; |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 319 | |
| 320 | // Wait for an update to complete. |
| 321 | if (FLAGS_update) { |
Darin Petkov | 9d911fa | 2010-08-19 09:36:08 -0700 | [diff] [blame] | 322 | LOG(INFO) << "Waiting for update to complete."; |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 323 | CompleteUpdate(); // Should never return. |
| 324 | return 1; |
| 325 | } |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 326 | return 0; |
| 327 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 328 | |
| 329 | // Start watching for updates. |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 330 | if (FLAGS_watch_for_updates) { |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 331 | LOG_IF(WARNING, FLAGS_reboot) << "-reboot flag ignored."; |
Andrew de los Reyes | 63b96d7 | 2010-05-10 13:08:54 -0700 | [diff] [blame] | 332 | LOG(INFO) << "Watching for status updates."; |
| 333 | WatchForUpdates(); // Should never return. |
| 334 | return 1; |
| 335 | } |
Darin Petkov | 58529db | 2010-08-13 09:19:47 -0700 | [diff] [blame] | 336 | |
Darin Petkov | 296889c | 2010-07-23 16:20:54 -0700 | [diff] [blame] | 337 | if (FLAGS_reboot) { |
| 338 | LOG(INFO) << "Requesting a reboot..."; |
| 339 | CHECK(RebootIfNeeded()); |
| 340 | return 0; |
| 341 | } |
Andrew de los Reyes | ada4220 | 2010-07-15 22:23:20 -0700 | [diff] [blame] | 342 | |
Darin Petkov | 8daa324 | 2010-10-25 13:28:47 -0700 | [diff] [blame] | 343 | LOG(INFO) << "Done."; |
Andrew de los Reyes | 4e9b9f4 | 2010-04-26 15:06:43 -0700 | [diff] [blame] | 344 | return 0; |
| 345 | } |