Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(169)

Side by Side Diff: update_engine_client.cc

Issue 4094001: AU: Provide a D-Bus API for changing the update track. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/update_engine.git
Patch Set: review comments Created 10 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « update_engine.xml ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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(status, false, "Print the status to stdout."); 29 DEFINE_bool(status, false, "Print the status to stdout.");
30 DEFINE_string(track, "", "Permanently change the update track.");
30 DEFINE_bool(update, false, "Forces an update and waits for its completion. " 31 DEFINE_bool(update, false, "Forces an update and waits for its completion. "
31 "Exit status is 0 if the update succeeded, and 1 otherwise."); 32 "Exit status is 0 if the update succeeded, and 1 otherwise.");
32 DEFINE_bool(watch_for_updates, false, 33 DEFINE_bool(watch_for_updates, false,
33 "Listen for status updates and print them to the screen."); 34 "Listen for status updates and print them to the screen.");
34 35
35 namespace { 36 namespace {
36 37
37 bool GetProxy(DBusGProxy** out_proxy) { 38 bool GetProxy(DBusGProxy** out_proxy) {
38 DBusGConnection* bus; 39 DBusGConnection* bus;
39 DBusGProxy* proxy; 40 DBusGProxy* proxy;
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
169 170
170 gboolean rc = 171 gboolean rc =
171 org_chromium_UpdateEngineInterface_reboot_if_needed(proxy, &error); 172 org_chromium_UpdateEngineInterface_reboot_if_needed(proxy, &error);
172 // Reboot error code doesn't necessarily mean that a reboot 173 // Reboot error code doesn't necessarily mean that a reboot
173 // failed. For example, D-Bus may be shutdown before we receive the 174 // failed. For example, D-Bus may be shutdown before we receive the
174 // result. 175 // result.
175 LOG_IF(INFO, !rc) << "Reboot error message: " << GetGErrorMessage(error); 176 LOG_IF(INFO, !rc) << "Reboot error message: " << GetGErrorMessage(error);
176 return true; 177 return true;
177 } 178 }
178 179
180 void SetTrack(const string& track) {
181 DBusGProxy* proxy;
182 GError* error = NULL;
183
184 CHECK(GetProxy(&proxy));
185
186 gboolean rc =
187 org_chromium_UpdateEngineInterface_set_track(proxy,
188 track.c_str(),
189 &error);
190 CHECK_EQ(rc, true) << "Error setting the track: "
191 << GetGErrorMessage(error);
192 LOG(INFO) << "TODO: Track permanently set to: " << track;
193 }
194
179 static gboolean CompleteUpdateSource(gpointer data) { 195 static gboolean CompleteUpdateSource(gpointer data) {
180 string current_op; 196 string current_op;
181 if (!GetStatus(&current_op) || current_op == "UPDATE_STATUS_IDLE") { 197 if (!GetStatus(&current_op) || current_op == "UPDATE_STATUS_IDLE") {
182 LOG(ERROR) << "Update failed."; 198 LOG(ERROR) << "Update failed.";
183 exit(1); 199 exit(1);
184 } 200 }
185 if (current_op == "UPDATE_STATUS_UPDATED_NEED_REBOOT") { 201 if (current_op == "UPDATE_STATUS_UPDATED_NEED_REBOOT") {
186 LOG(INFO) << "Update succeeded -- reboot needed."; 202 LOG(INFO) << "Update succeeded -- reboot needed.";
187 exit(0); 203 exit(0);
188 } 204 }
(...skipping 22 matching lines...) Expand all
211 227
212 if (FLAGS_status) { 228 if (FLAGS_status) {
213 LOG(INFO) << "Querying Update Engine status..."; 229 LOG(INFO) << "Querying Update Engine status...";
214 if (!GetStatus(NULL)) { 230 if (!GetStatus(NULL)) {
215 LOG(FATAL) << "GetStatus failed."; 231 LOG(FATAL) << "GetStatus failed.";
216 return 1; 232 return 1;
217 } 233 }
218 return 0; 234 return 0;
219 } 235 }
220 236
237 // First, update the track if requested.
238 if (!FLAGS_track.empty()) {
239 SetTrack(FLAGS_track);
240 }
241
221 // Initiate an update check, if necessary. 242 // Initiate an update check, if necessary.
222 if (FLAGS_check_for_update || 243 if (FLAGS_check_for_update ||
223 FLAGS_update || 244 FLAGS_update ||
224 !FLAGS_app_version.empty() || 245 !FLAGS_app_version.empty() ||
225 !FLAGS_omaha_url.empty()) { 246 !FLAGS_omaha_url.empty()) {
226 LOG_IF(WARNING, FLAGS_reboot) << "-reboot flag ignored."; 247 LOG_IF(WARNING, FLAGS_reboot) << "-reboot flag ignored.";
227 string app_version = FLAGS_app_version; 248 string app_version = FLAGS_app_version;
228 if (FLAGS_update && app_version.empty()) { 249 if (FLAGS_update && app_version.empty()) {
229 app_version = "ForcedUpdate"; 250 app_version = "ForcedUpdate";
230 LOG(INFO) << "Forcing an update by setting app_version to ForcedUpdate."; 251 LOG(INFO) << "Forcing an update by setting app_version to ForcedUpdate.";
(...skipping 18 matching lines...) Expand all
249 WatchForUpdates(); // Should never return. 270 WatchForUpdates(); // Should never return.
250 return 1; 271 return 1;
251 } 272 }
252 273
253 if (FLAGS_reboot) { 274 if (FLAGS_reboot) {
254 LOG(INFO) << "Requesting a reboot..."; 275 LOG(INFO) << "Requesting a reboot...";
255 CHECK(RebootIfNeeded()); 276 CHECK(RebootIfNeeded());
256 return 0; 277 return 0;
257 } 278 }
258 279
259 LOG(INFO) << "No flags specified. Exiting."; 280 LOG(INFO) << "Done.";
260 return 0; 281 return 0;
261 } 282 }
OLDNEW
« no previous file with comments | « update_engine.xml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698