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 #include <tr1/memory> | 6 #include <tr1/memory> |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include <base/at_exit.h> | 9 #include <base/at_exit.h> |
10 #include <base/command_line.h> | 10 #include <base/command_line.h> |
(...skipping 22 matching lines...) Expand all Loading... | |
33 DEFINE_bool(foreground, false, | 33 DEFINE_bool(foreground, false, |
34 "Don't daemon()ize; run in foreground."); | 34 "Don't daemon()ize; run in foreground."); |
35 | 35 |
36 using std::string; | 36 using std::string; |
37 using std::tr1::shared_ptr; | 37 using std::tr1::shared_ptr; |
38 using std::vector; | 38 using std::vector; |
39 | 39 |
40 namespace chromeos_update_engine { | 40 namespace chromeos_update_engine { |
41 | 41 |
42 gboolean UpdateBootFlags(void* arg) { | 42 gboolean UpdateBootFlags(void* arg) { |
43 // This purely best effort. Failures should be logged by Subprocess. | 43 UpdateAttempter* attempter = reinterpret_cast<UpdateAttempter*>(arg); |
44 if (attempter->status() == UPDATE_STATUS_UPDATED_NEED_REBOOT) { | |
45 // Don't update the flags if there's an update that's just been applied and | |
46 // we're waiting for reboot because we may end up reverting the update. | |
47 return FALSE; // Don't call this callback again. | |
48 } | |
49 if (attempter->status() != UPDATE_STATUS_IDLE) { | |
adlr
2010/10/22 00:45:28
since it's single threaded, and this and postinst
| |
50 // To avoid races (e.g., setting a good kernel right after post-install but | |
51 // before the status changes), update the boot flag only if the attempter is | |
52 // idle. | |
53 return TRUE; // Call this callback again. | |
54 } | |
55 // This is purely best effort. Failures should be logged by Subprocess. | |
44 int unused = 0; | 56 int unused = 0; |
45 vector<string> cmd(1, "/usr/sbin/chromeos-setgoodkernel"); | 57 vector<string> cmd(1, "/usr/sbin/chromeos-setgoodkernel"); |
46 Subprocess::SynchronousExec(cmd, &unused); | 58 Subprocess::SynchronousExec(cmd, &unused); |
47 return FALSE; // Don't call this callback again | 59 return FALSE; // Don't call this callback again |
48 } | 60 } |
49 | 61 |
50 namespace { | 62 namespace { |
51 | 63 |
52 void SetupDbusService(UpdateEngineService* service) { | 64 void SetupDbusService(UpdateEngineService* service) { |
53 DBusGConnection *bus; | 65 DBusGConnection *bus; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
135 UpdateEngineService* service = | 147 UpdateEngineService* service = |
136 UPDATE_ENGINE_SERVICE(g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL)); | 148 UPDATE_ENGINE_SERVICE(g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL)); |
137 service->update_attempter_ = &update_attempter; | 149 service->update_attempter_ = &update_attempter; |
138 update_attempter.set_dbus_service(service); | 150 update_attempter.set_dbus_service(service); |
139 chromeos_update_engine::SetupDbusService(service); | 151 chromeos_update_engine::SetupDbusService(service); |
140 | 152 |
141 // Schedule periodic update checks. | 153 // Schedule periodic update checks. |
142 chromeos_update_engine::UpdateCheckScheduler scheduler(&update_attempter); | 154 chromeos_update_engine::UpdateCheckScheduler scheduler(&update_attempter); |
143 scheduler.Run(); | 155 scheduler.Run(); |
144 | 156 |
145 // Update boot flags after 45 seconds | 157 // Update boot flags after 45 seconds. |
146 g_timeout_add_seconds(45, &chromeos_update_engine::UpdateBootFlags, NULL); | 158 g_timeout_add_seconds(45, |
159 &chromeos_update_engine::UpdateBootFlags, | |
160 &update_attempter); | |
147 | 161 |
148 // Run the main loop until exit time: | 162 // Run the main loop until exit time: |
149 g_main_loop_run(loop); | 163 g_main_loop_run(loop); |
150 | 164 |
151 // Cleanup: | 165 // Cleanup: |
152 g_main_loop_unref(loop); | 166 g_main_loop_unref(loop); |
153 update_attempter.set_dbus_service(NULL); | 167 update_attempter.set_dbus_service(NULL); |
154 g_object_unref(G_OBJECT(service)); | 168 g_object_unref(G_OBJECT(service)); |
155 | 169 |
156 LOG(INFO) << "Chrome OS Update Engine terminating"; | 170 LOG(INFO) << "Chrome OS Update Engine terminating"; |
157 return 0; | 171 return 0; |
158 } | 172 } |
OLD | NEW |