| 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, "", | 25 DEFINE_string(app_version, "", "Force the current app version."); |
| 26 "Force the current app version."); | 26 DEFINE_bool(check_for_update, false, "Initiate check for updates."); |
| 27 DEFINE_bool(check_for_update, false, | |
| 28 "Initiate check for updates."); | |
| 29 DEFINE_bool(force_update, false, | 27 DEFINE_bool(force_update, false, |
| 30 "Force an update, even over an expensive network."); | 28 "Force an update, even over an expensive network."); |
| 31 DEFINE_string(omaha_url, "", | 29 DEFINE_string(omaha_url, "", "The URL of the Omaha update server."); |
| 32 "The URL of the Omaha update server."); | 30 DEFINE_bool(reboot, false, "Initiate a reboot if needed."); |
| 33 DEFINE_bool(status, false, "Print the status to stdout."); | 31 DEFINE_bool(status, false, "Print the status to stdout."); |
| 34 DEFINE_bool(watch_for_updates, false, | 32 DEFINE_bool(watch_for_updates, false, |
| 35 "Listen for status updates and print them to the screen."); | 33 "Listen for status updates and print them to the screen."); |
| 36 | 34 |
| 37 namespace { | 35 namespace { |
| 38 | 36 |
| 39 bool GetProxy(DBusGProxy** out_proxy) { | 37 bool GetProxy(DBusGProxy** out_proxy) { |
| 40 DBusGConnection* bus; | 38 DBusGConnection* bus; |
| 41 DBusGProxy* proxy; | 39 DBusGProxy* proxy; |
| 42 GError* error = NULL; | 40 GError* error = NULL; |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 gboolean rc = | 149 gboolean rc = |
| 152 org_chromium_UpdateEngineInterface_attempt_update(proxy, | 150 org_chromium_UpdateEngineInterface_attempt_update(proxy, |
| 153 app_version.c_str(), | 151 app_version.c_str(), |
| 154 omaha_url.c_str(), | 152 omaha_url.c_str(), |
| 155 &error); | 153 &error); |
| 156 CHECK_EQ(rc, TRUE) << "Error checking for update: " | 154 CHECK_EQ(rc, TRUE) << "Error checking for update: " |
| 157 << GetGErrorMessage(error); | 155 << GetGErrorMessage(error); |
| 158 return true; | 156 return true; |
| 159 } | 157 } |
| 160 | 158 |
| 159 bool RebootIfNeeded() { |
| 160 DBusGProxy* proxy; |
| 161 GError* error = NULL; |
| 162 |
| 163 CHECK(GetProxy(&proxy)); |
| 164 |
| 165 gboolean rc = |
| 166 org_chromium_UpdateEngineInterface_reboot_if_needed(proxy, &error); |
| 167 // Reboot error code doesn't necessarily mean that a reboot |
| 168 // failed. For example, D-Bus may be shutdown before we receive the |
| 169 // result. |
| 170 LOG_IF(INFO, !rc) << "Reboot error message: " << GetGErrorMessage(error); |
| 171 return true; |
| 172 } |
| 173 |
| 161 } // namespace {} | 174 } // namespace {} |
| 162 | 175 |
| 163 int main(int argc, char** argv) { | 176 int main(int argc, char** argv) { |
| 164 // Boilerplate init commands. | 177 // Boilerplate init commands. |
| 165 g_type_init(); | 178 g_type_init(); |
| 166 g_thread_init(NULL); | 179 g_thread_init(NULL); |
| 167 dbus_g_thread_init(); | 180 dbus_g_thread_init(); |
| 168 chromeos_update_engine::Subprocess::Init(); | 181 chromeos_update_engine::Subprocess::Init(); |
| 169 google::ParseCommandLineFlags(&argc, &argv, true); | 182 google::ParseCommandLineFlags(&argc, &argv, true); |
| 170 | 183 |
| 171 if (FLAGS_status) { | 184 if (FLAGS_status) { |
| 172 LOG(INFO) << "Querying Update Engine status..."; | 185 LOG(INFO) << "Querying Update Engine status..."; |
| 173 if (!GetStatus()) { | 186 if (!GetStatus()) { |
| 174 LOG(FATAL) << "GetStatus() failed."; | 187 LOG(FATAL) << "GetStatus() failed."; |
| 175 } | 188 } |
| 176 return 0; | 189 return 0; |
| 177 } | 190 } |
| 178 if (FLAGS_force_update || FLAGS_check_for_update || | 191 if (FLAGS_force_update || FLAGS_check_for_update || |
| 179 !FLAGS_app_version.empty() || !FLAGS_omaha_url.empty()) { | 192 !FLAGS_app_version.empty() || !FLAGS_omaha_url.empty()) { |
| 193 LOG_IF(WARNING, FLAGS_reboot) << "-reboot flag ignored."; |
| 180 LOG(INFO) << "Initiating update check and install."; | 194 LOG(INFO) << "Initiating update check and install."; |
| 181 if (FLAGS_force_update) { | 195 if (FLAGS_force_update) { |
| 182 LOG(INFO) << "Will not abort due to being on expensive network."; | 196 LOG(INFO) << "Will not abort due to being on expensive network."; |
| 183 } | 197 } |
| 184 CHECK(CheckForUpdates(FLAGS_force_update, FLAGS_app_version, | 198 CHECK(CheckForUpdates(FLAGS_force_update, FLAGS_app_version, |
| 185 FLAGS_omaha_url)) | 199 FLAGS_omaha_url)) |
| 186 << "Update check/initiate update failed."; | 200 << "Update check/initiate update failed."; |
| 187 return 0; | 201 return 0; |
| 188 } | 202 } |
| 189 if (FLAGS_watch_for_updates) { | 203 if (FLAGS_watch_for_updates) { |
| 204 LOG_IF(WARNING, FLAGS_reboot) << "-reboot flag ignored."; |
| 190 LOG(INFO) << "Watching for status updates."; | 205 LOG(INFO) << "Watching for status updates."; |
| 191 WatchForUpdates(); // Should never return. | 206 WatchForUpdates(); // Should never return. |
| 192 return 1; | 207 return 1; |
| 193 } | 208 } |
| 209 if (FLAGS_reboot) { |
| 210 LOG(INFO) << "Requesting a reboot..."; |
| 211 CHECK(RebootIfNeeded()); |
| 212 return 0; |
| 213 } |
| 194 | 214 |
| 195 LOG(INFO) << "No flags specified. Exiting."; | 215 LOG(INFO) << "No flags specified. Exiting."; |
| 196 return 0; | 216 return 0; |
| 197 } | 217 } |
| OLD | NEW |