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 #include <gflags/gflags.h> | 8 #include <gflags/gflags.h> |
9 #include <glib.h> | 9 #include <glib.h> |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "chromeos/obsolete_logging.h" | 11 #include "chromeos/obsolete_logging.h" |
12 #include "update_engine/dbus_constants.h" | 12 #include "update_engine/dbus_constants.h" |
13 #include "update_engine/dbus_service.h" | 13 #include "update_engine/dbus_service.h" |
14 #include "update_engine/update_attempter.h" | 14 #include "update_engine/update_attempter.h" |
15 | 15 |
16 extern "C" { | 16 extern "C" { |
17 #include "update_engine/update_engine.dbusserver.h" | 17 #include "update_engine/update_engine.dbusserver.h" |
18 } | 18 } |
19 | 19 |
20 DEFINE_bool(logtostderr, false, | 20 DEFINE_bool(logtostderr, false, |
21 "Write logs to stderr instead of to a file in log_dir."); | 21 "Write logs to stderr instead of to a file in log_dir."); |
22 | 22 |
23 using std::string; | 23 using std::string; |
24 using std::tr1::shared_ptr; | 24 using std::tr1::shared_ptr; |
25 using std::vector; | 25 using std::vector; |
26 | 26 |
27 namespace chromeos_update_engine { | 27 namespace chromeos_update_engine { |
28 | 28 |
| 29 namespace { |
| 30 |
| 31 struct PeriodicallyUpdateArgs { |
| 32 UpdateAttempter* update_attempter; |
| 33 gboolean should_repeat; |
| 34 }; |
| 35 |
| 36 gboolean PeriodicallyUpdate(void* arg) { |
| 37 PeriodicallyUpdateArgs* args = reinterpret_cast<PeriodicallyUpdateArgs*>(arg); |
| 38 args->update_attempter->Update(false); |
| 39 return args->should_repeat; |
| 40 } |
| 41 |
29 void SetupDbusService(UpdateEngineService* service) { | 42 void SetupDbusService(UpdateEngineService* service) { |
30 DBusGConnection *bus; | 43 DBusGConnection *bus; |
31 DBusGProxy *proxy; | 44 DBusGProxy *proxy; |
32 GError *error = NULL; | 45 GError *error = NULL; |
33 | 46 |
34 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); | 47 bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); |
35 if (!bus) { | 48 if (!bus) { |
36 LOG(FATAL) << "Failed to get bus"; | 49 LOG(FATAL) << "Failed to get bus"; |
37 } | 50 } |
38 proxy = dbus_g_proxy_new_for_name(bus, | 51 proxy = dbus_g_proxy_new_for_name(bus, |
(...skipping 14 matching lines...) Expand all Loading... |
53 g_error_free(error); | 66 g_error_free(error); |
54 LOG(FATAL) << "Got result code " << request_name_ret | 67 LOG(FATAL) << "Got result code " << request_name_ret |
55 << " from requesting name, but expected " | 68 << " from requesting name, but expected " |
56 << DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER; | 69 << DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER; |
57 } | 70 } |
58 dbus_g_connection_register_g_object(bus, | 71 dbus_g_connection_register_g_object(bus, |
59 "/org/chromium/UpdateEngine", | 72 "/org/chromium/UpdateEngine", |
60 G_OBJECT(service)); | 73 G_OBJECT(service)); |
61 } | 74 } |
62 | 75 |
| 76 } // namespace {} |
| 77 |
63 } // namespace chromeos_update_engine | 78 } // namespace chromeos_update_engine |
64 | 79 |
65 #include "update_engine/subprocess.h" | 80 #include "update_engine/subprocess.h" |
66 | 81 |
67 int main(int argc, char** argv) { | 82 int main(int argc, char** argv) { |
68 ::g_type_init(); | 83 ::g_type_init(); |
69 g_thread_init(NULL); | 84 g_thread_init(NULL); |
70 dbus_g_thread_init(); | 85 dbus_g_thread_init(); |
71 chromeos_update_engine::Subprocess::Init(); | 86 chromeos_update_engine::Subprocess::Init(); |
72 google::ParseCommandLineFlags(&argc, &argv, true); | 87 google::ParseCommandLineFlags(&argc, &argv, true); |
73 CommandLine::Init(argc, argv); | 88 CommandLine::Init(argc, argv); |
74 logging::InitLogging("logfile.txt", | 89 logging::InitLogging("/var/log/update_engine.log", |
75 (FLAGS_logtostderr ? | 90 (FLAGS_logtostderr ? |
76 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG : | 91 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG : |
77 logging::LOG_ONLY_TO_FILE), | 92 logging::LOG_ONLY_TO_FILE), |
78 logging::DONT_LOCK_LOG_FILE, | 93 logging::DONT_LOCK_LOG_FILE, |
79 logging::APPEND_TO_OLD_LOG_FILE); | 94 logging::APPEND_TO_OLD_LOG_FILE); |
80 LOG(INFO) << "Chrome OS Update Engine starting"; | 95 LOG(INFO) << "Chrome OS Update Engine starting"; |
81 | 96 |
82 // Create the single GMainLoop | 97 // Create the single GMainLoop |
83 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); | 98 GMainLoop* loop = g_main_loop_new(g_main_context_default(), FALSE); |
84 | 99 |
85 // Create the update attempter: | 100 // Create the update attempter: |
86 chromeos_update_engine::UpdateAttempter update_attempter; | 101 chromeos_update_engine::UpdateAttempter update_attempter; |
87 | 102 |
88 // Create the dbus service object: | 103 // Create the dbus service object: |
89 dbus_g_object_type_install_info(UPDATE_ENGINE_TYPE_SERVICE, | 104 dbus_g_object_type_install_info(UPDATE_ENGINE_TYPE_SERVICE, |
90 &dbus_glib_update_engine_service_object_info); | 105 &dbus_glib_update_engine_service_object_info); |
91 UpdateEngineService* service = | 106 UpdateEngineService* service = |
92 UPDATE_ENGINE_SERVICE(g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL)); | 107 UPDATE_ENGINE_SERVICE(g_object_new(UPDATE_ENGINE_TYPE_SERVICE, NULL)); |
93 service->update_attempter_ = &update_attempter; | 108 service->update_attempter_ = &update_attempter; |
94 update_attempter.set_dbus_service(service); | 109 update_attempter.set_dbus_service(service); |
95 chromeos_update_engine::SetupDbusService(service); | 110 chromeos_update_engine::SetupDbusService(service); |
96 | 111 |
| 112 // Kick off periodic updating. First, update after 2 minutes. Also, update |
| 113 // every 30 minutes. |
| 114 chromeos_update_engine::PeriodicallyUpdateArgs two_min_args = |
| 115 {&update_attempter, FALSE}; |
| 116 g_timeout_add(2 * 60 * 1000, |
| 117 &chromeos_update_engine::PeriodicallyUpdate, |
| 118 &two_min_args); |
| 119 |
| 120 chromeos_update_engine::PeriodicallyUpdateArgs thirty_min_args = |
| 121 {&update_attempter, TRUE}; |
| 122 g_timeout_add(30 * 60 * 1000, |
| 123 &chromeos_update_engine::PeriodicallyUpdate, |
| 124 &thirty_min_args); |
| 125 |
97 // Run the main loop until exit time: | 126 // Run the main loop until exit time: |
98 g_main_loop_run(loop); | 127 g_main_loop_run(loop); |
99 | 128 |
100 // Cleanup: | 129 // Cleanup: |
101 g_main_loop_unref(loop); | 130 g_main_loop_unref(loop); |
102 update_attempter.set_dbus_service(NULL); | 131 update_attempter.set_dbus_service(NULL); |
103 g_object_unref(G_OBJECT(service)); | 132 g_object_unref(G_OBJECT(service)); |
104 | 133 |
105 LOG(INFO) << "Chrome OS Update Engine terminating"; | 134 LOG(INFO) << "Chrome OS Update Engine terminating"; |
106 return 0; | 135 return 0; |
107 } | 136 } |
OLD | NEW |