| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include <gflags/gflags.h> | 7 #include <gflags/gflags.h> |
| 8 #include <glib.h> | 8 #include <glib.h> |
| 9 | 9 |
| 10 #include "update_engine/marshal.glibmarshal.h" | 10 #include "update_engine/marshal.glibmarshal.h" |
| 11 #include "update_engine/dbus_constants.h" | 11 #include "update_engine/dbus_constants.h" |
| 12 #include "update_engine/subprocess.h" | 12 #include "update_engine/subprocess.h" |
| 13 #include "update_engine/utils.h" | 13 #include "update_engine/utils.h" |
| 14 | 14 |
| 15 extern "C" { | 15 extern "C" { |
| 16 #include "update_engine/update_engine.dbusclient.h" | 16 #include "update_engine/update_engine.dbusclient.h" |
| 17 } | 17 } |
| 18 | 18 |
| 19 using chromeos_update_engine::kUpdateEngineServiceName; | 19 using chromeos_update_engine::kUpdateEngineServiceName; |
| 20 using chromeos_update_engine::kUpdateEngineServicePath; | 20 using chromeos_update_engine::kUpdateEngineServicePath; |
| 21 using chromeos_update_engine::kUpdateEngineServiceInterface; | 21 using chromeos_update_engine::kUpdateEngineServiceInterface; |
| 22 using chromeos_update_engine::utils::GetGErrorMessage; | 22 using chromeos_update_engine::utils::GetGErrorMessage; |
| 23 using std::string; | 23 using std::string; |
| 24 | 24 |
| 25 DEFINE_string(app_version, "", "Force the current app version."); | 25 DEFINE_string(app_version, "", "Force the current app version."); |
| 26 DEFINE_bool(check_for_update, false, "Initiate check for updates."); | 26 DEFINE_bool(check_for_update, false, "Initiate check for updates."); |
| 27 DEFINE_string(omaha_url, "", "The URL of the Omaha update server."); | 27 DEFINE_string(omaha_url, "", "The URL of the Omaha update server."); |
| 28 DEFINE_bool(reboot, false, "Initiate a reboot if needed."); | 28 DEFINE_bool(reboot, false, "Initiate a reboot if needed."); |
| 29 DEFINE_bool(show_track, false, "Show the update track."); |
| 29 DEFINE_bool(status, false, "Print the status to stdout."); | 30 DEFINE_bool(status, false, "Print the status to stdout."); |
| 30 DEFINE_string(track, "", "Permanently change the update track."); | 31 DEFINE_string(track, "", "Permanently change the update track."); |
| 31 DEFINE_bool(update, false, "Forces an update and waits for its completion. " | 32 DEFINE_bool(update, false, "Forces an update and waits for its completion. " |
| 32 "Exit status is 0 if the update succeeded, and 1 otherwise."); | 33 "Exit status is 0 if the update succeeded, and 1 otherwise."); |
| 33 DEFINE_bool(watch_for_updates, false, | 34 DEFINE_bool(watch_for_updates, false, |
| 34 "Listen for status updates and print them to the screen."); | 35 "Listen for status updates and print them to the screen."); |
| 35 | 36 |
| 36 namespace { | 37 namespace { |
| 37 | 38 |
| 38 bool GetProxy(DBusGProxy** out_proxy) { | 39 bool GetProxy(DBusGProxy** out_proxy) { |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 186 |
| 186 gboolean rc = | 187 gboolean rc = |
| 187 org_chromium_UpdateEngineInterface_set_track(proxy, | 188 org_chromium_UpdateEngineInterface_set_track(proxy, |
| 188 track.c_str(), | 189 track.c_str(), |
| 189 &error); | 190 &error); |
| 190 CHECK_EQ(rc, true) << "Error setting the track: " | 191 CHECK_EQ(rc, true) << "Error setting the track: " |
| 191 << GetGErrorMessage(error); | 192 << GetGErrorMessage(error); |
| 192 LOG(INFO) << "Track permanently set to: " << track; | 193 LOG(INFO) << "Track permanently set to: " << track; |
| 193 } | 194 } |
| 194 | 195 |
| 196 string GetTrack() { |
| 197 DBusGProxy* proxy; |
| 198 GError* error = NULL; |
| 199 |
| 200 CHECK(GetProxy(&proxy)); |
| 201 |
| 202 char* track = NULL; |
| 203 gboolean rc = |
| 204 org_chromium_UpdateEngineInterface_get_track(proxy, |
| 205 &track, |
| 206 &error); |
| 207 CHECK_EQ(rc, true) << "Error getting the track: " |
| 208 << GetGErrorMessage(error); |
| 209 string output = track; |
| 210 g_free(track); |
| 211 return output; |
| 212 } |
| 213 |
| 195 static gboolean CompleteUpdateSource(gpointer data) { | 214 static gboolean CompleteUpdateSource(gpointer data) { |
| 196 string current_op; | 215 string current_op; |
| 197 if (!GetStatus(¤t_op) || current_op == "UPDATE_STATUS_IDLE") { | 216 if (!GetStatus(¤t_op) || current_op == "UPDATE_STATUS_IDLE") { |
| 198 LOG(ERROR) << "Update failed."; | 217 LOG(ERROR) << "Update failed."; |
| 199 exit(1); | 218 exit(1); |
| 200 } | 219 } |
| 201 if (current_op == "UPDATE_STATUS_UPDATED_NEED_REBOOT") { | 220 if (current_op == "UPDATE_STATUS_UPDATED_NEED_REBOOT") { |
| 202 LOG(INFO) << "Update succeeded -- reboot needed."; | 221 LOG(INFO) << "Update succeeded -- reboot needed."; |
| 203 exit(0); | 222 exit(0); |
| 204 } | 223 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 232 return 1; | 251 return 1; |
| 233 } | 252 } |
| 234 return 0; | 253 return 0; |
| 235 } | 254 } |
| 236 | 255 |
| 237 // First, update the track if requested. | 256 // First, update the track if requested. |
| 238 if (!FLAGS_track.empty()) { | 257 if (!FLAGS_track.empty()) { |
| 239 SetTrack(FLAGS_track); | 258 SetTrack(FLAGS_track); |
| 240 } | 259 } |
| 241 | 260 |
| 261 // Show the track if requested. |
| 262 if (FLAGS_show_track) { |
| 263 LOG(INFO) << "Track: " << GetTrack(); |
| 264 } |
| 265 |
| 242 // Initiate an update check, if necessary. | 266 // Initiate an update check, if necessary. |
| 243 if (FLAGS_check_for_update || | 267 if (FLAGS_check_for_update || |
| 244 FLAGS_update || | 268 FLAGS_update || |
| 245 !FLAGS_app_version.empty() || | 269 !FLAGS_app_version.empty() || |
| 246 !FLAGS_omaha_url.empty()) { | 270 !FLAGS_omaha_url.empty()) { |
| 247 LOG_IF(WARNING, FLAGS_reboot) << "-reboot flag ignored."; | 271 LOG_IF(WARNING, FLAGS_reboot) << "-reboot flag ignored."; |
| 248 string app_version = FLAGS_app_version; | 272 string app_version = FLAGS_app_version; |
| 249 if (FLAGS_update && app_version.empty()) { | 273 if (FLAGS_update && app_version.empty()) { |
| 250 app_version = "ForcedUpdate"; | 274 app_version = "ForcedUpdate"; |
| 251 LOG(INFO) << "Forcing an update by setting app_version to ForcedUpdate."; | 275 LOG(INFO) << "Forcing an update by setting app_version to ForcedUpdate."; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 273 | 297 |
| 274 if (FLAGS_reboot) { | 298 if (FLAGS_reboot) { |
| 275 LOG(INFO) << "Requesting a reboot..."; | 299 LOG(INFO) << "Requesting a reboot..."; |
| 276 CHECK(RebootIfNeeded()); | 300 CHECK(RebootIfNeeded()); |
| 277 return 0; | 301 return 0; |
| 278 } | 302 } |
| 279 | 303 |
| 280 LOG(INFO) << "Done."; | 304 LOG(INFO) << "Done."; |
| 281 return 0; | 305 return 0; |
| 282 } | 306 } |
| OLD | NEW |