| 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/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 s_metrics_lib.SendEnumToUMA(std::string(kCrashCounterHistogram), | 60 s_metrics_lib.SendEnumToUMA(std::string(kCrashCounterHistogram), |
| 61 kCrashKindUncleanShutdown, | 61 kCrashKindUncleanShutdown, |
| 62 kCrashKindMax); | 62 kCrashKindMax); |
| 63 } | 63 } |
| 64 | 64 |
| 65 static void CountUserCrash() { | 65 static void CountUserCrash() { |
| 66 s_metrics_lib.SendEnumToUMA(std::string(kCrashCounterHistogram), | 66 s_metrics_lib.SendEnumToUMA(std::string(kCrashCounterHistogram), |
| 67 kCrashKindUser, | 67 kCrashKindUser, |
| 68 kCrashKindMax); | 68 kCrashKindMax); |
| 69 std::string command = StringPrintf( | 69 std::string command = StringPrintf( |
| 70 "/usr/bin/dbus-send --type=signal --system / \"%s\"", | 70 "/usr/bin/dbus-send --type=signal --system / \"%s\" &", |
| 71 kUserCrashSignal); | 71 kUserCrashSignal); |
| 72 // Announce through D-Bus whenever a user crash happens. This is | 72 // Announce through D-Bus whenever a user crash happens. This is |
| 73 // used by the metrics daemon to log active use time between | 73 // used by the metrics daemon to log active use time between |
| 74 // crashes. | 74 // crashes. |
| 75 // | 75 // |
| 76 // This could be done more efficiently by explicit fork/exec or | 76 // This could be done more efficiently by explicit fork/exec or |
| 77 // using a dbus library directly. However, this should run | 77 // using a dbus library directly. However, this should run |
| 78 // relatively rarely and longer term we may need to implement a | 78 // relatively rarely and longer term we may need to implement a |
| 79 // better way to do this that doesn't rely on D-Bus. | 79 // better way to do this that doesn't rely on D-Bus. |
| 80 // |
| 81 // We run in the background in case dbus daemon itself is crashed |
| 82 // and not responding. This allows us to not block and potentially |
| 83 // deadlock on a dbus-daemon crash. If dbus-daemon crashes without |
| 84 // restarting, each crash will fork off a lot of dbus-send |
| 85 // processes. Such a system is in a unusable state and will need |
| 86 // to be restarted anyway. |
| 80 | 87 |
| 81 int status __attribute__((unused)) = system(command.c_str()); | 88 int status = system(command.c_str()); |
| 89 if (status != 0) { |
| 90 s_system_log.LogWarning("dbus-send running failed"); |
| 91 } |
| 82 } | 92 } |
| 83 | 93 |
| 84 static int Initialize(KernelCollector *kernel_collector, | 94 static int Initialize(KernelCollector *kernel_collector, |
| 85 UserCollector *user_collector, | 95 UserCollector *user_collector, |
| 86 UncleanShutdownCollector *unclean_shutdown_collector) { | 96 UncleanShutdownCollector *unclean_shutdown_collector) { |
| 87 CHECK(!FLAGS_clean_shutdown) << "Incompatible options"; | 97 CHECK(!FLAGS_clean_shutdown) << "Incompatible options"; |
| 88 | 98 |
| 89 bool was_kernel_crash = false; | 99 bool was_kernel_crash = false; |
| 90 bool was_unclean_shutdown = false; | 100 bool was_unclean_shutdown = false; |
| 91 kernel_collector->Enable(); | 101 kernel_collector->Enable(); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 } | 180 } |
| 171 | 181 |
| 172 if (FLAGS_clean_shutdown) { | 182 if (FLAGS_clean_shutdown) { |
| 173 unclean_shutdown_collector.Disable(); | 183 unclean_shutdown_collector.Disable(); |
| 174 user_collector.Disable(); | 184 user_collector.Disable(); |
| 175 return 0; | 185 return 0; |
| 176 } | 186 } |
| 177 | 187 |
| 178 return HandleUserCrash(&user_collector); | 188 return HandleUserCrash(&user_collector); |
| 179 } | 189 } |
| OLD | NEW |