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_USER_COLLECTOR_H_ | 5 #ifndef _CRASH_REPORTER_USER_COLLECTOR_H_ |
6 #define _CRASH_USER_COLLECTOR_H_ | 6 #define _CRASH_REPORTER_USER_COLLECTOR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "crash-reporter/system_logging.h" | 10 #include "crash-reporter/system_logging.h" |
| 11 #include "gtest/gtest_prod.h" // for FRIEND_TEST |
11 | 12 |
12 class FilePath; | 13 class FilePath; |
13 | 14 |
14 // User crash collector. | 15 // User crash collector. |
15 class UserCollector { | 16 class UserCollector { |
16 public: | 17 public: |
17 typedef void (*CountCrashFunction)(); | 18 typedef void (*CountCrashFunction)(); |
18 typedef bool (*IsFeedbackAllowedFunction)(); | 19 typedef bool (*IsFeedbackAllowedFunction)(); |
19 | 20 |
20 UserCollector(); | 21 UserCollector(); |
21 | 22 |
22 // Initialize the user crash collector for detection of crashes, | 23 // Initialize the user crash collector for detection of crashes, |
23 // given a crash counting function, the path to this executable, | 24 // given a crash counting function, the path to this executable, |
24 // metrics collection enabled oracle, and system logger facility. | 25 // metrics collection enabled oracle, and system logger facility. |
25 // Crash detection/reporting is not enabled until Enable is | 26 // Crash detection/reporting is not enabled until Enable is called. |
26 // called. | 27 // |generate_diagnostics| is used to indicate whether or not to try |
| 28 // to generate a minidump from crashes. |
27 void Initialize(CountCrashFunction count_crash, | 29 void Initialize(CountCrashFunction count_crash, |
28 const std::string &our_path, | 30 const std::string &our_path, |
29 IsFeedbackAllowedFunction is_metrics_allowed, | 31 IsFeedbackAllowedFunction is_metrics_allowed, |
30 SystemLogging *logger); | 32 SystemLogging *logger, |
| 33 bool generate_diagnostics); |
31 | 34 |
32 virtual ~UserCollector(); | 35 virtual ~UserCollector(); |
33 | 36 |
34 // Enable collection. | 37 // Enable collection. |
35 bool Enable() { return SetUpInternal(true); } | 38 bool Enable() { return SetUpInternal(true); } |
36 | 39 |
37 // Disable collection. | 40 // Disable collection. |
38 bool Disable() { return SetUpInternal(false); } | 41 bool Disable() { return SetUpInternal(false); } |
39 | 42 |
40 // Handle a specific user crash. | 43 // Handle a specific user crash. Returns true on success. |
41 void HandleCrash(int signal, int pid, const std::string &exec); | 44 bool HandleCrash(int signal, int pid, const char *force_exec); |
42 | 45 |
43 // Set (override the default) core file pattern. | 46 // Set (override the default) core file pattern. |
44 void set_core_pattern_file(const std::string &pattern) { | 47 void set_core_pattern_file(const std::string &pattern) { |
45 core_pattern_file_ = pattern; | 48 core_pattern_file_ = pattern; |
46 } | 49 } |
47 | 50 |
48 private: | 51 private: |
49 friend class UserCollectorTest; | 52 friend class UserCollectorTest; |
| 53 FRIEND_TEST(UserCollectorTest, CopyOffProcFilesBadPath); |
| 54 FRIEND_TEST(UserCollectorTest, CopyOffProcFilesBadPid); |
| 55 FRIEND_TEST(UserCollectorTest, CopyOffProcFilesOK); |
| 56 FRIEND_TEST(UserCollectorTest, FormatDumpBasename); |
| 57 FRIEND_TEST(UserCollectorTest, GetCrashDirectoryInfo); |
| 58 FRIEND_TEST(UserCollectorTest, GetIdFromStatus); |
| 59 FRIEND_TEST(UserCollectorTest, GetProcessPath); |
| 60 FRIEND_TEST(UserCollectorTest, GetSymlinkTarget); |
| 61 FRIEND_TEST(UserCollectorTest, GetUserInfoFromName); |
| 62 |
| 63 // Enumeration to pass to GetIdFromStatus. Must match the order |
| 64 // that the kernel lists IDs in the status file. |
| 65 enum IdKind { |
| 66 kIdReal = 0, // uid and gid |
| 67 kIdEffective = 1, // euid and egid |
| 68 kIdSet = 2, // suid and sgid |
| 69 kIdFileSystem = 3, // fsuid and fsgid |
| 70 kIdMax |
| 71 }; |
50 | 72 |
51 std::string GetPattern(bool enabled) const; | 73 std::string GetPattern(bool enabled) const; |
52 bool SetUpInternal(bool enabled); | 74 bool SetUpInternal(bool enabled); |
53 | 75 |
| 76 FilePath GetProcessPath(pid_t pid); |
| 77 bool GetSymlinkTarget(const FilePath &symlink, |
| 78 FilePath *target); |
| 79 bool GetExecutableBaseNameFromPid(uid_t pid, |
| 80 std::string *base_name); |
| 81 bool GetIdFromStatus(const char *prefix, |
| 82 IdKind kind, |
| 83 const std::string &status_contents, |
| 84 int *id); |
| 85 bool GetUserInfoFromName(const std::string &name, |
| 86 uid_t *uid, |
| 87 gid_t *gid); |
| 88 bool CopyOffProcFiles(pid_t pid, const FilePath &process_map); |
| 89 FilePath GetCrashDirectoryInfo(uid_t process_euid, |
| 90 uid_t default_user_id, |
| 91 gid_t default_user_group, |
| 92 mode_t *mode, |
| 93 uid_t *directory_owner, |
| 94 gid_t *directory_group); |
| 95 // Determines the crash directory for given pid based on pid's owner, |
| 96 // and creates the directory if necessary with appropriate permissions. |
| 97 // Returns true whether or not directory needed to be created, false on |
| 98 // any failure. |
| 99 bool GetCreatedCrashDirectory(pid_t pid, |
| 100 FilePath *crash_file_path); |
| 101 std::string FormatDumpBasename(const std::string &exec_name, |
| 102 time_t timestamp, |
| 103 pid_t pid); |
| 104 bool CopyStdinToCoreFile(const FilePath &core_path); |
| 105 bool ConvertCoreToMinidump(const FilePath &core_path, |
| 106 const FilePath &procfs_directory, |
| 107 const FilePath &minidump_path, |
| 108 const FilePath &temp_directory); |
| 109 bool GenerateDiagnostics(pid_t pid, const std::string &exec_name); |
| 110 |
| 111 bool generate_diagnostics_; |
54 std::string core_pattern_file_; | 112 std::string core_pattern_file_; |
55 CountCrashFunction count_crash_function_; | 113 CountCrashFunction count_crash_function_; |
56 std::string our_path_; | 114 std::string our_path_; |
57 bool initialized_; | 115 bool initialized_; |
58 IsFeedbackAllowedFunction is_feedback_allowed_function_; | 116 IsFeedbackAllowedFunction is_feedback_allowed_function_; |
59 SystemLogging *logger_; | 117 SystemLogging *logger_; |
| 118 |
| 119 static const char *kUserId; |
| 120 static const char *kGroupId; |
60 }; | 121 }; |
61 | 122 |
62 #endif // _CRASH_USER_COLLECTOR_H_ | 123 #endif // _CRASH_REPORTER_USER_COLLECTOR_H_ |
OLD | NEW |