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 #include "crash-reporter/crash_collector.h" | 5 #include "crash-reporter/crash_collector.h" |
6 | 6 |
7 #include <dirent.h> | 7 #include <dirent.h> |
8 #include <pwd.h> // For struct passwd. | 8 #include <pwd.h> // For struct passwd. |
9 #include <sys/types.h> // for mode_t. | 9 #include <sys/types.h> // for mode_t. |
10 | 10 |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 sanitized_exec_name.c_str(), | 79 sanitized_exec_name.c_str(), |
80 tm.tm_year + 1900, | 80 tm.tm_year + 1900, |
81 tm.tm_mon + 1, | 81 tm.tm_mon + 1, |
82 tm.tm_mday, | 82 tm.tm_mday, |
83 tm.tm_hour, | 83 tm.tm_hour, |
84 tm.tm_min, | 84 tm.tm_min, |
85 tm.tm_sec, | 85 tm.tm_sec, |
86 pid); | 86 pid); |
87 } | 87 } |
88 | 88 |
| 89 FilePath CrashCollector::GetCrashPath(const FilePath &crash_directory, |
| 90 const std::string &basename, |
| 91 const std::string &extension) { |
| 92 return crash_directory.Append(StringPrintf("%s.%s", |
| 93 basename.c_str(), |
| 94 extension.c_str())); |
| 95 } |
| 96 |
89 FilePath CrashCollector::GetCrashDirectoryInfo( | 97 FilePath CrashCollector::GetCrashDirectoryInfo( |
90 uid_t process_euid, | 98 uid_t process_euid, |
91 uid_t default_user_id, | 99 uid_t default_user_id, |
92 gid_t default_user_group, | 100 gid_t default_user_group, |
93 mode_t *mode, | 101 mode_t *mode, |
94 uid_t *directory_owner, | 102 uid_t *directory_owner, |
95 gid_t *directory_group) { | 103 gid_t *directory_group) { |
96 if (process_euid == default_user_id) { | 104 if (process_euid == default_user_id) { |
97 *mode = kUserCrashPathMode; | 105 *mode = kUserCrashPathMode; |
98 *directory_owner = default_user_id; | 106 *directory_owner = default_user_id; |
(...skipping 19 matching lines...) Expand all Loading... |
118 logger_->LogError("Cannot find user named %s", name.c_str()); | 126 logger_->LogError("Cannot find user named %s", name.c_str()); |
119 return false; | 127 return false; |
120 } | 128 } |
121 | 129 |
122 *uid = passwd_result->pw_uid; | 130 *uid = passwd_result->pw_uid; |
123 *gid = passwd_result->pw_gid; | 131 *gid = passwd_result->pw_gid; |
124 return true; | 132 return true; |
125 } | 133 } |
126 | 134 |
127 bool CrashCollector::GetCreatedCrashDirectoryByEuid(uid_t euid, | 135 bool CrashCollector::GetCreatedCrashDirectoryByEuid(uid_t euid, |
128 FilePath *crash_directory) { | 136 FilePath *crash_directory, |
| 137 bool *out_of_capacity) { |
129 uid_t default_user_id; | 138 uid_t default_user_id; |
130 gid_t default_user_group; | 139 gid_t default_user_group; |
131 | 140 |
| 141 if (out_of_capacity != NULL) *out_of_capacity = false; |
| 142 |
132 // For testing. | 143 // For testing. |
133 if (forced_crash_directory_ != NULL) { | 144 if (forced_crash_directory_ != NULL) { |
134 *crash_directory = FilePath(forced_crash_directory_); | 145 *crash_directory = FilePath(forced_crash_directory_); |
135 return true; | 146 return true; |
136 } | 147 } |
137 | 148 |
138 if (!GetUserInfoFromName(kDefaultUserName, | 149 if (!GetUserInfoFromName(kDefaultUserName, |
139 &default_user_id, | 150 &default_user_id, |
140 &default_user_group)) { | 151 &default_user_group)) { |
141 logger_->LogError("Could not find default user info"); | 152 logger_->LogError("Could not find default user info"); |
(...skipping 24 matching lines...) Expand all Loading... |
166 umask(old_mask); | 177 umask(old_mask); |
167 } | 178 } |
168 | 179 |
169 if (!file_util::PathExists(*crash_directory)) { | 180 if (!file_util::PathExists(*crash_directory)) { |
170 logger_->LogError("Unable to create crash directory %s", | 181 logger_->LogError("Unable to create crash directory %s", |
171 crash_directory->value().c_str()); | 182 crash_directory->value().c_str()); |
172 return false; | 183 return false; |
173 } | 184 } |
174 | 185 |
175 if (!CheckHasCapacity(*crash_directory)) { | 186 if (!CheckHasCapacity(*crash_directory)) { |
| 187 if (out_of_capacity != NULL) *out_of_capacity = true; |
176 return false; | 188 return false; |
177 } | 189 } |
178 | 190 |
179 return true; | 191 return true; |
180 } | 192 } |
181 | 193 |
182 // Return true if the given crash directory has not already reached | 194 // Return true if the given crash directory has not already reached |
183 // maximum capacity. | 195 // maximum capacity. |
184 bool CrashCollector::CheckHasCapacity(const FilePath &crash_directory) { | 196 bool CrashCollector::CheckHasCapacity(const FilePath &crash_directory) { |
185 DIR* dir = opendir(crash_directory.value().c_str()); | 197 DIR* dir = opendir(crash_directory.value().c_str()); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
264 } | 276 } |
265 std::string version("unknown"); | 277 std::string version("unknown"); |
266 std::map<std::string, std::string>::iterator i; | 278 std::map<std::string, std::string>::iterator i; |
267 if ((i = contents.find("CHROMEOS_RELEASE_VERSION")) != contents.end()) { | 279 if ((i = contents.find("CHROMEOS_RELEASE_VERSION")) != contents.end()) { |
268 version = i->second; | 280 version = i->second; |
269 } | 281 } |
270 int64 payload_size = -1; | 282 int64 payload_size = -1; |
271 file_util::GetFileSize(FilePath(payload_path), &payload_size); | 283 file_util::GetFileSize(FilePath(payload_path), &payload_size); |
272 std::string meta_data = StringPrintf("%sexec_name=%s\n" | 284 std::string meta_data = StringPrintf("%sexec_name=%s\n" |
273 "ver=%s\n" | 285 "ver=%s\n" |
| 286 "payload=%s\n" |
274 "payload_size=%lld\n" | 287 "payload_size=%lld\n" |
275 "done=1\n", | 288 "done=1\n", |
276 extra_metadata_.c_str(), | 289 extra_metadata_.c_str(), |
277 exec_name.c_str(), | 290 exec_name.c_str(), |
278 version.c_str(), | 291 version.c_str(), |
| 292 payload_path.c_str(), |
279 payload_size); | 293 payload_size); |
280 if (!file_util::WriteFile(meta_path, meta_data.c_str(), meta_data.size())) { | 294 if (!file_util::WriteFile(meta_path, meta_data.c_str(), meta_data.size())) { |
281 logger_->LogError("Unable to write %s", meta_path.value().c_str()); | 295 logger_->LogError("Unable to write %s", meta_path.value().c_str()); |
282 } | 296 } |
283 } | 297 } |
OLD | NEW |