blob: 176c0bdabf42634321b2faaf2d24fae2fbb099b1 [file] [log] [blame]
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05001#include "config.h"
Jayanth Othayothd02153c2017-07-02 22:29:42 -05002
3#include "core_manager.hpp"
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05004
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -05005#include <phosphor-logging/lg2.hpp>
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05006#include <sdbusplus/exception.hpp>
Jayanth Othayothd02153c2017-07-02 22:29:42 -05007
Jayanth Othayoth0af74a52021-04-08 03:55:21 -05008#include <filesystem>
9#include <regex>
10
Jayanth Othayothd02153c2017-07-02 22:29:42 -050011namespace phosphor
12{
13namespace dump
14{
15namespace core
16{
Jayanth Othayothd02153c2017-07-02 22:29:42 -050017
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050018using namespace std;
19
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050020void Manager::watchCallback(const UserMap& fileInfo)
Jayanth Othayothd02153c2017-07-02 22:29:42 -050021{
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050022 vector<string> files;
23
Jayanth Othayothd02153c2017-07-02 22:29:42 -050024 for (const auto& i : fileInfo)
25 {
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050026 std::filesystem::path file(i.first);
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050027 std::string name = file.filename();
28
29 /*
30 As per coredump source code systemd-coredump uses below format
31 https://github.com/systemd/systemd/blob/master/src/coredump/coredump.c
32 /var/lib/systemd/coredump/core.%s.%s." SD_ID128_FORMAT_STR “
33 systemd-coredump also creates temporary file in core file path prior
34 to actual core file creation. Checking the file name format will help
35 to limit dump creation only for the new core files.
36 */
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050037 if ("core" == name.substr(0, name.find('.')))
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050038 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050039 // Consider only file name start with "core."
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050040 files.push_back(file);
Jayanth Othayothd02153c2017-07-02 22:29:42 -050041 }
42 }
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050043
44 if (!files.empty())
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050045 {
46 createHelper(files);
47 }
48}
49
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050050void Manager::createHelper(const vector<string>& files)
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050051{
52 constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
53 constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
54 constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
Dhruvaraj Subhashchandran247159b2023-06-29 05:17:35 -050055 constexpr auto DUMP_CREATE_IFACE = "xyz.openbmc_project.Dump.Create";
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050056
57 auto b = sdbusplus::bus::new_default();
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050058 auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
59 MAPPER_INTERFACE, "GetObject");
Dhruvaraj Subhashchandran247159b2023-06-29 05:17:35 -050060 mapper.append(BMC_DUMP_OBJPATH, vector<string>({DUMP_CREATE_IFACE}));
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050061
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050062 map<string, vector<string>> mapperResponse;
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070063 try
64 {
Lei YU0eadeb72021-07-23 15:47:42 +080065 auto mapperResponseMsg = b.call(mapper);
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070066 mapperResponseMsg.read(mapperResponse);
67 }
Patrick Williams9b18bf22022-07-22 19:26:55 -050068 catch (const sdbusplus::exception_t& e)
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070069 {
Dhruvaraj Subhashchandran1615b822023-05-31 15:29:15 -050070 lg2::error("Failed to GetObject on Dump.Create: {ERROR}", "ERROR", e);
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070071 return;
72 }
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050073 if (mapperResponse.empty())
74 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050075 lg2::error("Error reading mapper response");
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050076 return;
77 }
78
79 const auto& host = mapperResponse.cbegin()->first;
Dhruvaraj Subhashchandran247159b2023-06-29 05:17:35 -050080 auto m = b.new_method_call(host.c_str(), BMC_DUMP_OBJPATH,
81 DUMP_CREATE_IFACE, "CreateDump");
82 phosphor::dump::DumpCreateParams params;
83 using CreateParameters =
84 sdbusplus::common::xyz::openbmc_project::dump::Create::CreateParameters;
85 using DumpType =
86 sdbusplus::common::xyz::openbmc_project::dump::Create::DumpType;
87 using DumpIntr = sdbusplus::common::xyz::openbmc_project::dump::Create;
88 params[DumpIntr::convertCreateParametersToString(
89 CreateParameters::DumpType)] =
90 DumpIntr::convertDumpTypeToString(DumpType::ApplicationCored);
91 params[DumpIntr::convertCreateParametersToString(
92 CreateParameters::FilePath)] = files.front();
93 m.append(params);
Lei YU0eadeb72021-07-23 15:47:42 +080094 try
95 {
96 b.call_noreply(m);
97 }
Patrick Williams9b18bf22022-07-22 19:26:55 -050098 catch (const sdbusplus::exception_t& e)
Lei YU0eadeb72021-07-23 15:47:42 +080099 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -0500100 lg2::error("Failed to create dump: {ERROR}", "ERROR", e);
Lei YU0eadeb72021-07-23 15:47:42 +0800101 }
Jayanth Othayothd02153c2017-07-02 22:29:42 -0500102}
103
Jayanth Othayothd02153c2017-07-02 22:29:42 -0500104} // namespace core
105} // namespace dump
106} // namespace phosphor