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_USER_COLLECTOR_H_ | 5 #ifndef _CRASH_REPORTER_USER_COLLECTOR_H_ |
6 #define _CRASH_REPORTER_USER_COLLECTOR_H_ | 6 #define _CRASH_REPORTER_USER_COLLECTOR_H_ |
7 | 7 |
8 #include <string> | 8 #include <string> |
| 9 #include <vector> |
9 | 10 |
10 #include "crash-reporter/crash_collector.h" | 11 #include "crash-reporter/crash_collector.h" |
11 #include "gtest/gtest_prod.h" // for FRIEND_TEST | 12 #include "gtest/gtest_prod.h" // for FRIEND_TEST |
12 | 13 |
13 class FilePath; | 14 class FilePath; |
14 class SystemLogging; | 15 class SystemLogging; |
15 | 16 |
16 // User crash collector. | 17 // User crash collector. |
17 class UserCollector : public CrashCollector { | 18 class UserCollector : public CrashCollector { |
18 public: | 19 public: |
(...skipping 25 matching lines...) Expand all Loading... |
44 // Set (override the default) core file pattern. | 45 // Set (override the default) core file pattern. |
45 void set_core_pattern_file(const std::string &pattern) { | 46 void set_core_pattern_file(const std::string &pattern) { |
46 core_pattern_file_ = pattern; | 47 core_pattern_file_ = pattern; |
47 } | 48 } |
48 | 49 |
49 private: | 50 private: |
50 friend class UserCollectorTest; | 51 friend class UserCollectorTest; |
51 FRIEND_TEST(UserCollectorTest, CopyOffProcFilesBadPath); | 52 FRIEND_TEST(UserCollectorTest, CopyOffProcFilesBadPath); |
52 FRIEND_TEST(UserCollectorTest, CopyOffProcFilesBadPid); | 53 FRIEND_TEST(UserCollectorTest, CopyOffProcFilesBadPid); |
53 FRIEND_TEST(UserCollectorTest, CopyOffProcFilesOK); | 54 FRIEND_TEST(UserCollectorTest, CopyOffProcFilesOK); |
| 55 FRIEND_TEST(UserCollectorTest, ForkExecAndPipe); |
54 FRIEND_TEST(UserCollectorTest, GetIdFromStatus); | 56 FRIEND_TEST(UserCollectorTest, GetIdFromStatus); |
55 FRIEND_TEST(UserCollectorTest, GetProcessPath); | 57 FRIEND_TEST(UserCollectorTest, GetProcessPath); |
56 FRIEND_TEST(UserCollectorTest, GetSymlinkTarget); | 58 FRIEND_TEST(UserCollectorTest, GetSymlinkTarget); |
57 FRIEND_TEST(UserCollectorTest, GetUserInfoFromName); | 59 FRIEND_TEST(UserCollectorTest, GetUserInfoFromName); |
58 | 60 |
59 // Enumeration to pass to GetIdFromStatus. Must match the order | 61 // Enumeration to pass to GetIdFromStatus. Must match the order |
60 // that the kernel lists IDs in the status file. | 62 // that the kernel lists IDs in the status file. |
61 enum IdKind { | 63 enum IdKind { |
62 kIdReal = 0, // uid and gid | 64 kIdReal = 0, // uid and gid |
63 kIdEffective = 1, // euid and egid | 65 kIdEffective = 1, // euid and egid |
64 kIdSet = 2, // suid and sgid | 66 kIdSet = 2, // suid and sgid |
65 kIdFileSystem = 3, // fsuid and fsgid | 67 kIdFileSystem = 3, // fsuid and fsgid |
66 kIdMax | 68 kIdMax |
67 }; | 69 }; |
68 | 70 |
| 71 static const int kForkProblem = 255; |
| 72 |
69 std::string GetPattern(bool enabled) const; | 73 std::string GetPattern(bool enabled) const; |
70 bool SetUpInternal(bool enabled); | 74 bool SetUpInternal(bool enabled); |
71 | 75 |
72 FilePath GetProcessPath(pid_t pid); | 76 FilePath GetProcessPath(pid_t pid); |
73 bool GetSymlinkTarget(const FilePath &symlink, | 77 bool GetSymlinkTarget(const FilePath &symlink, |
74 FilePath *target); | 78 FilePath *target); |
75 bool GetExecutableBaseNameFromPid(uid_t pid, | 79 bool GetExecutableBaseNameFromPid(uid_t pid, |
76 std::string *base_name); | 80 std::string *base_name); |
77 bool GetIdFromStatus(const char *prefix, | 81 bool GetIdFromStatus(const char *prefix, |
78 IdKind kind, | 82 IdKind kind, |
79 const std::string &status_contents, | 83 const std::string &status_contents, |
80 int *id); | 84 int *id); |
81 bool CopyOffProcFiles(pid_t pid, const FilePath &process_map); | 85 bool CopyOffProcFiles(pid_t pid, const FilePath &process_map); |
82 // Determines the crash directory for given pid based on pid's owner, | 86 // Determines the crash directory for given pid based on pid's owner, |
83 // and creates the directory if necessary with appropriate permissions. | 87 // and creates the directory if necessary with appropriate permissions. |
84 // Returns true whether or not directory needed to be created, false on | 88 // Returns true whether or not directory needed to be created, false on |
85 // any failure. | 89 // any failure. |
86 bool GetCreatedCrashDirectory(pid_t pid, | 90 bool GetCreatedCrashDirectory(pid_t pid, |
87 FilePath *crash_file_path); | 91 FilePath *crash_file_path); |
88 bool CopyStdinToCoreFile(const FilePath &core_path); | 92 bool CopyStdinToCoreFile(const FilePath &core_path); |
| 93 int ForkExecAndPipe(std::vector<const char *> &arguments, |
| 94 const char *output_file); |
89 bool ConvertCoreToMinidump(const FilePath &core_path, | 95 bool ConvertCoreToMinidump(const FilePath &core_path, |
90 const FilePath &procfs_directory, | 96 const FilePath &procfs_directory, |
91 const FilePath &minidump_path, | 97 const FilePath &minidump_path, |
92 const FilePath &temp_directory); | 98 const FilePath &temp_directory); |
93 bool GenerateDiagnostics(pid_t pid, const std::string &exec_name); | 99 bool GenerateDiagnostics(pid_t pid, const std::string &exec_name); |
94 | 100 |
95 bool generate_diagnostics_; | 101 bool generate_diagnostics_; |
96 std::string core_pattern_file_; | 102 std::string core_pattern_file_; |
97 std::string our_path_; | 103 std::string our_path_; |
98 bool initialized_; | 104 bool initialized_; |
99 | 105 |
100 static const char *kUserId; | 106 static const char *kUserId; |
101 static const char *kGroupId; | 107 static const char *kGroupId; |
102 }; | 108 }; |
103 | 109 |
104 #endif // _CRASH_REPORTER_USER_COLLECTOR_H_ | 110 #endif // _CRASH_REPORTER_USER_COLLECTOR_H_ |
OLD | NEW |