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 <gflags/gflags.h> | 9 #include <gflags/gflags.h> |
10 #include <glib.h> | 10 #include <glib.h> |
11 | 11 |
| 12 #include "base/at_exit.h" |
12 #include "base/command_line.h" | 13 #include "base/command_line.h" |
13 #include "base/logging.h" | 14 #include "base/logging.h" |
14 #include "base/string_util.h" | 15 #include "base/string_util.h" |
15 #include "metrics/metrics_library.h" | 16 #include "metrics/metrics_library.h" |
16 #include "update_engine/dbus_constants.h" | 17 #include "update_engine/dbus_constants.h" |
17 #include "update_engine/dbus_service.h" | 18 #include "update_engine/dbus_service.h" |
18 #include "update_engine/prefs.h" | 19 #include "update_engine/prefs.h" |
19 #include "update_engine/subprocess.h" | 20 #include "update_engine/subprocess.h" |
20 #include "update_engine/update_attempter.h" | 21 #include "update_engine/update_attempter.h" |
21 #include "update_engine/utils.h" | 22 #include "update_engine/utils.h" |
(...skipping 16 matching lines...) Expand all Loading... |
38 gboolean UpdateBootFlags(void* arg) { | 39 gboolean UpdateBootFlags(void* arg) { |
39 // This purely best effort. Failures should be logged by Subprocess. | 40 // This purely best effort. Failures should be logged by Subprocess. |
40 int unused = 0; | 41 int unused = 0; |
41 vector<string> cmd(1, "/usr/sbin/chromeos-setgoodkernel"); | 42 vector<string> cmd(1, "/usr/sbin/chromeos-setgoodkernel"); |
42 Subprocess::SynchronousExec(cmd, &unused); | 43 Subprocess::SynchronousExec(cmd, &unused); |
43 return FALSE; // Don't call this callback again | 44 return FALSE; // Don't call this callback again |
44 } | 45 } |
45 | 46 |
46 namespace { | 47 namespace { |
47 | 48 |
| 49 const int kTimeoutOnce = 7 * 60; // at 7 minutes |
| 50 const int kTimeoutPeriodic = 45 * 60; // every 45 minutes |
| 51 const int kTimeoutFuzz = 10 * 60; // +/- 5 minutes |
| 52 |
| 53 // Schedules an update check |seconds| from now, while adding some fuzz. |
| 54 void ScheduleUpdateCheck(int seconds, |
| 55 GSourceFunc update_function, |
| 56 UpdateAttempter* update_attempter) { |
| 57 seconds = utils::FuzzInt(seconds, kTimeoutFuzz); |
| 58 g_timeout_add_seconds(seconds, update_function, update_attempter); |
| 59 } |
| 60 |
48 gboolean UpdateOnce(void* arg) { | 61 gboolean UpdateOnce(void* arg) { |
49 UpdateAttempter* update_attempter = reinterpret_cast<UpdateAttempter*>(arg); | 62 UpdateAttempter* update_attempter = reinterpret_cast<UpdateAttempter*>(arg); |
50 update_attempter->Update("", ""); | 63 update_attempter->Update("", ""); |
51 return FALSE; | 64 return FALSE; // Don't run again. |
52 } | 65 } |
53 | 66 |
54 gboolean UpdatePeriodically(void* arg) { | 67 gboolean UpdatePeriodically(void* arg) { |
55 UpdateAttempter* update_attempter = reinterpret_cast<UpdateAttempter*>(arg); | 68 UpdateAttempter* update_attempter = reinterpret_cast<UpdateAttempter*>(arg); |
56 update_attempter->Update("", ""); | 69 update_attempter->Update("", ""); |
57 return TRUE; | 70 ScheduleUpdateCheck(kTimeoutPeriodic, &UpdatePeriodically, update_attempter); |
| 71 return FALSE; // Don't run again. |
58 } | 72 } |
59 | 73 |
60 void SchedulePeriodicUpdateChecks(UpdateAttempter* update_attempter) { | 74 void SchedulePeriodicUpdateChecks(UpdateAttempter* update_attempter) { |
61 if (!utils::IsOfficialBuild()) { | 75 if (!utils::IsOfficialBuild()) { |
62 LOG(WARNING) << "Non-official build: periodic update checks disabled."; | 76 LOG(WARNING) << "Non-official build: periodic update checks disabled."; |
63 return; | 77 return; |
64 } | 78 } |
65 | |
66 if (utils::IsRemovableDevice(utils::RootDevice(utils::BootDevice()))) { | 79 if (utils::IsRemovableDevice(utils::RootDevice(utils::BootDevice()))) { |
67 LOG(WARNING) << "Removable device boot: periodic update checks disabled."; | 80 LOG(WARNING) << "Removable device boot: periodic update checks disabled."; |
68 return; | 81 return; |
69 } | 82 } |
70 | 83 // Kick off periodic updating. |
71 // Kick off periodic updating. First, update after 2 minutes. Also, update | 84 ScheduleUpdateCheck(kTimeoutOnce, &UpdateOnce, update_attempter); |
72 // every 30 minutes. | 85 ScheduleUpdateCheck(kTimeoutPeriodic, &UpdatePeriodically, update_attempter); |
73 g_timeout_add_seconds(2 * 60, &UpdateOnce, update_attempter); | |
74 g_timeout_add_seconds(30 * 60, &UpdatePeriodically, update_attempter); | |
75 } | 86 } |
76 | 87 |
77 void SetupDbusService(UpdateEngineService* service) { | 88 void SetupDbusService(UpdateEngineService* service) { |
78 DBusGConnection *bus; | 89 DBusGConnection *bus; |
79 DBusGProxy *proxy; | 90 DBusGProxy *proxy; |
80 GError *error = NULL; | 91 GError *error = NULL; |
81 | 92 |
82 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); | 93 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); |
83 if (!bus) { | 94 if (!bus) { |
84 LOG(FATAL) << "Failed to get bus"; | 95 LOG(FATAL) << "Failed to get bus"; |
(...skipping 26 matching lines...) Expand all Loading... |
111 } // namespace {} | 122 } // namespace {} |
112 | 123 |
113 } // namespace chromeos_update_engine | 124 } // namespace chromeos_update_engine |
114 | 125 |
115 #include "update_engine/subprocess.h" | 126 #include "update_engine/subprocess.h" |
116 | 127 |
117 int main(int argc, char** argv) { | 128 int main(int argc, char** argv) { |
118 ::g_type_init(); | 129 ::g_type_init(); |
119 g_thread_init(NULL); | 130 g_thread_init(NULL); |
120 dbus_g_thread_init(); | 131 dbus_g_thread_init(); |
| 132 base::AtExitManager exit_manager; // Required for base/rand_util.h. |
121 chromeos_update_engine::Subprocess::Init(); | 133 chromeos_update_engine::Subprocess::Init(); |
122 google::ParseCommandLineFlags(&argc, &argv, true); | 134 google::ParseCommandLineFlags(&argc, &argv, true); |
123 CommandLine::Init(argc, argv); | 135 CommandLine::Init(argc, argv); |
124 logging::InitLogging("/var/log/update_engine.log", | 136 logging::InitLogging("/var/log/update_engine.log", |
125 (FLAGS_logtostderr ? | 137 (FLAGS_logtostderr ? |
126 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG : | 138 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG : |
127 logging::LOG_ONLY_TO_FILE), | 139 logging::LOG_ONLY_TO_FILE), |
128 logging::DONT_LOCK_LOG_FILE, | 140 logging::DONT_LOCK_LOG_FILE, |
129 logging::APPEND_TO_OLD_LOG_FILE); | 141 logging::APPEND_TO_OLD_LOG_FILE); |
130 if (!FLAGS_foreground) | 142 if (!FLAGS_foreground) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 g_main_loop_run(loop); | 176 g_main_loop_run(loop); |
165 | 177 |
166 // Cleanup: | 178 // Cleanup: |
167 g_main_loop_unref(loop); | 179 g_main_loop_unref(loop); |
168 update_attempter.set_dbus_service(NULL); | 180 update_attempter.set_dbus_service(NULL); |
169 g_object_unref(G_OBJECT(service)); | 181 g_object_unref(G_OBJECT(service)); |
170 | 182 |
171 LOG(INFO) << "Chrome OS Update Engine terminating"; | 183 LOG(INFO) << "Chrome OS Update Engine terminating"; |
172 return 0; | 184 return 0; |
173 } | 185 } |
OLD | NEW |