Index: user_collector.cc |
diff --git a/user_collector.cc b/user_collector.cc |
index 59b460bdca6ae261cfa8bfe2890170a5fc91c2f5..939e7bd82fa7ad97512211b8eab7b0f1247f3a3c 100644 |
--- a/user_collector.cc |
+++ b/user_collector.cc |
@@ -68,7 +68,8 @@ UserCollector::~UserCollector() { |
std::string UserCollector::GetPattern(bool enabled) const { |
if (enabled) { |
- return StringPrintf("|%s --signal=%%s --pid=%%p", our_path_.c_str()); |
+ return StringPrintf("|%s --signal=%%s --pid=%%p --exec_name=%%e", |
+ our_path_.c_str()); |
} else { |
return "core"; |
} |
@@ -169,12 +170,6 @@ bool UserCollector::GetIdFromStatus(const char *prefix, |
return true; |
} |
-void UserCollector::LogCollectionError(const std::string &error_message) { |
- error_log_.append(error_message.c_str()); |
- error_log_.append("\n"); |
- logger_->LogError(error_message.c_str()); |
-} |
- |
void UserCollector::EnqueueCollectionErrorLog(pid_t pid, |
const std::string &exec) { |
FilePath crash_path; |
@@ -197,14 +192,13 @@ void UserCollector::EnqueueCollectionErrorLog(pid_t pid, |
bool UserCollector::CopyOffProcFiles(pid_t pid, |
const FilePath &container_dir) { |
if (!file_util::CreateDirectory(container_dir)) { |
- LogCollectionError(StringPrintf("Could not create %s", |
- container_dir.value().c_str())); |
+ logger_->LogError("Could not create %s", |
+ container_dir.value().c_str()); |
return false; |
} |
FilePath process_path = GetProcessPath(pid); |
if (!file_util::PathExists(process_path)) { |
- LogCollectionError(StringPrintf("Path %s does not exist", |
- process_path.value().c_str())); |
+ logger_->LogError("Path %s does not exist", process_path.value().c_str()); |
return false; |
} |
static const char *proc_files[] = { |
@@ -217,8 +211,7 @@ bool UserCollector::CopyOffProcFiles(pid_t pid, |
for (unsigned i = 0; i < arraysize(proc_files); ++i) { |
if (!file_util::CopyFile(process_path.Append(proc_files[i]), |
container_dir.Append(proc_files[i]))) { |
- LogCollectionError(StringPrintf("Could not copy %s file", |
- proc_files[i])); |
+ logger_->LogError("Could not copy %s file", proc_files[i]); |
return false; |
} |
} |
@@ -231,23 +224,26 @@ bool UserCollector::GetCreatedCrashDirectory(pid_t pid, |
FilePath process_path = GetProcessPath(pid); |
std::string status; |
if (FLAGS_directory_failure_test) { |
- LogCollectionError("Purposefully failing to create spool directory"); |
+ logger_->LogError("Purposefully failing to create spool directory"); |
return false; |
} |
if (!file_util::ReadFileToString(process_path.Append("status"), |
&status)) { |
- LogCollectionError("Could not read status file"); |
+ logger_->LogError("Could not read status file"); |
+ logger_->LogInfo("Path %s FileExists: %d", |
+ process_path.value().c_str(), |
+ file_util::DirectoryExists(process_path)); |
return false; |
} |
int process_euid; |
if (!GetIdFromStatus(kUserId, kIdEffective, status, &process_euid)) { |
- LogCollectionError("Could not find euid in status file"); |
+ logger_->LogError("Could not find euid in status file"); |
return false; |
} |
if (!GetCreatedCrashDirectoryByEuid(process_euid, |
crash_file_path, |
out_of_capacity)) { |
- LogCollectionError("Could not create crash directory"); |
+ logger_->LogError("Could not create crash directory"); |
return false; |
} |
return true; |
@@ -260,7 +256,7 @@ bool UserCollector::CopyStdinToCoreFile(const FilePath &core_path) { |
return true; |
} |
- LogCollectionError("Could not write core file"); |
+ logger_->LogError("Could not write core file"); |
// If the file system was full, make sure we remove any remnants. |
file_util::Delete(core_path, false); |
return false; |
@@ -283,22 +279,23 @@ bool UserCollector::RunCoreToMinidump(const FilePath &core_path, |
core2md_arguments.pop_back(); |
} |
+ std::string errors_during_fork; |
petkov
2011/01/18 19:18:20
unused?
kmixter1
2011/01/25 21:28:07
Done.
|
int errorlevel = ForkExecAndPipe(core2md_arguments, |
output_path.value().c_str()); |
std::string output; |
file_util::ReadFileToString(output_path, &output); |
if (errorlevel != 0) { |
- LogCollectionError(StringPrintf("Problem during %s [result=%d]: %s", |
- kCoreToMinidumpConverterPath, |
- errorlevel, |
- output.c_str())); |
+ logger_->LogError("Problem during %s [result=%d]: %s", |
+ kCoreToMinidumpConverterPath, |
+ errorlevel, |
+ output.c_str()); |
return false; |
} |
if (!file_util::PathExists(minidump_path)) { |
- LogCollectionError(StringPrintf("Minidump file %s was not created", |
- minidump_path.value().c_str())); |
+ logger_->LogError("Minidump file %s was not created", |
+ minidump_path.value().c_str()); |
return false; |
} |
return true; |
@@ -334,7 +331,7 @@ bool UserCollector::ConvertAndEnqueueCrash(int pid, |
bool *out_of_capacity) { |
FilePath crash_path; |
if (!GetCreatedCrashDirectory(pid, &crash_path, out_of_capacity)) { |
- LogCollectionError("Unable to find/create process-specific crash path"); |
+ logger_->LogError("Unable to find/create process-specific crash path"); |
return false; |
} |
@@ -376,15 +373,20 @@ bool UserCollector::ConvertAndEnqueueCrash(int pid, |
return true; |
} |
-bool UserCollector::HandleCrash(int signal, int pid, const char *force_exec) { |
+bool UserCollector::HandleCrash(int signal, int pid, |
+ const char *kernel_supplied_name, |
+ const char *force_exec) { |
CHECK(initialized_); |
std::string exec; |
if (force_exec) { |
exec.assign(force_exec); |
} else if (!GetExecutableBaseNameFromPid(pid, &exec)) { |
- // If for some reason we don't have the base name, avoid completely |
- // failing by indicating an unknown name. |
- exec = "unknown"; |
+ // If we cannot find the exec name, use the kernel supplied name. |
+ // We don't always use the kernel's since it truncates the name to |
+ // 16 characters. |
+ if (!kernel_supplied_name) |
+ kernel_supplied_name = "null"; |
+ exec = StringPrintf("supplied_%s", kernel_supplied_name); |
} |
// Allow us to test the crash reporting mechanism successfully even if |
@@ -421,7 +423,11 @@ bool UserCollector::HandleCrash(int signal, int pid, const char *force_exec) { |
if (generate_diagnostics_) { |
bool out_of_capacity = false; |
- if (!ConvertAndEnqueueCrash(pid, exec, &out_of_capacity)) { |
+ logger_->set_accumulator(&error_log_); |
+ bool convert_and_enqueue_result = |
+ ConvertAndEnqueueCrash(pid, exec, &out_of_capacity); |
+ logger_->set_accumulator(NULL); |
+ if (!convert_and_enqueue_result) { |
if (!out_of_capacity) |
EnqueueCollectionErrorLog(pid, exec); |
return false; |