1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "chromecast/crash/linux/minidump_writer.h"
8 #include "base/files/file_util.h"
9 #include "base/logging.h"
10 #include "chromecast/base/path_utils.h"
11 #include "chromecast/base/process_utils.h"
12 #include "chromecast/crash/linux/dump_info.h"
13 #include "chromecast/crash/linux/minidump_generator.h"
15 namespace chromecast
{
19 const char kDumpStateSuffix
[] = ".txt.gz";
21 // Fork and run dumpstate, saving results to minidump_name + ".txt.gz".
22 int DumpState(const std::string
& minidump_name
) {
23 std::vector
<std::string
> argv
;
24 argv
.push_back(GetBinPathASCII("dumpstate").value());
26 argv
.push_back("crash-request");
30 minidump_name
); // dumpstate appends ".txt.gz" to the filename.
33 if (!chromecast::GetAppOutput(argv
, &log
)) {
34 LOG(ERROR
) << "failed to execute dumpstate";
42 MinidumpWriter::MinidumpWriter(MinidumpGenerator
* minidump_generator
,
43 const std::string
& minidump_filename
,
44 const MinidumpParams
& params
,
45 const DumpStateCallback
& dump_state_cb
)
46 : minidump_generator_(minidump_generator
),
47 minidump_path_(minidump_filename
),
49 dump_state_cb_(dump_state_cb
) {
52 MinidumpWriter::MinidumpWriter(MinidumpGenerator
* minidump_generator
,
53 const std::string
& minidump_filename
,
54 const MinidumpParams
& params
)
55 : MinidumpWriter(minidump_generator
,
58 base::Bind(&DumpState
)) {
61 MinidumpWriter::~MinidumpWriter() {
64 int MinidumpWriter::DoWork() {
65 // If path is not absolute, append it to |dump_path_|.
66 if (!minidump_path_
.value().empty() && minidump_path_
.value()[0] != '/')
67 minidump_path_
= dump_path_
.Append(minidump_path_
);
69 // The path should be a file in the |dump_path_| directory.
70 if (dump_path_
!= minidump_path_
.DirName()) {
71 LOG(INFO
) << "The absolute path: " << minidump_path_
.value() << " is not"
72 << "in the correct directory: " << dump_path_
.value();
76 // Generate a minidump at the specified |minidump_path_|.
77 if (!minidump_generator_
->Generate(minidump_path_
.value())) {
78 LOG(ERROR
) << "Generate minidump failed " << minidump_path_
.value();
82 // Run the dumpstate callback.
83 DCHECK(!dump_state_cb_
.is_null());
84 if (dump_state_cb_
.Run(minidump_path_
.value()) < 0) {
85 LOG(ERROR
) << "DumpState callback failed.";
89 // Add this entry to the lockfile.
90 const DumpInfo
info(minidump_path_
.value(),
91 minidump_path_
.value() + kDumpStateSuffix
,
94 if (AddEntryToLockFile(info
) < 0) {
95 LOG(ERROR
) << "lockfile logging failed";
102 } // namespace crash_manager