| 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 <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "crash-reporter/kernel_collector.h" | 10 #include "crash-reporter/kernel_collector.h" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 int status __attribute__((unused)) = system(command.c_str()); | 82 int status __attribute__((unused)) = system(command.c_str()); |
| 83 } | 83 } |
| 84 | 84 |
| 85 static int Initialize(KernelCollector *kernel_collector, | 85 static int Initialize(KernelCollector *kernel_collector, |
| 86 UserCollector *user_collector, | 86 UserCollector *user_collector, |
| 87 UncleanShutdownCollector *unclean_shutdown_collector) { | 87 UncleanShutdownCollector *unclean_shutdown_collector) { |
| 88 CHECK(!FLAGS_clean_shutdown) << "Incompatible options"; | 88 CHECK(!FLAGS_clean_shutdown) << "Incompatible options"; |
| 89 | 89 |
| 90 bool was_kernel_crash = false; | 90 bool was_kernel_crash = false; |
| 91 bool was_unclean_shutdown = false; | 91 bool was_unclean_shutdown = false; |
| 92 kernel_collector->Enable(); |
| 92 if (kernel_collector->IsEnabled()) { | 93 if (kernel_collector->IsEnabled()) { |
| 93 was_kernel_crash = kernel_collector->Collect(); | 94 was_kernel_crash = kernel_collector->Collect(); |
| 94 } | 95 } |
| 95 | 96 |
| 96 if (FLAGS_unclean_check) { | 97 if (FLAGS_unclean_check) { |
| 97 was_unclean_shutdown = unclean_shutdown_collector->Collect(); | 98 was_unclean_shutdown = unclean_shutdown_collector->Collect(); |
| 98 } | 99 } |
| 99 | 100 |
| 100 // Touch a file to notify the metrics daemon that a kernel | 101 // Touch a file to notify the metrics daemon that a kernel |
| 101 // crash has been detected so that it can log the time since | 102 // crash has been detected so that it can log the time since |
| 102 // the last kernel crash. | 103 // the last kernel crash. |
| 103 if (IsFeedbackAllowed()) { | 104 if (IsFeedbackAllowed()) { |
| 104 if (was_kernel_crash) { | 105 if (was_kernel_crash) { |
| 105 TouchFile(FilePath("/tmp/kernel-crash-detected")); | 106 TouchFile(FilePath("/tmp/kernel-crash-detected")); |
| 106 } else if (was_unclean_shutdown) { | 107 } else if (was_unclean_shutdown) { |
| 107 // We only count an unclean shutdown if it did not come with | 108 // We only count an unclean shutdown if it did not come with |
| 108 // an associated kernel crash. | 109 // an associated kernel crash. |
| 109 TouchFile(FilePath("/tmp/unclean-shutdown-detected")); | 110 TouchFile(FilePath("/tmp/unclean-shutdown-detected")); |
| 110 } | 111 } |
| 111 } | 112 } |
| 112 | 113 |
| 113 // Must enable the unclean shutdown collector *after* collecting. | 114 // Must enable the unclean shutdown collector *after* collecting. |
| 114 kernel_collector->Enable(); | |
| 115 unclean_shutdown_collector->Enable(); | 115 unclean_shutdown_collector->Enable(); |
| 116 user_collector->Enable(); | 116 user_collector->Enable(); |
| 117 | 117 |
| 118 return 0; | 118 return 0; |
| 119 } | 119 } |
| 120 | 120 |
| 121 static int HandleUserCrash(UserCollector *user_collector) { | 121 static int HandleUserCrash(UserCollector *user_collector) { |
| 122 // Handle a specific user space crash. | 122 // Handle a specific user space crash. |
| 123 CHECK(FLAGS_signal != -1) << "Signal must be set"; | 123 CHECK(FLAGS_signal != -1) << "Signal must be set"; |
| 124 CHECK(FLAGS_pid != -1) << "PID must be set"; | 124 CHECK(FLAGS_pid != -1) << "PID must be set"; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 } | 166 } |
| 167 | 167 |
| 168 if (FLAGS_clean_shutdown) { | 168 if (FLAGS_clean_shutdown) { |
| 169 unclean_shutdown_collector.Disable(); | 169 unclean_shutdown_collector.Disable(); |
| 170 user_collector.Disable(); | 170 user_collector.Disable(); |
| 171 return 0; | 171 return 0; |
| 172 } | 172 } |
| 173 | 173 |
| 174 return HandleUserCrash(&user_collector); | 174 return HandleUserCrash(&user_collector); |
| 175 } | 175 } |
| OLD | NEW |