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

Side by Side Diff: crash_collector.cc

Issue 3209003: Limit the number of crash reports to enqueue at once (Closed) Base URL: http://git.chromium.org/git/crash-reporter.git
Patch Set: Respond to reviews Created 10 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « crash_collector.h ('k') | crash_collector_test.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 #include "crash-reporter/crash_collector.h" 5 #include "crash-reporter/crash_collector.h"
6 6
7 #include <dirent.h>
7 #include <pwd.h> // For struct passwd. 8 #include <pwd.h> // For struct passwd.
8 #include <sys/types.h> // for mode_t. 9 #include <sys/types.h> // for mode_t.
9 10
10 #include "base/file_util.h" 11 #include "base/file_util.h"
11 #include "base/logging.h" 12 #include "base/logging.h"
12 #include "base/string_util.h" 13 #include "base/string_util.h"
13 #include "crash-reporter/system_logging.h" 14 #include "crash-reporter/system_logging.h"
14 15
15 static const char kDefaultUserName[] = "chronos"; 16 static const char kDefaultUserName[] = "chronos";
16 static const char kSystemCrashPath[] = "/var/spool/crash"; 17 static const char kSystemCrashPath[] = "/var/spool/crash";
17 static const char kUserCrashPath[] = "/home/chronos/user/crash"; 18 static const char kUserCrashPath[] = "/home/chronos/user/crash";
18 19
19 // Directory mode of the user crash spool directory. 20 // Directory mode of the user crash spool directory.
20 static const mode_t kUserCrashPathMode = 0755; 21 static const mode_t kUserCrashPathMode = 0755;
21 22
22 // Directory mode of the system crash spool directory. 23 // Directory mode of the system crash spool directory.
23 static const mode_t kSystemCrashPathMode = 01755; 24 static const mode_t kSystemCrashPathMode = 01755;
24 25
25 static const uid_t kRootOwner = 0; 26 static const uid_t kRootOwner = 0;
26 static const uid_t kRootGroup = 0; 27 static const uid_t kRootGroup = 0;
27 28
29 // Maximum of 8 crash reports per directory.
30 const int CrashCollector::kMaxCrashDirectorySize = 8;
31
28 CrashCollector::CrashCollector() : forced_crash_directory_(NULL) { 32 CrashCollector::CrashCollector() : forced_crash_directory_(NULL) {
29 } 33 }
30 34
31 CrashCollector::~CrashCollector() { 35 CrashCollector::~CrashCollector() {
32 } 36 }
33 37
34 void CrashCollector::Initialize( 38 void CrashCollector::Initialize(
35 CrashCollector::CountCrashFunction count_crash_function, 39 CrashCollector::CountCrashFunction count_crash_function,
36 CrashCollector::IsFeedbackAllowedFunction is_feedback_allowed_function, 40 CrashCollector::IsFeedbackAllowedFunction is_feedback_allowed_function,
37 SystemLogging *logger) { 41 SystemLogging *logger) {
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 } 143 }
140 umask(old_mask); 144 umask(old_mask);
141 } 145 }
142 146
143 if (!file_util::PathExists(*crash_directory)) { 147 if (!file_util::PathExists(*crash_directory)) {
144 logger_->LogError("Unable to create crash directory %s", 148 logger_->LogError("Unable to create crash directory %s",
145 crash_directory->value().c_str()); 149 crash_directory->value().c_str());
146 return false; 150 return false;
147 } 151 }
148 152
153 if (!CheckHasCapacity(*crash_directory)) {
154 return false;
155 }
156
149 return true; 157 return true;
150 } 158 }
159
160 // Return true if the given crash directory has not already reached
161 // maximum capacity.
162 bool CrashCollector::CheckHasCapacity(const FilePath &crash_directory) {
163 DIR* dir = opendir(crash_directory.value().c_str());
164 if (!dir) {
165 return false;
166 }
167 struct dirent ent_buf;
168 struct dirent* ent;
169 int count_non_core = 0;
170 int count_core = 0;
171 bool full = false;
172 while (readdir_r(dir, &ent_buf, &ent) == 0 && ent != NULL) {
173 if ((strcmp(ent->d_name, ".") == 0) ||
174 (strcmp(ent->d_name, "..") == 0))
175 continue;
176
177 if (strcmp(ent->d_name + strlen(ent->d_name) - 5, ".core") == 0) {
178 ++count_core;
179 } else {
180 ++count_non_core;
181 }
182
183 if (count_core >= kMaxCrashDirectorySize ||
184 count_non_core >= kMaxCrashDirectorySize) {
185 logger_->LogWarning(
186 "Crash directory %s already full with %d pending reports",
187 crash_directory.value().c_str(),
188 kMaxCrashDirectorySize);
189 full = true;
190 break;
191 }
192 }
193 closedir(dir);
194 return !full;
195 }
OLDNEW
« no previous file with comments | « crash_collector.h ('k') | crash_collector_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698