Steve Fung | 6c34c25 | 2015-08-20 00:27:30 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 16 | |
Steve Fung | 129bea5 | 2015-07-23 13:11:15 -0700 | [diff] [blame] | 17 | #include "user_collector.h" |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 18 | |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 19 | #include <elf.h> |
| 20 | #include <fcntl.h> |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 21 | #include <grp.h> // For struct group. |
Ken Mixter | 1b8fe01 | 2011-01-25 13:33:05 -0800 | [diff] [blame] | 22 | #include <pcrecpp.h> |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 23 | #include <pwd.h> // For struct passwd. |
Ben Chan | f84ea21 | 2014-08-06 17:27:48 -0700 | [diff] [blame] | 24 | #include <stdint.h> |
Steve Fung | 8bafb3d | 2015-08-07 13:22:46 -0700 | [diff] [blame] | 25 | #include <sys/cdefs.h> // For __WORDSIZE |
Ken Mixter | 2953c3a | 2010-10-18 14:42:20 -0700 | [diff] [blame] | 26 | #include <sys/types.h> // For getpwuid_r, getgrnam_r, WEXITSTATUS. |
Steve Fung | b440e50 | 2015-08-21 02:12:34 -0700 | [diff] [blame] | 27 | #include <unistd.h> // For setgroups |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 28 | |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 29 | #include <string> |
Ken Mixter | 2953c3a | 2010-10-18 14:42:20 -0700 | [diff] [blame] | 30 | #include <vector> |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 31 | |
Ben Chan | ab6cc90 | 2014-09-05 08:21:06 -0700 | [diff] [blame] | 32 | #include <base/files/file_util.h> |
Ben Chan | 7e77690 | 2014-06-18 13:19:51 -0700 | [diff] [blame] | 33 | #include <base/logging.h> |
| 34 | #include <base/posix/eintr_wrapper.h> |
Ben Chan | 7e77690 | 2014-06-18 13:19:51 -0700 | [diff] [blame] | 35 | #include <base/strings/string_split.h> |
| 36 | #include <base/strings/string_util.h> |
| 37 | #include <base/strings/stringprintf.h> |
| 38 | #include <chromeos/process.h> |
| 39 | #include <chromeos/syslog_logging.h> |
Steve Fung | ab2ac7d | 2015-08-14 17:58:05 -0700 | [diff] [blame] | 40 | #include <cutils/properties.h> |
Steve Fung | b440e50 | 2015-08-21 02:12:34 -0700 | [diff] [blame] | 41 | #include <private/android_filesystem_config.h> |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 42 | |
| 43 | static const char kCollectionErrorSignature[] = |
| 44 | "crash_reporter-user-collection"; |
Steve Fung | ab2ac7d | 2015-08-14 17:58:05 -0700 | [diff] [blame] | 45 | static const char kCorePatternProperty[] = "crash_reporter.coredump.enabled"; |
| 46 | static const char kCoreToMinidumpConverterPath[] = "/system/bin/core2md"; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 47 | |
Ben Chan | f13bb58 | 2012-01-06 08:22:07 -0800 | [diff] [blame] | 48 | static const char kStatePrefix[] = "State:\t"; |
Ken Mixter | c49dbd4 | 2010-12-14 17:44:11 -0800 | [diff] [blame] | 49 | |
Steve Fung | da98133 | 2015-08-23 17:18:23 -0700 | [diff] [blame] | 50 | static const char kCoreTempFolder[] = "/data/misc/crash_reporter/tmp"; |
Steve Fung | ab2ac7d | 2015-08-14 17:58:05 -0700 | [diff] [blame] | 51 | |
Michael Krebs | 1c57e9e | 2012-09-25 18:03:13 -0700 | [diff] [blame] | 52 | // Define an otherwise invalid value that represents an unknown UID. |
| 53 | static const uid_t kUnknownUid = -1; |
| 54 | |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 55 | const char *UserCollector::kUserId = "Uid:\t"; |
| 56 | const char *UserCollector::kGroupId = "Gid:\t"; |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 57 | |
Simon Que | 9f90aca | 2013-02-19 17:19:52 -0800 | [diff] [blame] | 58 | using base::FilePath; |
Mike Frysinger | a557c11 | 2014-02-05 22:55:39 -0500 | [diff] [blame] | 59 | using base::StringPrintf; |
Simon Que | 9f90aca | 2013-02-19 17:19:52 -0800 | [diff] [blame] | 60 | |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 61 | UserCollector::UserCollector() |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 62 | : generate_diagnostics_(false), |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 63 | initialized_(false) { |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | void UserCollector::Initialize( |
| 67 | UserCollector::CountCrashFunction count_crash_function, |
| 68 | const std::string &our_path, |
| 69 | UserCollector::IsFeedbackAllowedFunction is_feedback_allowed_function, |
Steve Fung | d6169a2 | 2014-08-11 15:52:23 -0700 | [diff] [blame] | 70 | bool generate_diagnostics, |
| 71 | bool core2md_failure, |
| 72 | bool directory_failure, |
| 73 | const std::string &filter_in) { |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 74 | CrashCollector::Initialize(count_crash_function, |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 75 | is_feedback_allowed_function); |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 76 | our_path_ = our_path; |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 77 | initialized_ = true; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 78 | generate_diagnostics_ = generate_diagnostics; |
Steve Fung | d6169a2 | 2014-08-11 15:52:23 -0700 | [diff] [blame] | 79 | core2md_failure_ = core2md_failure; |
| 80 | directory_failure_ = directory_failure; |
| 81 | filter_in_ = filter_in; |
Steve Fung | b440e50 | 2015-08-21 02:12:34 -0700 | [diff] [blame] | 82 | |
| 83 | gid_t groups[] = { AID_SYSTEM, AID_DBUS }; |
| 84 | if (setgroups(arraysize(groups), groups) != 0) { |
| 85 | PLOG(FATAL) << "Unable to set groups to system and dbus"; |
| 86 | } |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | UserCollector::~UserCollector() { |
| 90 | } |
| 91 | |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 92 | std::string UserCollector::GetErrorTypeSignature(ErrorType error_type) const { |
| 93 | switch (error_type) { |
| 94 | case kErrorSystemIssue: |
| 95 | return "system-issue"; |
| 96 | case kErrorReadCoreData: |
| 97 | return "read-core-data"; |
| 98 | case kErrorUnusableProcFiles: |
| 99 | return "unusable-proc-files"; |
| 100 | case kErrorInvalidCoreFile: |
| 101 | return "invalid-core-file"; |
| 102 | case kErrorUnsupported32BitCoreFile: |
| 103 | return "unsupported-32bit-core-file"; |
| 104 | case kErrorCore2MinidumpConversion: |
| 105 | return "core2md-conversion"; |
| 106 | default: |
| 107 | return ""; |
| 108 | } |
| 109 | } |
| 110 | |
Michael Krebs | 1c57e9e | 2012-09-25 18:03:13 -0700 | [diff] [blame] | 111 | // Return the string that should be used for the kernel's core_pattern file. |
| 112 | // Note that if you change the format of the enabled pattern, you'll probably |
| 113 | // also need to change the ParseCrashAttributes() function below, the |
| 114 | // user_collector_test.cc unittest, and the logging_UserCrash.py autotest. |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 115 | std::string UserCollector::GetPattern(bool enabled) const { |
| 116 | if (enabled) { |
Michael Krebs | 1c57e9e | 2012-09-25 18:03:13 -0700 | [diff] [blame] | 117 | // Combine the four crash attributes into one parameter to try to reduce |
| 118 | // the size of the invocation line for crash_reporter, since the kernel |
| 119 | // has a fixed-sized (128B) buffer for it (before parameter expansion). |
| 120 | // Note that the kernel does not support quoted arguments in core_pattern. |
Mike Frysinger | bfdf4a8 | 2014-03-14 09:31:33 -0400 | [diff] [blame] | 121 | return StringPrintf("|%s --user=%%P:%%s:%%u:%%e", our_path_.c_str()); |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 122 | } else { |
| 123 | return "core"; |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | bool UserCollector::SetUpInternal(bool enabled) { |
| 128 | CHECK(initialized_); |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 129 | LOG(INFO) << (enabled ? "Enabling" : "Disabling") << " user crash handling"; |
| 130 | |
Steve Fung | ab2ac7d | 2015-08-14 17:58:05 -0700 | [diff] [blame] | 131 | property_set(kCorePatternProperty, enabled ? "1" : "0"); |
| 132 | |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 133 | return true; |
| 134 | } |
| 135 | |
Ben Chan | f13bb58 | 2012-01-06 08:22:07 -0800 | [diff] [blame] | 136 | bool UserCollector::GetFirstLineWithPrefix( |
| 137 | const std::vector<std::string> &lines, |
| 138 | const char *prefix, std::string *line) { |
| 139 | std::vector<std::string>::const_iterator line_iterator; |
| 140 | for (line_iterator = lines.begin(); line_iterator != lines.end(); |
| 141 | ++line_iterator) { |
| 142 | if (line_iterator->find(prefix) == 0) { |
| 143 | *line = *line_iterator; |
| 144 | return true; |
| 145 | } |
| 146 | } |
| 147 | return false; |
| 148 | } |
| 149 | |
| 150 | bool UserCollector::GetIdFromStatus( |
| 151 | const char *prefix, IdKind kind, |
| 152 | const std::vector<std::string> &status_lines, int *id) { |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 153 | // From fs/proc/array.c:task_state(), this file contains: |
| 154 | // \nUid:\t<uid>\t<euid>\t<suid>\t<fsuid>\n |
Ben Chan | f13bb58 | 2012-01-06 08:22:07 -0800 | [diff] [blame] | 155 | std::string id_line; |
| 156 | if (!GetFirstLineWithPrefix(status_lines, prefix, &id_line)) { |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 157 | return false; |
| 158 | } |
Ben Chan | f13bb58 | 2012-01-06 08:22:07 -0800 | [diff] [blame] | 159 | std::string id_substring = id_line.substr(strlen(prefix), std::string::npos); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 160 | std::vector<std::string> ids; |
Chris Masone | 3ba6c5b | 2011-05-13 16:57:09 -0700 | [diff] [blame] | 161 | base::SplitString(id_substring, '\t', &ids); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 162 | if (ids.size() != kIdMax || kind < 0 || kind >= kIdMax) { |
| 163 | return false; |
| 164 | } |
| 165 | const char *number = ids[kind].c_str(); |
Ben Chan | 262d798 | 2014-09-18 08:05:20 -0700 | [diff] [blame] | 166 | char *end_number = nullptr; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 167 | *id = strtol(number, &end_number, 10); |
Ben Chan | f13bb58 | 2012-01-06 08:22:07 -0800 | [diff] [blame] | 168 | if (*end_number != '\0') { |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 169 | return false; |
Ben Chan | f13bb58 | 2012-01-06 08:22:07 -0800 | [diff] [blame] | 170 | } |
| 171 | return true; |
| 172 | } |
| 173 | |
| 174 | bool UserCollector::GetStateFromStatus( |
| 175 | const std::vector<std::string> &status_lines, std::string *state) { |
| 176 | std::string state_line; |
| 177 | if (!GetFirstLineWithPrefix(status_lines, kStatePrefix, &state_line)) { |
| 178 | return false; |
| 179 | } |
| 180 | *state = state_line.substr(strlen(kStatePrefix), std::string::npos); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 181 | return true; |
| 182 | } |
| 183 | |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 184 | void UserCollector::EnqueueCollectionErrorLog(pid_t pid, |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 185 | ErrorType error_type, |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 186 | const std::string &exec) { |
| 187 | FilePath crash_path; |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 188 | LOG(INFO) << "Writing conversion problems as separate crash report."; |
Ben Chan | 262d798 | 2014-09-18 08:05:20 -0700 | [diff] [blame] | 189 | if (!GetCreatedCrashDirectoryByEuid(0, &crash_path, nullptr)) { |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 190 | LOG(ERROR) << "Could not even get log directory; out of space?"; |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 191 | return; |
| 192 | } |
Thiemo Nagel | 8fce285 | 2014-05-09 14:48:45 +0200 | [diff] [blame] | 193 | AddCrashMetaData("sig", kCollectionErrorSignature); |
| 194 | AddCrashMetaData("error_type", GetErrorTypeSignature(error_type)); |
Ben Chan | 262d798 | 2014-09-18 08:05:20 -0700 | [diff] [blame] | 195 | std::string dump_basename = FormatDumpBasename(exec, time(nullptr), pid); |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 196 | std::string error_log = chromeos::GetLog(); |
Ken Mixter | 1b8fe01 | 2011-01-25 13:33:05 -0800 | [diff] [blame] | 197 | FilePath diag_log_path = GetCrashPath(crash_path, dump_basename, "diaglog"); |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 198 | if (GetLogContents(FilePath(log_config_path_), kCollectionErrorSignature, |
Ken Mixter | 1b8fe01 | 2011-01-25 13:33:05 -0800 | [diff] [blame] | 199 | diag_log_path)) { |
| 200 | // We load the contents of diag_log into memory and append it to |
| 201 | // the error log. We cannot just append to files because we need |
| 202 | // to always create new files to prevent attack. |
| 203 | std::string diag_log_contents; |
Mike Frysinger | a557c11 | 2014-02-05 22:55:39 -0500 | [diff] [blame] | 204 | base::ReadFileToString(diag_log_path, &diag_log_contents); |
Ken Mixter | 1b8fe01 | 2011-01-25 13:33:05 -0800 | [diff] [blame] | 205 | error_log.append(diag_log_contents); |
Mike Frysinger | a557c11 | 2014-02-05 22:55:39 -0500 | [diff] [blame] | 206 | base::DeleteFile(diag_log_path, false); |
Ken Mixter | 1b8fe01 | 2011-01-25 13:33:05 -0800 | [diff] [blame] | 207 | } |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 208 | FilePath log_path = GetCrashPath(crash_path, dump_basename, "log"); |
| 209 | FilePath meta_path = GetCrashPath(crash_path, dump_basename, "meta"); |
Ben Chan | f30c641 | 2014-05-22 23:09:01 -0700 | [diff] [blame] | 210 | // We must use WriteNewFile instead of base::WriteFile as we do |
Ken Mixter | 9b34647 | 2010-11-07 13:45:45 -0800 | [diff] [blame] | 211 | // not want to write with root access to a symlink that an attacker |
| 212 | // might have created. |
Thiemo Nagel | 8fce285 | 2014-05-09 14:48:45 +0200 | [diff] [blame] | 213 | if (WriteNewFile(log_path, error_log.data(), error_log.length()) < 0) { |
| 214 | LOG(ERROR) << "Error writing new file " << log_path.value(); |
| 215 | return; |
| 216 | } |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 217 | WriteCrashMetaData(meta_path, exec, log_path.value()); |
| 218 | } |
| 219 | |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 220 | bool UserCollector::CopyOffProcFiles(pid_t pid, |
| 221 | const FilePath &container_dir) { |
Mike Frysinger | a557c11 | 2014-02-05 22:55:39 -0500 | [diff] [blame] | 222 | if (!base::CreateDirectory(container_dir)) { |
Chris Masone | b3fe6c3 | 2013-05-31 09:37:33 -0700 | [diff] [blame] | 223 | PLOG(ERROR) << "Could not create " << container_dir.value().c_str(); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 224 | return false; |
| 225 | } |
| 226 | FilePath process_path = GetProcessPath(pid); |
Mike Frysinger | a557c11 | 2014-02-05 22:55:39 -0500 | [diff] [blame] | 227 | if (!base::PathExists(process_path)) { |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 228 | LOG(ERROR) << "Path " << process_path.value() << " does not exist"; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 229 | return false; |
| 230 | } |
| 231 | static const char *proc_files[] = { |
| 232 | "auxv", |
| 233 | "cmdline", |
| 234 | "environ", |
| 235 | "maps", |
| 236 | "status" |
| 237 | }; |
| 238 | for (unsigned i = 0; i < arraysize(proc_files); ++i) { |
Mike Frysinger | a557c11 | 2014-02-05 22:55:39 -0500 | [diff] [blame] | 239 | if (!base::CopyFile(process_path.Append(proc_files[i]), |
| 240 | container_dir.Append(proc_files[i]))) { |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 241 | LOG(ERROR) << "Could not copy " << proc_files[i] << " file"; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 242 | return false; |
| 243 | } |
| 244 | } |
Ben Chan | ec7d783 | 2012-01-09 10:29:58 -0800 | [diff] [blame] | 245 | return true; |
Ben Chan | f13bb58 | 2012-01-06 08:22:07 -0800 | [diff] [blame] | 246 | } |
| 247 | |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 248 | bool UserCollector::ValidateProcFiles(const FilePath &container_dir) const { |
Ben Chan | f13bb58 | 2012-01-06 08:22:07 -0800 | [diff] [blame] | 249 | // Check if the maps file is empty, which could be due to the crashed |
| 250 | // process being reaped by the kernel before finishing a core dump. |
Ben Chan | f84ea21 | 2014-08-06 17:27:48 -0700 | [diff] [blame] | 251 | int64_t file_size = 0; |
Mike Frysinger | a557c11 | 2014-02-05 22:55:39 -0500 | [diff] [blame] | 252 | if (!base::GetFileSize(container_dir.Append("maps"), &file_size)) { |
Ben Chan | f13bb58 | 2012-01-06 08:22:07 -0800 | [diff] [blame] | 253 | LOG(ERROR) << "Could not get the size of maps file"; |
| 254 | return false; |
| 255 | } |
| 256 | if (file_size == 0) { |
| 257 | LOG(ERROR) << "maps file is empty"; |
| 258 | return false; |
| 259 | } |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 260 | return true; |
| 261 | } |
| 262 | |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 263 | UserCollector::ErrorType UserCollector::ValidateCoreFile( |
| 264 | const FilePath &core_path) const { |
| 265 | int fd = HANDLE_EINTR(open(core_path.value().c_str(), O_RDONLY)); |
| 266 | if (fd < 0) { |
Chris Masone | b3fe6c3 | 2013-05-31 09:37:33 -0700 | [diff] [blame] | 267 | PLOG(ERROR) << "Could not open core file " << core_path.value(); |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 268 | return kErrorInvalidCoreFile; |
| 269 | } |
| 270 | |
| 271 | char e_ident[EI_NIDENT]; |
Mike Frysinger | a557c11 | 2014-02-05 22:55:39 -0500 | [diff] [blame] | 272 | bool read_ok = base::ReadFromFD(fd, e_ident, sizeof(e_ident)); |
Mike Frysinger | f1a5014 | 2014-05-14 16:05:09 -0400 | [diff] [blame] | 273 | IGNORE_EINTR(close(fd)); |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 274 | if (!read_ok) { |
| 275 | LOG(ERROR) << "Could not read header of core file"; |
| 276 | return kErrorInvalidCoreFile; |
| 277 | } |
| 278 | |
| 279 | if (e_ident[EI_MAG0] != ELFMAG0 || e_ident[EI_MAG1] != ELFMAG1 || |
| 280 | e_ident[EI_MAG2] != ELFMAG2 || e_ident[EI_MAG3] != ELFMAG3) { |
| 281 | LOG(ERROR) << "Invalid core file"; |
| 282 | return kErrorInvalidCoreFile; |
| 283 | } |
| 284 | |
| 285 | #if __WORDSIZE == 64 |
| 286 | // TODO(benchan, mkrebs): Remove this check once core2md can |
| 287 | // handles both 32-bit and 64-bit ELF on a 64-bit platform. |
| 288 | if (e_ident[EI_CLASS] == ELFCLASS32) { |
| 289 | LOG(ERROR) << "Conversion of 32-bit core file on 64-bit platform is " |
| 290 | << "currently not supported"; |
| 291 | return kErrorUnsupported32BitCoreFile; |
| 292 | } |
| 293 | #endif |
| 294 | |
| 295 | return kErrorNone; |
| 296 | } |
| 297 | |
Michael Krebs | 1c57e9e | 2012-09-25 18:03:13 -0700 | [diff] [blame] | 298 | bool UserCollector::GetCreatedCrashDirectory(pid_t pid, uid_t supplied_ruid, |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 299 | FilePath *crash_file_path, |
| 300 | bool *out_of_capacity) { |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 301 | FilePath process_path = GetProcessPath(pid); |
| 302 | std::string status; |
Steve Fung | d6169a2 | 2014-08-11 15:52:23 -0700 | [diff] [blame] | 303 | if (directory_failure_) { |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 304 | LOG(ERROR) << "Purposefully failing to create spool directory"; |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 305 | return false; |
| 306 | } |
Michael Krebs | 1c57e9e | 2012-09-25 18:03:13 -0700 | [diff] [blame] | 307 | |
| 308 | uid_t uid; |
Mike Frysinger | a557c11 | 2014-02-05 22:55:39 -0500 | [diff] [blame] | 309 | if (base::ReadFileToString(process_path.Append("status"), &status)) { |
Michael Krebs | 1c57e9e | 2012-09-25 18:03:13 -0700 | [diff] [blame] | 310 | std::vector<std::string> status_lines; |
| 311 | base::SplitString(status, '\n', &status_lines); |
| 312 | |
| 313 | std::string process_state; |
| 314 | if (!GetStateFromStatus(status_lines, &process_state)) { |
| 315 | LOG(ERROR) << "Could not find process state in status file"; |
| 316 | return false; |
| 317 | } |
| 318 | LOG(INFO) << "State of crashed process [" << pid << "]: " << process_state; |
| 319 | |
| 320 | // Get effective UID of crashing process. |
| 321 | int id; |
| 322 | if (!GetIdFromStatus(kUserId, kIdEffective, status_lines, &id)) { |
| 323 | LOG(ERROR) << "Could not find euid in status file"; |
| 324 | return false; |
| 325 | } |
| 326 | uid = id; |
| 327 | } else if (supplied_ruid != kUnknownUid) { |
| 328 | LOG(INFO) << "Using supplied UID " << supplied_ruid |
| 329 | << " for crashed process [" << pid |
| 330 | << "] due to error reading status file"; |
| 331 | uid = supplied_ruid; |
| 332 | } else { |
| 333 | LOG(ERROR) << "Could not read status file and kernel did not supply UID"; |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 334 | LOG(INFO) << "Path " << process_path.value() << " DirectoryExists: " |
Mike Frysinger | a557c11 | 2014-02-05 22:55:39 -0500 | [diff] [blame] | 335 | << base::DirectoryExists(process_path); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 336 | return false; |
| 337 | } |
Ben Chan | f13bb58 | 2012-01-06 08:22:07 -0800 | [diff] [blame] | 338 | |
Michael Krebs | 1c57e9e | 2012-09-25 18:03:13 -0700 | [diff] [blame] | 339 | if (!GetCreatedCrashDirectoryByEuid(uid, crash_file_path, out_of_capacity)) { |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 340 | LOG(ERROR) << "Could not create crash directory"; |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 341 | return false; |
| 342 | } |
| 343 | return true; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 344 | } |
| 345 | |
| 346 | bool UserCollector::CopyStdinToCoreFile(const FilePath &core_path) { |
| 347 | // Copy off all stdin to a core file. |
Steve Fung | ab2ac7d | 2015-08-14 17:58:05 -0700 | [diff] [blame] | 348 | FilePath stdin_path("/proc/self/fd/0"); |
Mike Frysinger | a557c11 | 2014-02-05 22:55:39 -0500 | [diff] [blame] | 349 | if (base::CopyFile(stdin_path, core_path)) { |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 350 | return true; |
| 351 | } |
| 352 | |
Chris Masone | b3fe6c3 | 2013-05-31 09:37:33 -0700 | [diff] [blame] | 353 | PLOG(ERROR) << "Could not write core file"; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 354 | // If the file system was full, make sure we remove any remnants. |
Mike Frysinger | a557c11 | 2014-02-05 22:55:39 -0500 | [diff] [blame] | 355 | base::DeleteFile(core_path, false); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 356 | return false; |
| 357 | } |
| 358 | |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 359 | bool UserCollector::RunCoreToMinidump(const FilePath &core_path, |
| 360 | const FilePath &procfs_directory, |
| 361 | const FilePath &minidump_path, |
| 362 | const FilePath &temp_directory) { |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 363 | FilePath output_path = temp_directory.Append("output"); |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 364 | chromeos::ProcessImpl core2md; |
| 365 | core2md.RedirectOutput(output_path.value()); |
| 366 | core2md.AddArg(kCoreToMinidumpConverterPath); |
| 367 | core2md.AddArg(core_path.value()); |
| 368 | core2md.AddArg(procfs_directory.value()); |
Ken Mixter | 2953c3a | 2010-10-18 14:42:20 -0700 | [diff] [blame] | 369 | |
Steve Fung | d6169a2 | 2014-08-11 15:52:23 -0700 | [diff] [blame] | 370 | if (!core2md_failure_) { |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 371 | core2md.AddArg(minidump_path.value()); |
| 372 | } else { |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 373 | // To test how core2md errors are propagaged, cause an error |
| 374 | // by forgetting a required argument. |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 377 | int errorlevel = core2md.Run(); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 378 | |
| 379 | std::string output; |
Mike Frysinger | a557c11 | 2014-02-05 22:55:39 -0500 | [diff] [blame] | 380 | base::ReadFileToString(output_path, &output); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 381 | if (errorlevel != 0) { |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 382 | LOG(ERROR) << "Problem during " << kCoreToMinidumpConverterPath |
| 383 | << " [result=" << errorlevel << "]: " << output; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 384 | return false; |
| 385 | } |
| 386 | |
Mike Frysinger | a557c11 | 2014-02-05 22:55:39 -0500 | [diff] [blame] | 387 | if (!base::PathExists(minidump_path)) { |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 388 | LOG(ERROR) << "Minidump file " << minidump_path.value() |
| 389 | << " was not created"; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 390 | return false; |
| 391 | } |
| 392 | return true; |
| 393 | } |
| 394 | |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 395 | UserCollector::ErrorType UserCollector::ConvertCoreToMinidump( |
| 396 | pid_t pid, |
| 397 | const FilePath &container_dir, |
| 398 | const FilePath &core_path, |
| 399 | const FilePath &minidump_path) { |
Ben Chan | ec7d783 | 2012-01-09 10:29:58 -0800 | [diff] [blame] | 400 | // If proc files are unuable, we continue to read the core file from stdin, |
| 401 | // but only skip the core-to-minidump conversion, so that we may still use |
| 402 | // the core file for debugging. |
| 403 | bool proc_files_usable = |
| 404 | CopyOffProcFiles(pid, container_dir) && ValidateProcFiles(container_dir); |
| 405 | |
| 406 | if (!CopyStdinToCoreFile(core_path)) { |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 407 | return kErrorReadCoreData; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 408 | } |
| 409 | |
Ben Chan | ec7d783 | 2012-01-09 10:29:58 -0800 | [diff] [blame] | 410 | if (!proc_files_usable) { |
| 411 | LOG(INFO) << "Skipped converting core file to minidump due to " |
| 412 | << "unusable proc files"; |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 413 | return kErrorUnusableProcFiles; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 414 | } |
| 415 | |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 416 | ErrorType error = ValidateCoreFile(core_path); |
| 417 | if (error != kErrorNone) { |
| 418 | return error; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 421 | if (!RunCoreToMinidump(core_path, |
| 422 | container_dir, // procfs directory |
| 423 | minidump_path, |
| 424 | container_dir)) { // temporary directory |
| 425 | return kErrorCore2MinidumpConversion; |
| 426 | } |
| 427 | |
| 428 | LOG(INFO) << "Stored minidump to " << minidump_path.value(); |
| 429 | return kErrorNone; |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 430 | } |
| 431 | |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 432 | UserCollector::ErrorType UserCollector::ConvertAndEnqueueCrash( |
Michael Krebs | 1c57e9e | 2012-09-25 18:03:13 -0700 | [diff] [blame] | 433 | pid_t pid, const std::string &exec, uid_t supplied_ruid, |
| 434 | bool *out_of_capacity) { |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 435 | FilePath crash_path; |
Michael Krebs | 1c57e9e | 2012-09-25 18:03:13 -0700 | [diff] [blame] | 436 | if (!GetCreatedCrashDirectory(pid, supplied_ruid, &crash_path, |
| 437 | out_of_capacity)) { |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 438 | LOG(ERROR) << "Unable to find/create process-specific crash path"; |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 439 | return kErrorSystemIssue; |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 440 | } |
| 441 | |
Ben Chan | 294d5d1 | 2012-01-04 20:40:15 -0800 | [diff] [blame] | 442 | // Directory like /tmp/crash_reporter/1234 which contains the |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 443 | // procfs entries and other temporary files used during conversion. |
Steve Fung | ab2ac7d | 2015-08-14 17:58:05 -0700 | [diff] [blame] | 444 | FilePath container_dir(StringPrintf("%s/%d", kCoreTempFolder, pid)); |
Ken Mixter | 1b8fe01 | 2011-01-25 13:33:05 -0800 | [diff] [blame] | 445 | // Delete a pre-existing directory from crash reporter that may have |
| 446 | // been left around for diagnostics from a failed conversion attempt. |
| 447 | // If we don't, existing files can cause forking to fail. |
Mike Frysinger | a557c11 | 2014-02-05 22:55:39 -0500 | [diff] [blame] | 448 | base::DeleteFile(container_dir, true); |
Ben Chan | 262d798 | 2014-09-18 08:05:20 -0700 | [diff] [blame] | 449 | std::string dump_basename = FormatDumpBasename(exec, time(nullptr), pid); |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 450 | FilePath core_path = GetCrashPath(crash_path, dump_basename, "core"); |
| 451 | FilePath meta_path = GetCrashPath(crash_path, dump_basename, "meta"); |
| 452 | FilePath minidump_path = GetCrashPath(crash_path, dump_basename, "dmp"); |
Ken Mixter | c49dbd4 | 2010-12-14 17:44:11 -0800 | [diff] [blame] | 453 | FilePath log_path = GetCrashPath(crash_path, dump_basename, "log"); |
| 454 | |
Simon Que | acc7938 | 2012-05-04 18:10:09 -0700 | [diff] [blame] | 455 | if (GetLogContents(FilePath(log_config_path_), exec, log_path)) |
Ken Mixter | c49dbd4 | 2010-12-14 17:44:11 -0800 | [diff] [blame] | 456 | AddCrashMetaData("log", log_path.value()); |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 457 | |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 458 | ErrorType error_type = |
| 459 | ConvertCoreToMinidump(pid, container_dir, core_path, minidump_path); |
| 460 | if (error_type != kErrorNone) { |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 461 | LOG(INFO) << "Leaving core file at " << core_path.value() |
| 462 | << " due to conversion error"; |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 463 | return error_type; |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | // Here we commit to sending this file. We must not return false |
| 467 | // after this point or we will generate a log report as well as a |
| 468 | // crash report. |
| 469 | WriteCrashMetaData(meta_path, |
| 470 | exec, |
| 471 | minidump_path.value()); |
| 472 | |
Michael Krebs | 538ecbf | 2011-07-27 14:13:22 -0700 | [diff] [blame] | 473 | if (!IsDeveloperImage()) { |
Mike Frysinger | a557c11 | 2014-02-05 22:55:39 -0500 | [diff] [blame] | 474 | base::DeleteFile(core_path, false); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 475 | } else { |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 476 | LOG(INFO) << "Leaving core file at " << core_path.value() |
| 477 | << " due to developer image"; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 478 | } |
| 479 | |
Mike Frysinger | a557c11 | 2014-02-05 22:55:39 -0500 | [diff] [blame] | 480 | base::DeleteFile(container_dir, true); |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 481 | return kErrorNone; |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Ken Mixter | 1b8fe01 | 2011-01-25 13:33:05 -0800 | [diff] [blame] | 484 | bool UserCollector::ParseCrashAttributes(const std::string &crash_attributes, |
Michael Krebs | 1c57e9e | 2012-09-25 18:03:13 -0700 | [diff] [blame] | 485 | pid_t *pid, int *signal, uid_t *uid, |
Ken Mixter | 1b8fe01 | 2011-01-25 13:33:05 -0800 | [diff] [blame] | 486 | std::string *kernel_supplied_name) { |
Michael Krebs | 1c57e9e | 2012-09-25 18:03:13 -0700 | [diff] [blame] | 487 | pcrecpp::RE re("(\\d+):(\\d+):(\\d+):(.*)"); |
| 488 | if (re.FullMatch(crash_attributes, pid, signal, uid, kernel_supplied_name)) |
| 489 | return true; |
| 490 | |
| 491 | LOG(INFO) << "Falling back to parsing crash attributes '" |
| 492 | << crash_attributes << "' without UID"; |
| 493 | pcrecpp::RE re_without_uid("(\\d+):(\\d+):(.*)"); |
| 494 | *uid = kUnknownUid; |
| 495 | return re_without_uid.FullMatch(crash_attributes, pid, signal, |
| 496 | kernel_supplied_name); |
Ken Mixter | 1b8fe01 | 2011-01-25 13:33:05 -0800 | [diff] [blame] | 497 | } |
| 498 | |
Ken Mixter | 5d3a1a2 | 2011-03-16 12:47:20 -0700 | [diff] [blame] | 499 | bool UserCollector::ShouldDump(bool has_owner_consent, |
| 500 | bool is_developer, |
Ken Mixter | 5d3a1a2 | 2011-03-16 12:47:20 -0700 | [diff] [blame] | 501 | std::string *reason) { |
| 502 | reason->clear(); |
| 503 | |
Ken Mixter | 5d3a1a2 | 2011-03-16 12:47:20 -0700 | [diff] [blame] | 504 | // For developer builds, we always want to keep the crash reports unless |
| 505 | // we're testing the crash facilities themselves. This overrides |
| 506 | // feedback. Crash sending still obeys consent. |
Michael Krebs | 538ecbf | 2011-07-27 14:13:22 -0700 | [diff] [blame] | 507 | if (is_developer) { |
Ken Mixter | 5d3a1a2 | 2011-03-16 12:47:20 -0700 | [diff] [blame] | 508 | *reason = "developer build - not testing - always dumping"; |
| 509 | return true; |
| 510 | } |
| 511 | |
| 512 | if (!has_owner_consent) { |
| 513 | *reason = "ignoring - no consent"; |
| 514 | return false; |
| 515 | } |
| 516 | |
| 517 | *reason = "handling"; |
| 518 | return true; |
| 519 | } |
| 520 | |
Ken Mixter | 1b8fe01 | 2011-01-25 13:33:05 -0800 | [diff] [blame] | 521 | bool UserCollector::HandleCrash(const std::string &crash_attributes, |
| 522 | const char *force_exec) { |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 523 | CHECK(initialized_); |
Michael Krebs | 1c57e9e | 2012-09-25 18:03:13 -0700 | [diff] [blame] | 524 | pid_t pid = 0; |
Ken Mixter | 1b8fe01 | 2011-01-25 13:33:05 -0800 | [diff] [blame] | 525 | int signal = 0; |
Michael Krebs | 1c57e9e | 2012-09-25 18:03:13 -0700 | [diff] [blame] | 526 | uid_t supplied_ruid = kUnknownUid; |
Ken Mixter | 1b8fe01 | 2011-01-25 13:33:05 -0800 | [diff] [blame] | 527 | std::string kernel_supplied_name; |
| 528 | |
Michael Krebs | 1c57e9e | 2012-09-25 18:03:13 -0700 | [diff] [blame] | 529 | if (!ParseCrashAttributes(crash_attributes, &pid, &signal, &supplied_ruid, |
Ken Mixter | 1b8fe01 | 2011-01-25 13:33:05 -0800 | [diff] [blame] | 530 | &kernel_supplied_name)) { |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 531 | LOG(ERROR) << "Invalid parameter: --user=" << crash_attributes; |
Ken Mixter | 1b8fe01 | 2011-01-25 13:33:05 -0800 | [diff] [blame] | 532 | return false; |
| 533 | } |
| 534 | |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 535 | std::string exec; |
| 536 | if (force_exec) { |
| 537 | exec.assign(force_exec); |
| 538 | } else if (!GetExecutableBaseNameFromPid(pid, &exec)) { |
Ken Mixter | 1b8fe01 | 2011-01-25 13:33:05 -0800 | [diff] [blame] | 539 | // If we cannot find the exec name, use the kernel supplied name. |
| 540 | // We don't always use the kernel's since it truncates the name to |
| 541 | // 16 characters. |
| 542 | exec = StringPrintf("supplied_%s", kernel_supplied_name.c_str()); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 543 | } |
Ken Mixter | c6a58e0 | 2010-11-01 18:05:30 -0700 | [diff] [blame] | 544 | |
| 545 | // Allow us to test the crash reporting mechanism successfully even if |
| 546 | // other parts of the system crash. |
Steve Fung | d6169a2 | 2014-08-11 15:52:23 -0700 | [diff] [blame] | 547 | if (!filter_in_.empty() && |
| 548 | (filter_in_ == "none" || |
| 549 | filter_in_ != exec)) { |
Ken Mixter | c6a58e0 | 2010-11-01 18:05:30 -0700 | [diff] [blame] | 550 | // We use a different format message to make it more obvious in tests |
| 551 | // which crashes are test generated and which are real. |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 552 | LOG(WARNING) << "Ignoring crash from " << exec << "[" << pid << "] while " |
Steve Fung | d6169a2 | 2014-08-11 15:52:23 -0700 | [diff] [blame] | 553 | << "filter_in=" << filter_in_ << "."; |
Ken Mixter | c6a58e0 | 2010-11-01 18:05:30 -0700 | [diff] [blame] | 554 | return true; |
| 555 | } |
| 556 | |
Ken Mixter | 5d3a1a2 | 2011-03-16 12:47:20 -0700 | [diff] [blame] | 557 | std::string reason; |
| 558 | bool dump = ShouldDump(is_feedback_allowed_function_(), |
Michael Krebs | 538ecbf | 2011-07-27 14:13:22 -0700 | [diff] [blame] | 559 | IsDeveloperImage(), |
Ken Mixter | 5d3a1a2 | 2011-03-16 12:47:20 -0700 | [diff] [blame] | 560 | &reason); |
Ken Mixter | 2105b49 | 2010-11-09 16:14:38 -0800 | [diff] [blame] | 561 | |
Ken Mixter | a324932 | 2011-03-03 08:47:38 -0800 | [diff] [blame] | 562 | LOG(WARNING) << "Received crash notification for " << exec << "[" << pid |
Michael Krebs | 1c57e9e | 2012-09-25 18:03:13 -0700 | [diff] [blame] | 563 | << "] sig " << signal << ", user " << supplied_ruid |
| 564 | << " (" << reason << ")"; |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 565 | |
Ken Mixter | 5d3a1a2 | 2011-03-16 12:47:20 -0700 | [diff] [blame] | 566 | if (dump) { |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 567 | count_crash_function_(); |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 568 | |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 569 | if (generate_diagnostics_) { |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 570 | bool out_of_capacity = false; |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 571 | ErrorType error_type = |
Michael Krebs | 1c57e9e | 2012-09-25 18:03:13 -0700 | [diff] [blame] | 572 | ConvertAndEnqueueCrash(pid, exec, supplied_ruid, &out_of_capacity); |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 573 | if (error_type != kErrorNone) { |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 574 | if (!out_of_capacity) |
Ben Chan | 6e709a1 | 2012-02-29 12:10:44 -0800 | [diff] [blame] | 575 | EnqueueCollectionErrorLog(pid, error_type, exec); |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 576 | return false; |
| 577 | } |
Ken Mixter | 0340316 | 2010-08-18 15:23:16 -0700 | [diff] [blame] | 578 | } |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 579 | } |
Ken Mixter | 207694d | 2010-10-28 15:42:37 -0700 | [diff] [blame] | 580 | |
Ken Mixter | 777484c | 2010-07-23 16:22:44 -0700 | [diff] [blame] | 581 | return true; |
Chris Sosa | e4a8603 | 2010-06-16 17:08:34 -0700 | [diff] [blame] | 582 | } |