| 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/user_collector.h" | 5 #include "crash-reporter/user_collector.h" |
| 6 | 6 |
| 7 #include <grp.h> // For struct group. | 7 #include <grp.h> // For struct group. |
| 8 #include <pcrecpp.h> | 8 #include <pcrecpp.h> |
| 9 #include <pcrecpp.h> | 9 #include <pcrecpp.h> |
| 10 #include <pwd.h> // For struct passwd. | 10 #include <pwd.h> // For struct passwd. |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 408 return true; | 408 return true; |
| 409 } | 409 } |
| 410 | 410 |
| 411 bool UserCollector::ParseCrashAttributes(const std::string &crash_attributes, | 411 bool UserCollector::ParseCrashAttributes(const std::string &crash_attributes, |
| 412 pid_t *pid, int *signal, | 412 pid_t *pid, int *signal, |
| 413 std::string *kernel_supplied_name) { | 413 std::string *kernel_supplied_name) { |
| 414 pcrecpp::RE re("(\\d+):(\\d+):(.*)"); | 414 pcrecpp::RE re("(\\d+):(\\d+):(.*)"); |
| 415 return re.FullMatch(crash_attributes, pid, signal, kernel_supplied_name); | 415 return re.FullMatch(crash_attributes, pid, signal, kernel_supplied_name); |
| 416 } | 416 } |
| 417 | 417 |
| 418 bool UserCollector::ShouldDump(bool has_owner_consent, |
| 419 bool is_developer, |
| 420 bool is_crash_test_in_progress, |
| 421 const std::string &exec, |
| 422 std::string *reason) { |
| 423 reason->clear(); |
| 424 |
| 425 // Treat Chrome crashes as if the user opted-out. We stop counting Chrome |
| 426 // crashes towards user crashes, so user crashes really mean non-Chrome |
| 427 // user-space crashes. |
| 428 if (exec == "chrome" || exec == "supplied_chrome") { |
| 429 *reason = "ignoring - chrome crash"; |
| 430 return false; |
| 431 } |
| 432 |
| 433 // For developer builds, we always want to keep the crash reports unless |
| 434 // we're testing the crash facilities themselves. This overrides |
| 435 // feedback. Crash sending still obeys consent. |
| 436 if (is_developer && !is_crash_test_in_progress) { |
| 437 *reason = "developer build - not testing - always dumping"; |
| 438 return true; |
| 439 } |
| 440 |
| 441 if (!has_owner_consent) { |
| 442 *reason = "ignoring - no consent"; |
| 443 return false; |
| 444 } |
| 445 |
| 446 *reason = "handling"; |
| 447 return true; |
| 448 } |
| 449 |
| 418 bool UserCollector::HandleCrash(const std::string &crash_attributes, | 450 bool UserCollector::HandleCrash(const std::string &crash_attributes, |
| 419 const char *force_exec) { | 451 const char *force_exec) { |
| 420 CHECK(initialized_); | 452 CHECK(initialized_); |
| 421 int pid = 0; | 453 int pid = 0; |
| 422 int signal = 0; | 454 int signal = 0; |
| 423 std::string kernel_supplied_name; | 455 std::string kernel_supplied_name; |
| 424 | 456 |
| 425 if (!ParseCrashAttributes(crash_attributes, &pid, &signal, | 457 if (!ParseCrashAttributes(crash_attributes, &pid, &signal, |
| 426 &kernel_supplied_name)) { | 458 &kernel_supplied_name)) { |
| 427 LOG(ERROR) << "Invalid parameter: --user=" << crash_attributes; | 459 LOG(ERROR) << "Invalid parameter: --user=" << crash_attributes; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 443 if (!FLAGS_filter_in.empty() && | 475 if (!FLAGS_filter_in.empty() && |
| 444 (FLAGS_filter_in == "none" || | 476 (FLAGS_filter_in == "none" || |
| 445 FLAGS_filter_in != exec)) { | 477 FLAGS_filter_in != exec)) { |
| 446 // We use a different format message to make it more obvious in tests | 478 // We use a different format message to make it more obvious in tests |
| 447 // which crashes are test generated and which are real. | 479 // which crashes are test generated and which are real. |
| 448 LOG(WARNING) << "Ignoring crash from " << exec << "[" << pid << "] while " | 480 LOG(WARNING) << "Ignoring crash from " << exec << "[" << pid << "] while " |
| 449 << "filter_in=" << FLAGS_filter_in << "."; | 481 << "filter_in=" << FLAGS_filter_in << "."; |
| 450 return true; | 482 return true; |
| 451 } | 483 } |
| 452 | 484 |
| 453 bool feedback = is_feedback_allowed_function_(); | 485 std::string reason; |
| 454 const char *handling_string = "handling"; | 486 bool dump = ShouldDump(is_feedback_allowed_function_(), |
| 455 if (!feedback) { | 487 file_util::PathExists(FilePath(kLeaveCoreFile)), |
| 456 handling_string = "ignoring - no consent"; | 488 IsCrashTestInProgress(), |
| 457 } | 489 exec, |
| 458 | 490 &reason); |
| 459 // Treat Chrome crashes as if the user opted-out. We stop counting Chrome | |
| 460 // crashes towards user crashes, so user crashes really mean non-Chrome | |
| 461 // user-space crashes. | |
| 462 if (exec == "chrome" || exec == "supplied_chrome") { | |
| 463 feedback = false; | |
| 464 handling_string = "ignoring - chrome crash"; | |
| 465 } | |
| 466 | 491 |
| 467 LOG(WARNING) << "Received crash notification for " << exec << "[" << pid | 492 LOG(WARNING) << "Received crash notification for " << exec << "[" << pid |
| 468 << "] sig " << signal << " (" << handling_string << ")"; | 493 << "] sig " << signal << " (" << reason << ")"; |
| 469 | 494 |
| 470 // For developer builds, we always want to keep the crash reports unless | 495 if (dump) { |
| 471 // we're testing the crash facilities themselves. | |
| 472 if (file_util::PathExists(FilePath(kLeaveCoreFile)) && | |
| 473 !IsCrashTestInProgress()) { | |
| 474 feedback = true; | |
| 475 } | |
| 476 | |
| 477 if (feedback) { | |
| 478 count_crash_function_(); | 496 count_crash_function_(); |
| 479 | 497 |
| 480 if (generate_diagnostics_) { | 498 if (generate_diagnostics_) { |
| 481 bool out_of_capacity = false; | 499 bool out_of_capacity = false; |
| 482 bool convert_and_enqueue_result = | 500 bool convert_and_enqueue_result = |
| 483 ConvertAndEnqueueCrash(pid, exec, &out_of_capacity); | 501 ConvertAndEnqueueCrash(pid, exec, &out_of_capacity); |
| 484 if (!convert_and_enqueue_result) { | 502 if (!convert_and_enqueue_result) { |
| 485 if (!out_of_capacity) | 503 if (!out_of_capacity) |
| 486 EnqueueCollectionErrorLog(pid, exec); | 504 EnqueueCollectionErrorLog(pid, exec); |
| 487 return false; | 505 return false; |
| 488 } | 506 } |
| 489 } | 507 } |
| 490 } | 508 } |
| 491 | 509 |
| 492 return true; | 510 return true; |
| 493 } | 511 } |
| OLD | NEW |