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/logging.h" | 8 #include "base/logging.h" |
9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
10 #include "crash-reporter/system_logging.h" | 10 #include "crash-reporter/system_logging.h" |
11 #include "crash-reporter/user_collector.h" | 11 #include "crash-reporter/user_collector.h" |
12 #include "gflags/gflags.h" | 12 #include "gflags/gflags.h" |
13 #include "metrics/metrics_library.h" | 13 #include "metrics/metrics_library.h" |
14 | 14 |
15 #pragma GCC diagnostic ignored "-Wstrict-aliasing" | 15 #pragma GCC diagnostic ignored "-Wstrict-aliasing" |
16 DEFINE_bool(init, false, "Initialize crash logging"); | 16 DEFINE_bool(init, false, "Initialize crash logging"); |
17 DEFINE_bool(clean_shutdown, false, "Signal clean shutdown"); | 17 DEFINE_bool(clean_shutdown, false, "Signal clean shutdown"); |
18 DEFINE_bool(crash_test, false, "Crash test"); | 18 DEFINE_bool(crash_test, false, "Crash test"); |
19 DEFINE_string(exec, "", "Executable name crashed"); | 19 DEFINE_string(exec, "", "Executable name crashed"); |
20 DEFINE_int32(pid, -1, "Crashing PID"); | 20 DEFINE_int32(pid, -1, "Crashing PID"); |
21 DEFINE_int32(signal, -1, "Signal causing crash"); | 21 DEFINE_int32(signal, -1, "Signal causing crash"); |
22 DEFINE_bool(unclean_check, true, "Check for unclean shutdown"); | 22 DEFINE_bool(unclean_check, true, "Check for unclean shutdown"); |
23 #pragma GCC diagnostic error "-Wstrict-aliasing" | 23 #pragma GCC diagnostic error "-Wstrict-aliasing" |
24 | 24 |
25 static const char kCrashCounterHistogram[] = "Logging.CrashCounter"; | 25 static const char kCrashCounterHistogram[] = "Logging.CrashCounter"; |
26 static const char kUncleanShutdownFile[] = | 26 static const char kUncleanShutdownFile[] = |
27 "/var/lib/crash_reporter/pending_clean_shutdown"; | 27 "/var/lib/crash_reporter/pending_clean_shutdown"; |
| 28 static const char kEmpty[] = ""; |
28 | 29 |
29 // Enumeration of kinds of crashes to be used in the CrashCounter histogram. | 30 // Enumeration of kinds of crashes to be used in the CrashCounter histogram. |
30 enum CrashKinds { | 31 enum CrashKinds { |
31 CRASH_KIND_KERNEL = 1, | 32 CRASH_KIND_KERNEL = 1, |
32 CRASH_KIND_USER = 2, | 33 CRASH_KIND_USER = 2, |
33 CRASH_KIND_MAX | 34 CRASH_KIND_MAX |
34 }; | 35 }; |
35 | 36 |
36 static MetricsLibrary s_metrics_lib; | 37 static MetricsLibrary s_metrics_lib; |
37 static SystemLoggingImpl s_system_log; | 38 static SystemLoggingImpl s_system_log; |
(...skipping 13 matching lines...) Expand all Loading... |
51 s_system_log.LogWarning("Last shutdown was not clean"); | 52 s_system_log.LogWarning("Last shutdown was not clean"); |
52 if (IsMetricsCollectionAllowed()) { | 53 if (IsMetricsCollectionAllowed()) { |
53 s_metrics_lib.SendEnumToUMA(std::string(kCrashCounterHistogram), | 54 s_metrics_lib.SendEnumToUMA(std::string(kCrashCounterHistogram), |
54 CRASH_KIND_KERNEL, | 55 CRASH_KIND_KERNEL, |
55 CRASH_KIND_MAX); | 56 CRASH_KIND_MAX); |
56 } | 57 } |
57 if (!file_util::Delete(unclean_file_path, false)) { | 58 if (!file_util::Delete(unclean_file_path, false)) { |
58 s_system_log.LogError("Failed to delete unclean shutdown file %s", | 59 s_system_log.LogError("Failed to delete unclean shutdown file %s", |
59 kUncleanShutdownFile); | 60 kUncleanShutdownFile); |
60 } | 61 } |
| 62 |
| 63 // Touch a file to notify the metrics daemon that a kernel crash has |
| 64 // been detected so that it can log the time since the last kernel |
| 65 // crash. |
| 66 static const char kKernelCrashDetectedFile[] = "/tmp/kernel-crash-detected"; |
| 67 FilePath crash_detected(kKernelCrashDetectedFile); |
| 68 file_util::WriteFile(crash_detected, kEmpty, 0); |
61 } | 69 } |
62 | 70 |
63 static bool PrepareUncleanShutdownCheck() { | 71 static bool PrepareUncleanShutdownCheck() { |
64 static const char empty[] = ""; | |
65 FilePath file_path(kUncleanShutdownFile); | 72 FilePath file_path(kUncleanShutdownFile); |
66 file_util::CreateDirectory(file_path.DirName()); | 73 file_util::CreateDirectory(file_path.DirName()); |
67 return file_util::WriteFile(file_path, empty, 0) == 0; | 74 return file_util::WriteFile(file_path, kEmpty, 0) == 0; |
68 } | 75 } |
69 | 76 |
70 static void SignalCleanShutdown() { | 77 static void SignalCleanShutdown() { |
71 s_system_log.LogInfo("Clean shutdown signalled"); | 78 s_system_log.LogInfo("Clean shutdown signalled"); |
72 file_util::Delete(FilePath(kUncleanShutdownFile), false); | 79 file_util::Delete(FilePath(kUncleanShutdownFile), false); |
73 } | 80 } |
74 | 81 |
75 static void CountUserCrash() { | 82 static void CountUserCrash() { |
76 CHECK(IsMetricsCollectionAllowed()); | 83 CHECK(IsMetricsCollectionAllowed()); |
77 s_metrics_lib.SendEnumToUMA(std::string(kCrashCounterHistogram), | 84 s_metrics_lib.SendEnumToUMA(std::string(kCrashCounterHistogram), |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 // handling a crash. | 137 // handling a crash. |
131 if (FLAGS_crash_test) { | 138 if (FLAGS_crash_test) { |
132 *(char *)0 = 0; | 139 *(char *)0 = 0; |
133 return 0; | 140 return 0; |
134 } | 141 } |
135 | 142 |
136 user_collector.HandleCrash(FLAGS_signal, FLAGS_pid, FLAGS_exec); | 143 user_collector.HandleCrash(FLAGS_signal, FLAGS_pid, FLAGS_exec); |
137 | 144 |
138 return 0; | 145 return 0; |
139 } | 146 } |
OLD | NEW |