| 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 #ifndef _CRASH_REPORTER_CRASH_COLLECTOR_H_ | 5 #ifndef _CRASH_REPORTER_CRASH_COLLECTOR_H_ |
| 6 #define _CRASH_REPORTER_CRASH_COLLECTOR_H_ | 6 #define _CRASH_REPORTER_CRASH_COLLECTOR_H_ |
| 7 | 7 |
| 8 #include <sys/stat.h> |
| 9 |
| 10 #include <map> |
| 8 #include <string> | 11 #include <string> |
| 9 #include <sys/stat.h> | |
| 10 | 12 |
| 11 #include "gtest/gtest_prod.h" // for FRIEND_TEST | 13 #include "gtest/gtest_prod.h" // for FRIEND_TEST |
| 12 | 14 |
| 13 class FilePath; | 15 class FilePath; |
| 14 class SystemLogging; | 16 class SystemLogging; |
| 15 | 17 |
| 16 // User crash collector. | 18 // User crash collector. |
| 17 class CrashCollector { | 19 class CrashCollector { |
| 18 public: | 20 public: |
| 19 typedef void (*CountCrashFunction)(); | 21 typedef void (*CountCrashFunction)(); |
| 20 typedef bool (*IsFeedbackAllowedFunction)(); | 22 typedef bool (*IsFeedbackAllowedFunction)(); |
| 21 | 23 |
| 22 CrashCollector(); | 24 CrashCollector(); |
| 23 | 25 |
| 24 virtual ~CrashCollector(); | 26 virtual ~CrashCollector(); |
| 25 | 27 |
| 26 // Initialize the crash collector for detection of crashes, given a | 28 // Initialize the crash collector for detection of crashes, given a |
| 27 // crash counting function, metrics collection enabled oracle, and | 29 // crash counting function, metrics collection enabled oracle, and |
| 28 // system logger facility. | 30 // system logger facility. |
| 29 void Initialize(CountCrashFunction count_crash, | 31 void Initialize(CountCrashFunction count_crash, |
| 30 IsFeedbackAllowedFunction is_metrics_allowed, | 32 IsFeedbackAllowedFunction is_metrics_allowed, |
| 31 SystemLogging *logger); | 33 SystemLogging *logger); |
| 32 | 34 |
| 33 protected: | 35 protected: |
| 34 friend class CrashCollectorTest; | 36 friend class CrashCollectorTest; |
| 35 FRIEND_TEST(CrashCollectorTest, CheckHasCapacityOverCore); | 37 FRIEND_TEST(CrashCollectorTest, CheckHasCapacityCorrectBasename); |
| 36 FRIEND_TEST(CrashCollectorTest, CheckHasCapacityOverNonCore); | 38 FRIEND_TEST(CrashCollectorTest, CheckHasCapacityStrangeNames); |
| 39 FRIEND_TEST(CrashCollectorTest, CheckHasCapacityUsual); |
| 37 FRIEND_TEST(CrashCollectorTest, GetCrashDirectoryInfo); | 40 FRIEND_TEST(CrashCollectorTest, GetCrashDirectoryInfo); |
| 38 FRIEND_TEST(CrashCollectorTest, FormatDumpBasename); | 41 FRIEND_TEST(CrashCollectorTest, FormatDumpBasename); |
| 39 FRIEND_TEST(CrashCollectorTest, Initialize); | 42 FRIEND_TEST(CrashCollectorTest, Initialize); |
| 43 FRIEND_TEST(CrashCollectorTest, ReadKeyValueFile); |
| 44 FRIEND_TEST(CrashCollectorTest, Sanitize); |
| 40 | 45 |
| 41 // Set maximum enqueued crashes in a crash directory. | 46 // Set maximum enqueued crashes in a crash directory. |
| 42 static const int kMaxCrashDirectorySize; | 47 static const int kMaxCrashDirectorySize; |
| 43 | 48 |
| 49 // Return a filename that has only [a-z0-1_] characters by mapping |
| 50 // all others into '_'. |
| 51 std::string Sanitize(const std::string &name); |
| 52 |
| 44 // For testing, set the directory always returned by | 53 // For testing, set the directory always returned by |
| 45 // GetCreatedCrashDirectoryByEuid. | 54 // GetCreatedCrashDirectoryByEuid. |
| 46 void ForceCrashDirectory(const char *forced_directory) { | 55 void ForceCrashDirectory(const char *forced_directory) { |
| 47 forced_crash_directory_ = forced_directory; | 56 forced_crash_directory_ = forced_directory; |
| 48 } | 57 } |
| 49 | 58 |
| 50 FilePath GetCrashDirectoryInfo(uid_t process_euid, | 59 FilePath GetCrashDirectoryInfo(uid_t process_euid, |
| 51 uid_t default_user_id, | 60 uid_t default_user_id, |
| 52 gid_t default_user_group, | 61 gid_t default_user_group, |
| 53 mode_t *mode, | 62 mode_t *mode, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 65 | 74 |
| 66 // Format crash name based on components. | 75 // Format crash name based on components. |
| 67 std::string FormatDumpBasename(const std::string &exec_name, | 76 std::string FormatDumpBasename(const std::string &exec_name, |
| 68 time_t timestamp, | 77 time_t timestamp, |
| 69 pid_t pid); | 78 pid_t pid); |
| 70 | 79 |
| 71 // Check given crash directory still has remaining capacity for another | 80 // Check given crash directory still has remaining capacity for another |
| 72 // crash. | 81 // crash. |
| 73 bool CheckHasCapacity(const FilePath &crash_directory); | 82 bool CheckHasCapacity(const FilePath &crash_directory); |
| 74 | 83 |
| 84 // Read the given file of form [<key><separator><value>\n...] and return |
| 85 // a map of its contents. |
| 86 bool ReadKeyValueFile(const FilePath &file, |
| 87 char separator, |
| 88 std::map<std::string, std::string> *dictionary); |
| 89 |
| 90 // Write a file of metadata about crash. |
| 91 void WriteCrashMetaData(const FilePath &meta_path, |
| 92 const std::string &exec_name); |
| 93 |
| 75 CountCrashFunction count_crash_function_; | 94 CountCrashFunction count_crash_function_; |
| 76 IsFeedbackAllowedFunction is_feedback_allowed_function_; | 95 IsFeedbackAllowedFunction is_feedback_allowed_function_; |
| 77 SystemLogging *logger_; | 96 SystemLogging *logger_; |
| 78 const char *forced_crash_directory_; | 97 const char *forced_crash_directory_; |
| 79 }; | 98 }; |
| 80 | 99 |
| 81 #endif // _CRASH_REPORTER_CRASH_COLLECTOR_H_ | 100 #endif // _CRASH_REPORTER_CRASH_COLLECTOR_H_ |
| OLD | NEW |