aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteve Fung <stevefung@google.com>2015-09-01 14:04:48 -0700
committerSteve Fung <stevefung@google.com>2015-09-02 12:29:22 -0700
commitd1da80572702c6c7311f7ac15a2d850fe7e0f676 (patch)
tree1f2f9c0ce4cdcf90c56f76d9bdc08d1a2f3aade4
parentb801ab98983522cb77f32982c7e73e3eafbda9f3 (diff)
downloadcrash_reporter-d1da80572702c6c7311f7ac15a2d850fe7e0f676.tar.gz
crash_reporter: Call dbus-send using chromeos::ProcessImpl
Convert the call to dbus-send from system() to chromeos::ProcessImpl so that the shell_exec selinux policy can be removed. Bug: 23280203 Change-Id: I692ebecf5b7f0611de252225cedabcdefd56dff8
-rw-r--r--crash_reporter.cc30
1 files changed, 18 insertions, 12 deletions
diff --git a/crash_reporter.cc b/crash_reporter.cc
index 23bd342..72eeeda 100644
--- a/crash_reporter.cc
+++ b/crash_reporter.cc
@@ -25,6 +25,7 @@
#include <base/strings/string_util.h>
#include <base/strings/stringprintf.h>
#include <chromeos/flag_helper.h>
+#include <chromeos/process.h>
#include <chromeos/syslog_logging.h>
#include <metrics/metrics_library.h>
@@ -85,27 +86,32 @@ static void CountUncleanShutdown() {
static void CountUserCrash() {
SendCrashMetrics(kCrashKindUser, "user");
- std::string command = StringPrintf(
- "/system/bin/dbus-send --type=signal --system / \"%s\" &",
- kUserCrashSignal);
// Announce through D-Bus whenever a user crash happens. This is
// used by the metrics daemon to log active use time between
// crashes.
//
- // This could be done more efficiently by explicit fork/exec or
- // using a dbus library directly. However, this should run
- // relatively rarely and longer term we may need to implement a
- // better way to do this that doesn't rely on D-Bus.
- //
- // We run in the background in case dbus daemon itself is crashed
+ // We run in the background in case dbus-daemon itself is crashed
// and not responding. This allows us to not block and potentially
// deadlock on a dbus-daemon crash. If dbus-daemon crashes without
// restarting, each crash will fork off a lot of dbus-send
// processes. Such a system is in a unusable state and will need
// to be restarted anyway.
-
- int status = system(command.c_str());
- LOG_IF(WARNING, status != 0) << "dbus-send running failed";
+ //
+ // Note: This will mean that the dbus-send process will become a zombie and
+ // reparent to init for reaping, but that's OK -- see above.
+
+ chromeos::ProcessImpl dbus_send;
+ dbus_send.AddArg("/system/bin/dbus-send");
+ dbus_send.AddArg("--type=signal");
+ dbus_send.AddArg("--system");
+ dbus_send.AddArg("/");
+ dbus_send.AddArg(kUserCrashSignal);
+ bool status = dbus_send.Start();
+ if (status) {
+ dbus_send.Release();
+ } else {
+ PLOG(WARNING) << "Sending UserCrash DBus signal failed";
+ }
}