summaryrefslogtreecommitdiffstatsabout
path: root/utility/logparse.c
diff options
context:
space:
mode:
Diffstat (limited to 'utility/logparse.c')
-rw-r--r--utility/logparse.c67
1 files changed, 61 insertions, 6 deletions
diff --git a/utility/logparse.c b/utility/logparse.c
index 097e66d..ec587a8 100644
--- a/utility/logparse.c
+++ b/utility/logparse.c
@@ -212,6 +212,56 @@ void parser_find_logs(config_t *cfg)
212 apr_pool_destroy(tp); 212 apr_pool_destroy(tp);
213} 213}
214 214
215apr_status_t parser_logbadline(config_t *cfg, const char *filename,
216 const char *badline)
217{
218 apr_status_t rv = APR_SUCCESS;
219 apr_size_t len;
220 struct iovec vec[5];
221
222 if (cfg->badlinefile) {
223 if (!cfg->badline_fp) {
224 rv = apr_file_open(&cfg->badline_fp, cfg->badlinefile,
225 APR_FOPEN_CREATE | APR_FOPEN_WRITE | APR_FOPEN_APPEND,
226 APR_OS_DEFAULT, cfg->pool);
227 if (rv) {
228 logging_log(cfg, LOGLEVEL_NOISE,
229 "Error opening badline file %s\n", cfg->badlinefile);
230 cfg->badlinefile = NULL;
231 } else {
232 char date[APR_RFC822_DATE_LEN];
233 vec[0].iov_base = "Starting BadLines for \"";
234 vec[0].iov_len = sizeof("Starting BadLines for \"")-1;
235 vec[1].iov_base = (void *)filename;
236 vec[1].iov_len = strlen(filename);
237 vec[2].iov_base = "\" on ";
238 vec[2].iov_len = sizeof("\" on ")-1;
239 apr_rfc822_date(date, apr_time_now());
240 vec[3].iov_base = date;
241 vec[3].iov_len = APR_RFC822_DATE_LEN-1;
242 vec[4].iov_base = "\n";
243 vec[4].iov_len = 1;
244 apr_file_writev(cfg->badline_fp, vec,5, &len);
245 }
246 }
247 if (!rv) {
248 if ((++cfg->badline_count) > cfg->badlinemax) {
249 logging_log(cfg, LOGLEVEL_NOISE,
250 "Found more than %d bad lines (found %d)",
251 cfg->badlinemax, cfg->badline_count);
252 rv = APR_EINVAL;
253 } else {
254 vec[0].iov_base = (void *)badline;
255 vec[0].iov_len = strlen(badline);
256 vec[1].iov_base = "\n";
257 vec[1].iov_len = 1;
258 apr_file_writev(cfg->badline_fp, vec,2, &len);
259 }
260 }
261 }
262 return rv;
263}
264
215/* 265/*
216 * Modified version of apr_tokenize_to_argv to add [] as quoting characters 266 * Modified version of apr_tokenize_to_argv to add [] as quoting characters
217 * 267 *
@@ -406,12 +456,17 @@ apr_status_t parser_parsefile(config_t *cfg, config_filestat_t *fstat)
406 rv = parser_processline(targp, cfg, fstat, targv, targc); 456 rv = parser_processline(targp, cfg, fstat, targv, targc);
407 if (rv != APR_SUCCESS) { 457 if (rv != APR_SUCCESS) {
408 int i; 458 int i;
409 if (!cfg->dryrun) database_trans_abort(cfg); 459
410 logging_log(cfg, LOGLEVEL_ERROR, "Line %d(%d): %s", fstat->linesparsed, 460 fstat->linesbad++;
411 targc, buff); 461 rv = parser_logbadline(cfg, fstat->fname, buff);
412 for (i = 0; targv[i]; i++) { 462 if (rv) {
413 logging_log(cfg, LOGLEVEL_ERROR, "Arg (%d): '%s'", i, 463 if (!cfg->dryrun) database_trans_abort(cfg);
414 targv[i]); 464 logging_log(cfg, LOGLEVEL_ERROR, "Line %d(%d): %s", fstat->linesparsed,
465 targc, buff);
466 for (i = 0; targv[i]; i++) {
467 logging_log(cfg, LOGLEVEL_ERROR, "Arg (%d): '%s'", i,
468 targv[i]);
469 }
415 } 470 }
416 } 471 }
417 } else { 472 } else {