Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 5 | #include "crash-reporter/user_collector.h" |
| 6 | |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 7 | #include <grp.h> // For struct group. |
| 8 | #include <pwd.h> // For struct passwd. |
Ken Mixter | 2953c3a | 2010-10-18 14:42:20 -0700 | [diff] [blame] | 9 | #include <sys/types.h> // For getpwuid_r, getgrnam_r, WEXITSTATUS. |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 10 | |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 11 | #include <string> |
Ken Mixter | 2953c3a | 2010-10-18 14:42:20 -0700 | [diff] [blame] | 12 | #include <vector> |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 13 | |
| 14 | #include "base/file_util.h" |
| 15 | #include "base/logging.h" |
| 16 | #include "base/string_util.h" |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 17 | #include "crash-reporter/system_logging.h" |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 18 | #include "gflags/gflags.h" |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 19 | |
Ken Mixter | c6a58e0 | 2010-11-01 18:05:30 -0700 | [diff] [blame] | 20 | #pragma GCC diagnostic ignored "-Wstrict-aliasing" |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 21 | DEFINE_bool(core2md_failure_test, false, "Core2md failure test"); |
| 22 | DEFINE_bool(directory_failure_test, false, "Spool directory failure test"); |
Ken Mixter | c6a58e0 | 2010-11-01 18:05:30 -0700 | [diff] [blame] | 23 | DEFINE_string(filter_in, "", |
| 24 | "Ignore all crashes but this for testing"); |
| 25 | #pragma GCC diagnostic error "-Wstrict-aliasing" |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 26 | |
| 27 | static const char kCollectionErrorSignature[] = |
| 28 | "crash_reporter-user-collection"; |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 29 | // This procfs file is used to cause kernel core file writing to |
| 30 | // instead pipe the core file into a user space process. See |
| 31 | // core(5) man page. |
| 32 | static const char kCorePatternFile[] = "/proc/sys/kernel/core_pattern"; |
Ken Mixter | c49dbd4 | 2010-12-14 17:44:11 -0800 | [diff] [blame^] | 33 | static const char kCorePipeLimitFile[] = "/proc/sys/kernel/core_pipe_limit"; |
| 34 | // Set core_pipe_limit to 4 so that we can catch a few unrelated concurrent |
| 35 | // crashes, but finite to avoid infinitely recursing on crash handling. |
| 36 | static const char kCorePipeLimit[] = "4"; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 37 | static const char kCoreToMinidumpConverterPath[] = "/usr/bin/core2md"; |
Ken Mixter | 7ac7a70 | 2010-08-13 15:43:34 -0700 | [diff] [blame] | 38 | static const char kLeaveCoreFile[] = "/root/.leave_core"; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 39 | |
Ken Mixter | c49dbd4 | 2010-12-14 17:44:11 -0800 | [diff] [blame^] | 40 | static const char kDefaultLogConfig[] = "/etc/crash_reporter_logs.conf"; |
| 41 | |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 42 | const char *UserCollector::kUserId = "Uid:\t"; |
| 43 | const char *UserCollector::kGroupId = "Gid:\t"; |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 44 | |
| 45 | UserCollector::UserCollector() |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 46 | : generate_diagnostics_(false), |
| 47 | core_pattern_file_(kCorePatternFile), |
Ken Mixter | c49dbd4 | 2010-12-14 17:44:11 -0800 | [diff] [blame^] | 48 | core_pipe_limit_file_(kCorePipeLimitFile), |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 49 | initialized_(false) { |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | void UserCollector::Initialize( |
| 53 | UserCollector::CountCrashFunction count_crash_function, |
| 54 | const std::string &our_path, |
| 55 | UserCollector::IsFeedbackAllowedFunction is_feedback_allowed_function, |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 56 | SystemLogging *logger, |
| 57 | bool generate_diagnostics) { |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 58 | CrashCollector::Initialize(count_crash_function, |
| 59 | is_feedback_allowed_function, |
| 60 | logger); |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 61 | our_path_ = our_path; |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 62 | initialized_ = true; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 63 | generate_diagnostics_ = generate_diagnostics; |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | UserCollector::~UserCollector() { |
| 67 | } |
| 68 | |
| 69 | std::string UserCollector::GetPattern(bool enabled) const { |
| 70 | if (enabled) { |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 71 | return StringPrintf("|%s --signal=%%s --pid=%%p", our_path_.c_str()); |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 72 | } else { |
| 73 | return "core"; |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | bool UserCollector::SetUpInternal(bool enabled) { |
| 78 | CHECK(initialized_); |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 79 | logger_->LogInfo("%s user crash handling", |
| 80 | enabled ? "Enabling" : "Disabling"); |
Ken Mixter | c49dbd4 | 2010-12-14 17:44:11 -0800 | [diff] [blame^] | 81 | if (file_util::WriteFile(FilePath(core_pipe_limit_file_), |
| 82 | kCorePipeLimit, |
| 83 | strlen(kCorePipeLimit)) != |
| 84 | static_cast<int>(strlen(kCorePipeLimit))) { |
| 85 | logger_->LogError("Unable to write %s", core_pipe_limit_file_.c_str()); |
| 86 | return false; |
| 87 | } |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 88 | std::string pattern = GetPattern(enabled); |
| 89 | if (file_util::WriteFile(FilePath(core_pattern_file_), |
| 90 | pattern.c_str(), |
| 91 | pattern.length()) != |
| 92 | static_cast<int>(pattern.length())) { |
| 93 | logger_->LogError("Unable to write %s", core_pattern_file_.c_str()); |
| 94 | return false; |
| 95 | } |
| 96 | return true; |
| 97 | } |
| 98 | |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 99 | FilePath UserCollector::GetProcessPath(pid_t pid) { |
| 100 | return FilePath(StringPrintf("/proc/%d", pid)); |
| 101 | } |
| 102 | |
| 103 | bool UserCollector::GetSymlinkTarget(const FilePath &symlink, |
| 104 | FilePath *target) { |
| 105 | int max_size = 32; |
| 106 | scoped_array<char> buffer; |
| 107 | while (true) { |
| 108 | buffer.reset(new char[max_size + 1]); |
| 109 | ssize_t size = readlink(symlink.value().c_str(), buffer.get(), max_size); |
| 110 | if (size < 0) { |
| 111 | return false; |
| 112 | } |
| 113 | buffer[size] = 0; |
| 114 | if (size == max_size) { |
| 115 | // Avoid overflow when doubling. |
| 116 | if (max_size * 2 > max_size) { |
| 117 | max_size *= 2; |
| 118 | continue; |
| 119 | } else { |
| 120 | return false; |
| 121 | } |
| 122 | } |
| 123 | break; |
| 124 | } |
| 125 | |
| 126 | *target = FilePath(buffer.get()); |
| 127 | return true; |
| 128 | } |
| 129 | |
| 130 | bool UserCollector::GetExecutableBaseNameFromPid(uid_t pid, |
| 131 | std::string *base_name) { |
| 132 | FilePath target; |
| 133 | if (!GetSymlinkTarget(GetProcessPath(pid).Append("exe"), &target)) |
| 134 | return false; |
| 135 | *base_name = target.BaseName().value(); |
| 136 | return true; |
| 137 | } |
| 138 | |
| 139 | bool UserCollector::GetIdFromStatus(const char *prefix, |
| 140 | IdKind kind, |
| 141 | const std::string &status_contents, |
| 142 | int *id) { |
| 143 | // From fs/proc/array.c:task_state(), this file contains: |
| 144 | // \nUid:\t<uid>\t<euid>\t<suid>\t<fsuid>\n |
| 145 | std::vector<std::string> status_lines; |
| 146 | SplitString(status_contents, '\n', &status_lines); |
| 147 | std::vector<std::string>::iterator line_iterator; |
| 148 | for (line_iterator = status_lines.begin(); |
| 149 | line_iterator != status_lines.end(); |
| 150 | ++line_iterator) { |
| 151 | if (line_iterator->find(prefix) == 0) |
| 152 | break; |
| 153 | } |
| 154 | if (line_iterator == status_lines.end()) { |
| 155 | return false; |
| 156 | } |
| 157 | std::string id_substring = line_iterator->substr(strlen(prefix), |
| 158 | std::string::npos); |
| 159 | std::vector<std::string> ids; |
| 160 | SplitString(id_substring, '\t', &ids); |
| 161 | if (ids.size() != kIdMax || kind < 0 || kind >= kIdMax) { |
| 162 | return false; |
| 163 | } |
| 164 | const char *number = ids[kind].c_str(); |
| 165 | char *end_number = NULL; |
| 166 | *id = strtol(number, &end_number, 10); |
| 167 | if (*end_number != '\0') |
| 168 | return false; |
| 169 | return true; |
| 170 | } |
| 171 | |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 172 | void UserCollector::LogCollectionError(const std::string &error_message) { |
| 173 | error_log_.append(error_message.c_str()); |
| 174 | error_log_.append("\n"); |
| 175 | logger_->LogError(error_message.c_str()); |
| 176 | } |
| 177 | |
| 178 | void UserCollector::EnqueueCollectionErrorLog(pid_t pid, |
| 179 | const std::string &exec) { |
| 180 | FilePath crash_path; |
| 181 | logger_->LogInfo("Writing conversion problems as separate crash report."); |
| 182 | if (!GetCreatedCrashDirectoryByEuid(0, &crash_path, NULL)) { |
| 183 | logger_->LogError("Could not even get log directory; out of space?"); |
| 184 | return; |
| 185 | } |
| 186 | std::string dump_basename = FormatDumpBasename(exec, time(NULL), pid); |
| 187 | FilePath log_path = GetCrashPath(crash_path, dump_basename, "log"); |
| 188 | FilePath meta_path = GetCrashPath(crash_path, dump_basename, "meta"); |
Ken Mixter | 9b34647 | 2010-11-07 13:45:45 -0800 | [diff] [blame] | 189 | // We must use WriteNewFile instead of file_util::WriteFile as we do |
| 190 | // not want to write with root access to a symlink that an attacker |
| 191 | // might have created. |
| 192 | WriteNewFile(log_path, error_log_.data(), error_log_.length()); |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 193 | AddCrashMetaData("sig", kCollectionErrorSignature); |
| 194 | WriteCrashMetaData(meta_path, exec, log_path.value()); |
| 195 | } |
| 196 | |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 197 | bool UserCollector::CopyOffProcFiles(pid_t pid, |
| 198 | const FilePath &container_dir) { |
| 199 | if (!file_util::CreateDirectory(container_dir)) { |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 200 | LogCollectionError(StringPrintf("Could not create %s", |
| 201 | container_dir.value().c_str())); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 202 | return false; |
| 203 | } |
| 204 | FilePath process_path = GetProcessPath(pid); |
| 205 | if (!file_util::PathExists(process_path)) { |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 206 | LogCollectionError(StringPrintf("Path %s does not exist", |
| 207 | process_path.value().c_str())); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 208 | return false; |
| 209 | } |
| 210 | static const char *proc_files[] = { |
| 211 | "auxv", |
| 212 | "cmdline", |
| 213 | "environ", |
| 214 | "maps", |
| 215 | "status" |
| 216 | }; |
| 217 | for (unsigned i = 0; i < arraysize(proc_files); ++i) { |
| 218 | if (!file_util::CopyFile(process_path.Append(proc_files[i]), |
| 219 | container_dir.Append(proc_files[i]))) { |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 220 | LogCollectionError(StringPrintf("Could not copy %s file", |
| 221 | proc_files[i])); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 222 | return false; |
| 223 | } |
| 224 | } |
| 225 | return true; |
| 226 | } |
| 227 | |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 228 | bool UserCollector::GetCreatedCrashDirectory(pid_t pid, |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 229 | FilePath *crash_file_path, |
| 230 | bool *out_of_capacity) { |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 231 | FilePath process_path = GetProcessPath(pid); |
| 232 | std::string status; |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 233 | if (FLAGS_directory_failure_test) { |
| 234 | LogCollectionError("Purposefully failing to create spool directory"); |
| 235 | return false; |
| 236 | } |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 237 | if (!file_util::ReadFileToString(process_path.Append("status"), |
| 238 | &status)) { |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 239 | LogCollectionError("Could not read status file"); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 240 | return false; |
| 241 | } |
| 242 | int process_euid; |
| 243 | if (!GetIdFromStatus(kUserId, kIdEffective, status, &process_euid)) { |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 244 | LogCollectionError("Could not find euid in status file"); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 245 | return false; |
| 246 | } |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 247 | if (!GetCreatedCrashDirectoryByEuid(process_euid, |
| 248 | crash_file_path, |
| 249 | out_of_capacity)) { |
| 250 | LogCollectionError("Could not create crash directory"); |
| 251 | return false; |
| 252 | } |
| 253 | return true; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | bool UserCollector::CopyStdinToCoreFile(const FilePath &core_path) { |
| 257 | // Copy off all stdin to a core file. |
| 258 | FilePath stdin_path("/dev/fd/0"); |
| 259 | if (file_util::CopyFile(stdin_path, core_path)) { |
| 260 | return true; |
| 261 | } |
| 262 | |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 263 | LogCollectionError("Could not write core file"); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 264 | // If the file system was full, make sure we remove any remnants. |
| 265 | file_util::Delete(core_path, false); |
| 266 | return false; |
| 267 | } |
| 268 | |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 269 | bool UserCollector::RunCoreToMinidump(const FilePath &core_path, |
| 270 | const FilePath &procfs_directory, |
| 271 | const FilePath &minidump_path, |
| 272 | const FilePath &temp_directory) { |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 273 | FilePath output_path = temp_directory.Append("output"); |
Ken Mixter | 2953c3a | 2010-10-18 14:42:20 -0700 | [diff] [blame] | 274 | std::vector<const char *> core2md_arguments; |
| 275 | core2md_arguments.push_back(kCoreToMinidumpConverterPath); |
| 276 | core2md_arguments.push_back(core_path.value().c_str()); |
| 277 | core2md_arguments.push_back(procfs_directory.value().c_str()); |
| 278 | core2md_arguments.push_back(minidump_path.value().c_str()); |
| 279 | |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 280 | if (FLAGS_core2md_failure_test) { |
| 281 | // To test how core2md errors are propagaged, cause an error |
| 282 | // by forgetting a required argument. |
| 283 | core2md_arguments.pop_back(); |
| 284 | } |
| 285 | |
Ken Mixter | 2953c3a | 2010-10-18 14:42:20 -0700 | [diff] [blame] | 286 | int errorlevel = ForkExecAndPipe(core2md_arguments, |
| 287 | output_path.value().c_str()); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 288 | |
| 289 | std::string output; |
| 290 | file_util::ReadFileToString(output_path, &output); |
| 291 | if (errorlevel != 0) { |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 292 | LogCollectionError(StringPrintf("Problem during %s [result=%d]: %s", |
| 293 | kCoreToMinidumpConverterPath, |
| 294 | errorlevel, |
| 295 | output.c_str())); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 296 | return false; |
| 297 | } |
| 298 | |
| 299 | if (!file_util::PathExists(minidump_path)) { |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 300 | LogCollectionError(StringPrintf("Minidump file %s was not created", |
| 301 | minidump_path.value().c_str())); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 302 | return false; |
| 303 | } |
| 304 | return true; |
| 305 | } |
| 306 | |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 307 | bool UserCollector::ConvertCoreToMinidump(pid_t pid, |
| 308 | const FilePath &container_dir, |
| 309 | const FilePath &core_path, |
| 310 | const FilePath &minidump_path) { |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 311 | if (!CopyOffProcFiles(pid, container_dir)) { |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 312 | return false; |
| 313 | } |
| 314 | |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 315 | if (!CopyStdinToCoreFile(core_path)) { |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 316 | return false; |
| 317 | } |
| 318 | |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 319 | bool conversion_result = RunCoreToMinidump( |
| 320 | core_path, |
| 321 | container_dir, // procfs directory |
| 322 | minidump_path, |
| 323 | container_dir); // temporary directory |
Ken Mixter | ee849c5 | 2010-09-30 15:30:10 -0700 | [diff] [blame] | 324 | |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 325 | if (conversion_result) { |
| 326 | logger_->LogInfo("Stored minidump to %s", minidump_path.value().c_str()); |
| 327 | } |
| 328 | |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 329 | return conversion_result; |
| 330 | } |
| 331 | |
| 332 | bool UserCollector::ConvertAndEnqueueCrash(int pid, |
| 333 | const std::string &exec, |
| 334 | bool *out_of_capacity) { |
| 335 | FilePath crash_path; |
| 336 | if (!GetCreatedCrashDirectory(pid, &crash_path, out_of_capacity)) { |
| 337 | LogCollectionError("Unable to find/create process-specific crash path"); |
| 338 | return false; |
| 339 | } |
| 340 | |
| 341 | // Directory like /tmp/crash_reporter.1234 which contains the |
| 342 | // procfs entries and other temporary files used during conversion. |
| 343 | FilePath container_dir = FilePath("/tmp").Append( |
| 344 | StringPrintf("crash_reporter.%d", pid)); |
| 345 | std::string dump_basename = FormatDumpBasename(exec, time(NULL), pid); |
| 346 | FilePath core_path = GetCrashPath(crash_path, dump_basename, "core"); |
| 347 | FilePath meta_path = GetCrashPath(crash_path, dump_basename, "meta"); |
| 348 | FilePath minidump_path = GetCrashPath(crash_path, dump_basename, "dmp"); |
Ken Mixter | c49dbd4 | 2010-12-14 17:44:11 -0800 | [diff] [blame^] | 349 | FilePath log_path = GetCrashPath(crash_path, dump_basename, "log"); |
| 350 | |
| 351 | if (GetLogContents(FilePath(kDefaultLogConfig), exec, log_path)) |
| 352 | AddCrashMetaData("log", log_path.value()); |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 353 | |
| 354 | if (!ConvertCoreToMinidump(pid, container_dir, core_path, |
| 355 | minidump_path)) { |
| 356 | logger_->LogInfo("Leaving core file at %s due to conversion error", |
| 357 | core_path.value().c_str()); |
| 358 | return false; |
| 359 | } |
| 360 | |
| 361 | // Here we commit to sending this file. We must not return false |
| 362 | // after this point or we will generate a log report as well as a |
| 363 | // crash report. |
| 364 | WriteCrashMetaData(meta_path, |
| 365 | exec, |
| 366 | minidump_path.value()); |
| 367 | |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 368 | if (!file_util::PathExists(FilePath(kLeaveCoreFile))) { |
| 369 | file_util::Delete(core_path, false); |
| 370 | } else { |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 371 | logger_->LogInfo("Leaving core file at %s due to developer image", |
| 372 | core_path.value().c_str()); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 375 | file_util::Delete(container_dir, true); |
| 376 | return true; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | bool UserCollector::HandleCrash(int signal, int pid, const char *force_exec) { |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 380 | CHECK(initialized_); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 381 | std::string exec; |
| 382 | if (force_exec) { |
| 383 | exec.assign(force_exec); |
| 384 | } else if (!GetExecutableBaseNameFromPid(pid, &exec)) { |
| 385 | // If for some reason we don't have the base name, avoid completely |
| 386 | // failing by indicating an unknown name. |
| 387 | exec = "unknown"; |
| 388 | } |
Ken Mixter | c6a58e0 | 2010-11-01 18:05:30 -0700 | [diff] [blame] | 389 | |
| 390 | // Allow us to test the crash reporting mechanism successfully even if |
| 391 | // other parts of the system crash. |
| 392 | if (!FLAGS_filter_in.empty() && |
| 393 | (FLAGS_filter_in == "none" || |
| 394 | FLAGS_filter_in != exec)) { |
| 395 | // We use a different format message to make it more obvious in tests |
| 396 | // which crashes are test generated and which are real. |
| 397 | logger_->LogWarning("Ignoring crash from %s[%d] while filter_in=%s", |
| 398 | exec.c_str(), pid, FLAGS_filter_in.c_str()); |
| 399 | return true; |
| 400 | } |
| 401 | |
Ken Mixter | ee849c5 | 2010-09-30 15:30:10 -0700 | [diff] [blame] | 402 | bool feedback = is_feedback_allowed_function_(); |
Ken Mixter | 2105b49 | 2010-11-09 16:14:38 -0800 | [diff] [blame] | 403 | const char *handling_string = "handling"; |
| 404 | if (!feedback) { |
| 405 | handling_string = "ignoring - no consent"; |
| 406 | } |
| 407 | |
| 408 | // Treat Chrome crashes as if the user opted-out. We stop counting Chrome |
| 409 | // crashes towards user crashes, so user crashes really mean non-Chrome |
| 410 | // user-space crashes. |
| 411 | if (exec == "chrome") { |
| 412 | feedback = false; |
| 413 | handling_string = "ignoring - chrome crash"; |
| 414 | } |
| 415 | |
Ken Mixter | ee849c5 | 2010-09-30 15:30:10 -0700 | [diff] [blame] | 416 | logger_->LogWarning("Received crash notification for %s[%d] sig %d (%s)", |
Ken Mixter | 2105b49 | 2010-11-09 16:14:38 -0800 | [diff] [blame] | 417 | exec.c_str(), pid, signal, handling_string); |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 418 | |
Ken Mixter | ee849c5 | 2010-09-30 15:30:10 -0700 | [diff] [blame] | 419 | if (feedback) { |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 420 | count_crash_function_(); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 421 | |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 422 | if (generate_diagnostics_) { |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 423 | bool out_of_capacity = false; |
| 424 | if (!ConvertAndEnqueueCrash(pid, exec, &out_of_capacity)) { |
| 425 | if (!out_of_capacity) |
| 426 | EnqueueCollectionErrorLog(pid, exec); |
| 427 | return false; |
| 428 | } |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 429 | } |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 430 | } |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 431 | |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 432 | return true; |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 433 | } |