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 "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "chromeos/syslog_logging.h" |
11 #include "crash-reporter/kernel_collector.h" | 12 #include "crash-reporter/kernel_collector.h" |
12 #include "crash-reporter/system_logging.h" | |
13 #include "crash-reporter/unclean_shutdown_collector.h" | 13 #include "crash-reporter/unclean_shutdown_collector.h" |
14 #include "crash-reporter/user_collector.h" | 14 #include "crash-reporter/user_collector.h" |
15 #include "gflags/gflags.h" | 15 #include "gflags/gflags.h" |
16 #include "metrics/metrics_library.h" | 16 #include "metrics/metrics_library.h" |
17 | 17 |
18 #pragma GCC diagnostic ignored "-Wstrict-aliasing" | 18 #pragma GCC diagnostic ignored "-Wstrict-aliasing" |
19 DEFINE_bool(init, false, "Initialize crash logging"); | 19 DEFINE_bool(init, false, "Initialize crash logging"); |
20 DEFINE_bool(clean_shutdown, false, "Signal clean shutdown"); | 20 DEFINE_bool(clean_shutdown, false, "Signal clean shutdown"); |
21 DEFINE_string(generate_kernel_signature, "", | 21 DEFINE_string(generate_kernel_signature, "", |
22 "Generate signature from given kcrash file"); | 22 "Generate signature from given kcrash file"); |
(...skipping 11 matching lines...) Expand all Loading... |
34 | 34 |
35 // Enumeration of kinds of crashes to be used in the CrashCounter histogram. | 35 // Enumeration of kinds of crashes to be used in the CrashCounter histogram. |
36 enum CrashKinds { | 36 enum CrashKinds { |
37 kCrashKindUncleanShutdown = 1, | 37 kCrashKindUncleanShutdown = 1, |
38 kCrashKindUser = 2, | 38 kCrashKindUser = 2, |
39 kCrashKindKernel = 3, | 39 kCrashKindKernel = 3, |
40 kCrashKindMax | 40 kCrashKindMax |
41 }; | 41 }; |
42 | 42 |
43 static MetricsLibrary s_metrics_lib; | 43 static MetricsLibrary s_metrics_lib; |
44 static SystemLoggingImpl s_system_log; | |
45 | 44 |
46 static bool IsFeedbackAllowed() { | 45 static bool IsFeedbackAllowed() { |
47 return s_metrics_lib.AreMetricsEnabled(); | 46 return s_metrics_lib.AreMetricsEnabled(); |
48 } | 47 } |
49 | 48 |
50 static bool TouchFile(const FilePath &file_path) { | 49 static bool TouchFile(const FilePath &file_path) { |
51 return file_util::WriteFile(file_path, "", 0) == 0; | 50 return file_util::WriteFile(file_path, "", 0) == 0; |
52 } | 51 } |
53 | 52 |
54 static void CountKernelCrash() { | 53 static void CountKernelCrash() { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
89 // better way to do this that doesn't rely on D-Bus. | 88 // better way to do this that doesn't rely on D-Bus. |
90 // | 89 // |
91 // We run in the background in case dbus daemon itself is crashed | 90 // We run in the background in case dbus daemon itself is crashed |
92 // and not responding. This allows us to not block and potentially | 91 // and not responding. This allows us to not block and potentially |
93 // deadlock on a dbus-daemon crash. If dbus-daemon crashes without | 92 // deadlock on a dbus-daemon crash. If dbus-daemon crashes without |
94 // restarting, each crash will fork off a lot of dbus-send | 93 // restarting, each crash will fork off a lot of dbus-send |
95 // processes. Such a system is in a unusable state and will need | 94 // processes. Such a system is in a unusable state and will need |
96 // to be restarted anyway. | 95 // to be restarted anyway. |
97 | 96 |
98 int status = system(command.c_str()); | 97 int status = system(command.c_str()); |
99 if (status != 0) { | 98 LOG_IF(WARNING, status != 0) << "dbus-send running failed"; |
100 s_system_log.LogWarning("dbus-send running failed"); | |
101 } | |
102 } | 99 } |
103 | 100 |
104 static int Initialize(KernelCollector *kernel_collector, | 101 static int Initialize(KernelCollector *kernel_collector, |
105 UserCollector *user_collector, | 102 UserCollector *user_collector, |
106 UncleanShutdownCollector *unclean_shutdown_collector) { | 103 UncleanShutdownCollector *unclean_shutdown_collector) { |
107 CHECK(!FLAGS_clean_shutdown) << "Incompatible options"; | 104 CHECK(!FLAGS_clean_shutdown) << "Incompatible options"; |
108 | 105 |
109 bool was_kernel_crash = false; | 106 bool was_kernel_crash = false; |
110 bool was_unclean_shutdown = false; | 107 bool was_unclean_shutdown = false; |
111 kernel_collector->Enable(); | 108 kernel_collector->Enable(); |
(...skipping 30 matching lines...) Expand all Loading... |
142 CHECK(!FLAGS_user.empty()) << "--user= must be set"; | 139 CHECK(!FLAGS_user.empty()) << "--user= must be set"; |
143 | 140 |
144 // Make it possible to test what happens when we crash while | 141 // Make it possible to test what happens when we crash while |
145 // handling a crash. | 142 // handling a crash. |
146 if (FLAGS_crash_test) { | 143 if (FLAGS_crash_test) { |
147 *(char *)0 = 0; | 144 *(char *)0 = 0; |
148 return 0; | 145 return 0; |
149 } | 146 } |
150 | 147 |
151 // Accumulate logs to help in diagnosing failures during user collection. | 148 // Accumulate logs to help in diagnosing failures during user collection. |
152 s_system_log.set_accumulating(true); | 149 syslog_logging::AccumulateToString(true); |
153 // Handle the crash, get the name of the process from procfs. | 150 // Handle the crash, get the name of the process from procfs. |
154 bool handled = user_collector->HandleCrash(FLAGS_user, NULL); | 151 bool handled = user_collector->HandleCrash(FLAGS_user, NULL); |
155 s_system_log.set_accumulating(false); | 152 syslog_logging::AccumulateToString(false); |
156 if (!handled) | 153 if (!handled) |
157 return 1; | 154 return 1; |
158 return 0; | 155 return 0; |
159 } | 156 } |
160 | 157 |
161 // Interactive/diagnostics mode for generating kernel crash signatures. | 158 // Interactive/diagnostics mode for generating kernel crash signatures. |
162 static int GenerateKernelSignature(KernelCollector *kernel_collector) { | 159 static int GenerateKernelSignature(KernelCollector *kernel_collector) { |
163 std::string kcrash_contents; | 160 std::string kcrash_contents; |
164 std::string signature; | 161 std::string signature; |
165 if (!file_util::ReadFileToString(FilePath(FLAGS_generate_kernel_signature), | 162 if (!file_util::ReadFileToString(FilePath(FLAGS_generate_kernel_signature), |
(...skipping 11 matching lines...) Expand all Loading... |
177 printf("Kernel crash signature is \"%s\".\n", signature.c_str()); | 174 printf("Kernel crash signature is \"%s\".\n", signature.c_str()); |
178 return 0; | 175 return 0; |
179 } | 176 } |
180 | 177 |
181 int main(int argc, char *argv[]) { | 178 int main(int argc, char *argv[]) { |
182 google::ParseCommandLineFlags(&argc, &argv, true); | 179 google::ParseCommandLineFlags(&argc, &argv, true); |
183 FilePath my_path(argv[0]); | 180 FilePath my_path(argv[0]); |
184 file_util::AbsolutePath(&my_path); | 181 file_util::AbsolutePath(&my_path); |
185 s_metrics_lib.Init(); | 182 s_metrics_lib.Init(); |
186 CommandLine::Init(argc, argv); | 183 CommandLine::Init(argc, argv); |
187 logging::InitLogging(NULL, | 184 syslog_logging::OpenLog(my_path.BaseName().value().c_str(), true); |
188 logging::LOG_ONLY_TO_SYSTEM_DEBUG_LOG, | 185 syslog_logging::InitLogging(true, false); |
189 logging::DONT_LOCK_LOG_FILE, | |
190 logging::DELETE_OLD_LOG_FILE); | |
191 s_system_log.Initialize(my_path.BaseName().value().c_str()); | |
192 KernelCollector kernel_collector; | 186 KernelCollector kernel_collector; |
193 kernel_collector.Initialize(CountKernelCrash, | 187 kernel_collector.Initialize(CountKernelCrash, |
194 IsFeedbackAllowed, | 188 IsFeedbackAllowed); |
195 &s_system_log); | |
196 UserCollector user_collector; | 189 UserCollector user_collector; |
197 user_collector.Initialize(CountUserCrash, | 190 user_collector.Initialize(CountUserCrash, |
198 my_path.value(), | 191 my_path.value(), |
199 IsFeedbackAllowed, | 192 IsFeedbackAllowed, |
200 &s_system_log, | |
201 true); // generate_diagnostics | 193 true); // generate_diagnostics |
202 UncleanShutdownCollector unclean_shutdown_collector; | 194 UncleanShutdownCollector unclean_shutdown_collector; |
203 unclean_shutdown_collector.Initialize(CountUncleanShutdown, | 195 unclean_shutdown_collector.Initialize(CountUncleanShutdown, |
204 IsFeedbackAllowed, | 196 IsFeedbackAllowed); |
205 &s_system_log); | |
206 | 197 |
207 if (FLAGS_init) { | 198 if (FLAGS_init) { |
208 return Initialize(&kernel_collector, | 199 return Initialize(&kernel_collector, |
209 &user_collector, | 200 &user_collector, |
210 &unclean_shutdown_collector); | 201 &unclean_shutdown_collector); |
211 } | 202 } |
212 | 203 |
213 if (FLAGS_clean_shutdown) { | 204 if (FLAGS_clean_shutdown) { |
214 unclean_shutdown_collector.Disable(); | 205 unclean_shutdown_collector.Disable(); |
215 user_collector.Disable(); | 206 user_collector.Disable(); |
216 return 0; | 207 return 0; |
217 } | 208 } |
218 | 209 |
219 if (!FLAGS_generate_kernel_signature.empty()) { | 210 if (!FLAGS_generate_kernel_signature.empty()) { |
220 return GenerateKernelSignature(&kernel_collector); | 211 return GenerateKernelSignature(&kernel_collector); |
221 } | 212 } |
222 | 213 |
223 return HandleUserCrash(&user_collector); | 214 return HandleUserCrash(&user_collector); |
224 } | 215 } |
OLD | NEW |