crash collector: compress udev crash logs
BUG=chrome-os-partner:6492
TEST=Run:
"crash_reporter --udev=ACTION=change:KERNEL=card0:SUBSYSTEM=drm"
Check that a card0-drm log.gz file has been created under /var/spool/crash
Check that the corresponding .meta file points to the log.gz file.
Change-Id: Id1ecc82b9fac118f8bf1e5edc40c3a2f61abd4c4
Signed-off-by: Simon Que <sque@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/21495
Reviewed-by: Ben Chan <benchan@chromium.org>
diff --git a/crash_reporter/crash_collector.cc b/crash_reporter/crash_collector.cc
index 8b80f37..aaee3cb 100644
--- a/crash_reporter/crash_collector.cc
+++ b/crash_reporter/crash_collector.cc
@@ -37,6 +37,7 @@
static const char kUdevExecName[] = "udev";
static const char kUdevSignatureKey[] = "sig";
static const char kUserCrashPath[] = "/home/chronos/user/crash";
+static const char kGzipPath[] = "/bin/gzip";
// Directory mode of the user crash spool directory.
static const mode_t kUserCrashPathMode = 0755;
@@ -122,6 +123,18 @@
return false;
}
+ // Compress the output using gzip.
+ chromeos::ProcessImpl gzip_process;
+ gzip_process.AddArg(kGzipPath);
+ gzip_process.AddArg(crash_path.value());
+ int process_result = gzip_process.Run();
+ FilePath crash_path_zipped = FilePath(crash_path.value() + ".gz");
+ // If the zip file was not created, use the uncompressed file.
+ if (process_result != 0 || !file_util::PathExists(crash_path_zipped))
+ LOG(ERROR) << "Could not create zip file " << crash_path_zipped.value();
+ else
+ crash_path = crash_path_zipped;
+
AddCrashMetaData(kUdevSignatureKey, kCollectUdevSignature);
WriteCrashMetaData(GetCrashPath(crash_directory, log_file_name, "meta"),
kUdevExecName, crash_path.value());
diff --git a/crash_reporter/crash_collector.h b/crash_reporter/crash_collector.h
index aa00416..77e2121 100644
--- a/crash_reporter/crash_collector.h
+++ b/crash_reporter/crash_collector.h
@@ -28,6 +28,7 @@
void Initialize(CountCrashFunction count_crash,
IsFeedbackAllowedFunction is_metrics_allowed);
+ // TODO(crosbug.com/30268): refactor into separate class.
bool HandleUdevCrash(const std::string &udev_event);
protected: