From 6e68dd72c76bd314d8b35bb86bd2666bbc9bf092 Mon Sep 17 00:00:00 2001 From: Steve Fung Date: Tue, 1 Sep 2015 14:04:48 -0700 Subject: [PATCH] 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 --- crash_reporter/crash_reporter.cc | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/crash_reporter/crash_reporter.cc b/crash_reporter/crash_reporter.cc index 23bd3427e..72eeeda99 100644 --- a/crash_reporter/crash_reporter.cc +++ b/crash_reporter/crash_reporter.cc @@ -25,6 +25,7 @@ #include #include #include +#include #include #include @@ -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. + // + // 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. - int status = system(command.c_str()); - LOG_IF(WARNING, status != 0) << "dbus-send running failed"; + 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"; + } }