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 "crash-reporter/kernel_collector.h" | 5 #include "crash-reporter/kernel_collector.h" |
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" |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 preserved_dump_path_, | 59 preserved_dump_path_, |
60 kClearingSequence, | 60 kClearingSequence, |
61 strlen(kClearingSequence)) != strlen(kClearingSequence)) { | 61 strlen(kClearingSequence)) != strlen(kClearingSequence)) { |
62 logger_->LogError("Failed to clear kernel crash dump"); | 62 logger_->LogError("Failed to clear kernel crash dump"); |
63 return false; | 63 return false; |
64 } | 64 } |
65 logger_->LogInfo("Cleared kernel crash diagnostics"); | 65 logger_->LogInfo("Cleared kernel crash diagnostics"); |
66 return true; | 66 return true; |
67 } | 67 } |
68 | 68 |
69 FilePath KernelCollector::GetKernelCrashPath( | |
70 const FilePath &root_crash_path, | |
71 time_t timestamp) { | |
72 std::string dump_basename = | |
73 FormatDumpBasename(kKernelExecName, | |
74 timestamp, | |
75 kKernelPid); | |
76 return root_crash_path.Append( | |
77 StringPrintf("%s.kcrash", dump_basename.c_str())); | |
78 } | |
79 | |
80 bool KernelCollector::Collect() { | 69 bool KernelCollector::Collect() { |
81 std::string kernel_dump; | 70 std::string kernel_dump; |
82 FilePath root_crash_directory; | 71 FilePath root_crash_directory; |
83 if (!LoadPreservedDump(&kernel_dump)) { | 72 if (!LoadPreservedDump(&kernel_dump)) { |
84 return false; | 73 return false; |
85 } | 74 } |
86 if (kernel_dump.empty()) { | 75 if (kernel_dump.empty()) { |
87 return false; | 76 return false; |
88 } | 77 } |
| 78 logger_->LogInfo("Received prior crash notification from kernel"); |
| 79 |
89 if (is_feedback_allowed_function_()) { | 80 if (is_feedback_allowed_function_()) { |
90 count_crash_function_(); | 81 count_crash_function_(); |
91 | 82 |
92 if (!GetCreatedCrashDirectoryByEuid(kRootUid, | 83 if (!GetCreatedCrashDirectoryByEuid(kRootUid, |
93 &root_crash_directory)) { | 84 &root_crash_directory)) { |
94 return true; | 85 return true; |
95 } | 86 } |
96 | 87 |
97 FilePath kernel_crash_path = GetKernelCrashPath(root_crash_directory, | 88 std::string dump_basename = |
98 time(NULL)); | 89 FormatDumpBasename(kKernelExecName, |
| 90 time(NULL), |
| 91 kKernelPid); |
| 92 FilePath kernel_crash_path = root_crash_directory.Append( |
| 93 StringPrintf("%s.kcrash", dump_basename.c_str())); |
| 94 |
99 if (file_util::WriteFile(kernel_crash_path, | 95 if (file_util::WriteFile(kernel_crash_path, |
100 kernel_dump.data(), | 96 kernel_dump.data(), |
101 kernel_dump.length()) != | 97 kernel_dump.length()) != |
102 static_cast<int>(kernel_dump.length())) { | 98 static_cast<int>(kernel_dump.length())) { |
103 logger_->LogInfo("Failed to write kernel dump to %s", | 99 logger_->LogInfo("Failed to write kernel dump to %s", |
104 kernel_crash_path.value().c_str()); | 100 kernel_crash_path.value().c_str()); |
105 return true; | 101 return true; |
106 } | 102 } |
107 | 103 |
| 104 WriteCrashMetaData( |
| 105 root_crash_directory.Append( |
| 106 StringPrintf("%s.meta", dump_basename.c_str())), |
| 107 kKernelExecName); |
| 108 |
108 logger_->LogInfo("Collected kernel crash diagnostics into %s", | 109 logger_->LogInfo("Collected kernel crash diagnostics into %s", |
109 kernel_crash_path.value().c_str()); | 110 kernel_crash_path.value().c_str()); |
110 } else { | 111 } else { |
111 logger_->LogInfo("Crash not saved since metrics disabled"); | 112 logger_->LogInfo("Crash not saved since metrics disabled"); |
112 } | 113 } |
113 if (!ClearPreservedDump()) { | 114 if (!ClearPreservedDump()) { |
114 return false; | 115 return false; |
115 } | 116 } |
116 | 117 |
117 return true; | 118 return true; |
118 } | 119 } |
OLD | NEW |