Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(34)

Side by Side Diff: user_collector.h

Issue 3179006: Collect and send kernel crash diagnostics (Closed) Base URL: ssh://git@chromiumos-git//crash-reporter.git
Patch Set: Respond to reviews Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « unclean_shutdown_collector_test.cc ('k') | user_collector.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 9
10 #include "crash-reporter/system_logging.h" 10 #include "crash-reporter/crash_collector.h"
11 #include "gtest/gtest_prod.h" // for FRIEND_TEST 11 #include "gtest/gtest_prod.h" // for FRIEND_TEST
12 12
13 class FilePath; 13 class FilePath;
14 class SystemLogging;
14 15
15 // User crash collector. 16 // User crash collector.
16 class UserCollector { 17 class UserCollector : public CrashCollector {
17 public: 18 public:
18 typedef void (*CountCrashFunction)();
19 typedef bool (*IsFeedbackAllowedFunction)();
20
21 UserCollector(); 19 UserCollector();
22 20
23 // Initialize the user crash collector for detection of crashes, 21 // Initialize the user crash collector for detection of crashes,
24 // given a crash counting function, the path to this executable, 22 // given a crash counting function, the path to this executable,
25 // metrics collection enabled oracle, and system logger facility. 23 // metrics collection enabled oracle, and system logger facility.
26 // Crash detection/reporting is not enabled until Enable is called. 24 // Crash detection/reporting is not enabled until Enable is called.
27 // |generate_diagnostics| is used to indicate whether or not to try 25 // |generate_diagnostics| is used to indicate whether or not to try
28 // to generate a minidump from crashes. 26 // to generate a minidump from crashes.
29 void Initialize(CountCrashFunction count_crash, 27 void Initialize(CountCrashFunction count_crash,
30 const std::string &our_path, 28 const std::string &our_path,
(...skipping 15 matching lines...) Expand all
46 // Set (override the default) core file pattern. 44 // Set (override the default) core file pattern.
47 void set_core_pattern_file(const std::string &pattern) { 45 void set_core_pattern_file(const std::string &pattern) {
48 core_pattern_file_ = pattern; 46 core_pattern_file_ = pattern;
49 } 47 }
50 48
51 private: 49 private:
52 friend class UserCollectorTest; 50 friend class UserCollectorTest;
53 FRIEND_TEST(UserCollectorTest, CopyOffProcFilesBadPath); 51 FRIEND_TEST(UserCollectorTest, CopyOffProcFilesBadPath);
54 FRIEND_TEST(UserCollectorTest, CopyOffProcFilesBadPid); 52 FRIEND_TEST(UserCollectorTest, CopyOffProcFilesBadPid);
55 FRIEND_TEST(UserCollectorTest, CopyOffProcFilesOK); 53 FRIEND_TEST(UserCollectorTest, CopyOffProcFilesOK);
56 FRIEND_TEST(UserCollectorTest, FormatDumpBasename);
57 FRIEND_TEST(UserCollectorTest, GetCrashDirectoryInfo);
58 FRIEND_TEST(UserCollectorTest, GetIdFromStatus); 54 FRIEND_TEST(UserCollectorTest, GetIdFromStatus);
59 FRIEND_TEST(UserCollectorTest, GetProcessPath); 55 FRIEND_TEST(UserCollectorTest, GetProcessPath);
60 FRIEND_TEST(UserCollectorTest, GetSymlinkTarget); 56 FRIEND_TEST(UserCollectorTest, GetSymlinkTarget);
61 FRIEND_TEST(UserCollectorTest, GetUserInfoFromName); 57 FRIEND_TEST(UserCollectorTest, GetUserInfoFromName);
62 58
63 // Enumeration to pass to GetIdFromStatus. Must match the order 59 // Enumeration to pass to GetIdFromStatus. Must match the order
64 // that the kernel lists IDs in the status file. 60 // that the kernel lists IDs in the status file.
65 enum IdKind { 61 enum IdKind {
66 kIdReal = 0, // uid and gid 62 kIdReal = 0, // uid and gid
67 kIdEffective = 1, // euid and egid 63 kIdEffective = 1, // euid and egid
68 kIdSet = 2, // suid and sgid 64 kIdSet = 2, // suid and sgid
69 kIdFileSystem = 3, // fsuid and fsgid 65 kIdFileSystem = 3, // fsuid and fsgid
70 kIdMax 66 kIdMax
71 }; 67 };
72 68
73 std::string GetPattern(bool enabled) const; 69 std::string GetPattern(bool enabled) const;
74 bool SetUpInternal(bool enabled); 70 bool SetUpInternal(bool enabled);
75 71
76 FilePath GetProcessPath(pid_t pid); 72 FilePath GetProcessPath(pid_t pid);
77 bool GetSymlinkTarget(const FilePath &symlink, 73 bool GetSymlinkTarget(const FilePath &symlink,
78 FilePath *target); 74 FilePath *target);
79 bool GetExecutableBaseNameFromPid(uid_t pid, 75 bool GetExecutableBaseNameFromPid(uid_t pid,
80 std::string *base_name); 76 std::string *base_name);
81 bool GetIdFromStatus(const char *prefix, 77 bool GetIdFromStatus(const char *prefix,
82 IdKind kind, 78 IdKind kind,
83 const std::string &status_contents, 79 const std::string &status_contents,
84 int *id); 80 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); 81 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, 82 // Determines the crash directory for given pid based on pid's owner,
96 // and creates the directory if necessary with appropriate permissions. 83 // and creates the directory if necessary with appropriate permissions.
97 // Returns true whether or not directory needed to be created, false on 84 // Returns true whether or not directory needed to be created, false on
98 // any failure. 85 // any failure.
99 bool GetCreatedCrashDirectory(pid_t pid, 86 bool GetCreatedCrashDirectory(pid_t pid,
100 FilePath *crash_file_path); 87 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); 88 bool CopyStdinToCoreFile(const FilePath &core_path);
105 bool ConvertCoreToMinidump(const FilePath &core_path, 89 bool ConvertCoreToMinidump(const FilePath &core_path,
106 const FilePath &procfs_directory, 90 const FilePath &procfs_directory,
107 const FilePath &minidump_path, 91 const FilePath &minidump_path,
108 const FilePath &temp_directory); 92 const FilePath &temp_directory);
109 bool GenerateDiagnostics(pid_t pid, const std::string &exec_name); 93 bool GenerateDiagnostics(pid_t pid, const std::string &exec_name);
110 94
111 bool generate_diagnostics_; 95 bool generate_diagnostics_;
112 std::string core_pattern_file_; 96 std::string core_pattern_file_;
113 CountCrashFunction count_crash_function_;
114 std::string our_path_; 97 std::string our_path_;
115 bool initialized_; 98 bool initialized_;
116 IsFeedbackAllowedFunction is_feedback_allowed_function_;
117 SystemLogging *logger_;
118 99
119 static const char *kUserId; 100 static const char *kUserId;
120 static const char *kGroupId; 101 static const char *kGroupId;
121 }; 102 };
122 103
123 #endif // _CRASH_REPORTER_USER_COLLECTOR_H_ 104 #endif // _CRASH_REPORTER_USER_COLLECTOR_H_
OLDNEW
« no previous file with comments | « unclean_shutdown_collector_test.cc ('k') | user_collector.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698