Update V8 to version 4.7.24.
[chromium-blink-merge.git] / chromecast / crash / linux / minidump_writer.cc
blobcb79147dcccaf835f68e5464868c6a8a39a537a4
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"
7 #include "base/bind.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 {
17 namespace {
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());
25 argv.push_back("-w");
26 argv.push_back("crash-request");
27 argv.push_back("-z");
28 argv.push_back("-o");
29 argv.push_back(
30 minidump_name); // dumpstate appends ".txt.gz" to the filename.
32 std::string log;
33 if (!chromecast::GetAppOutput(argv, &log)) {
34 LOG(ERROR) << "failed to execute dumpstate";
35 return -1;
37 return 0;
40 } // namespace
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),
48 params_(params),
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,
56 minidump_filename,
57 params,
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();
73 return -1;
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();
79 return -1;
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.";
86 return -1;
89 // Add this entry to the lockfile.
90 const DumpInfo info(minidump_path_.value(),
91 minidump_path_.value() + kDumpStateSuffix,
92 time(nullptr),
93 params_);
94 if (AddEntryToLockFile(info) < 0) {
95 LOG(ERROR) << "lockfile logging failed";
96 return -1;
99 return 0;
102 } // namespace crash_manager