blob: 753a26b38863ef9f1e9a1fe1e698c53aa06dcc4b [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
George Liu858fbb22021-07-01 12:25:44 +08005#include <fmt/core.h>
6
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05007#include <phosphor-logging/log.hpp>
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05008#include <sdbusplus/exception.hpp>
Jayanth Othayothd02153c2017-07-02 22:29:42 -05009
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050010#include <filesystem>
11#include <regex>
12
Jayanth Othayothd02153c2017-07-02 22:29:42 -050013namespace phosphor
14{
15namespace dump
16{
17namespace core
18{
Jayanth Othayothd02153c2017-07-02 22:29:42 -050019
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050020using namespace phosphor::logging;
21using namespace std;
22
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050023void Manager::watchCallback(const UserMap& fileInfo)
Jayanth Othayothd02153c2017-07-02 22:29:42 -050024{
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050025 vector<string> files;
26
Jayanth Othayothd02153c2017-07-02 22:29:42 -050027 for (const auto& i : fileInfo)
28 {
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050029 std::filesystem::path file(i.first);
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050030 std::string name = file.filename();
31
32 /*
33 As per coredump source code systemd-coredump uses below format
34 https://github.com/systemd/systemd/blob/master/src/coredump/coredump.c
35 /var/lib/systemd/coredump/core.%s.%s." SD_ID128_FORMAT_STR “
36 systemd-coredump also creates temporary file in core file path prior
37 to actual core file creation. Checking the file name format will help
38 to limit dump creation only for the new core files.
39 */
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050040 if ("core" == name.substr(0, name.find('.')))
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050041 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050042 // Consider only file name start with "core."
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050043 files.push_back(file);
Jayanth Othayothd02153c2017-07-02 22:29:42 -050044 }
45 }
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050046
47 if (!files.empty())
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050048 {
49 createHelper(files);
50 }
51}
52
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050053void Manager::createHelper(const vector<string>& files)
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050054{
55 constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
56 constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
57 constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
58 constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Dump.Internal.Create");
59 constexpr auto APPLICATION_CORED =
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050060 "xyz.openbmc_project.Dump.Internal.Create.Type.ApplicationCored";
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050061
62 auto b = sdbusplus::bus::new_default();
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050063 auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
64 MAPPER_INTERFACE, "GetObject");
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050065 mapper.append(OBJ_INTERNAL, vector<string>({IFACE_INTERNAL}));
66
67 auto mapperResponseMsg = b.call(mapper);
68 if (mapperResponseMsg.is_method_error())
69 {
70 log<level::ERR>("Error in mapper call");
71 return;
72 }
73
74 map<string, vector<string>> mapperResponse;
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070075 try
76 {
77 mapperResponseMsg.read(mapperResponse);
78 }
79 catch (const sdbusplus::exception::SdBusError& e)
80 {
George Liu858fbb22021-07-01 12:25:44 +080081 log<level::ERR>(fmt::format("Failed to parse dump create message, "
82 "errormsg({}), REPLY_SIG({})",
83 e.what(), mapperResponseMsg.get_signature())
84 .c_str());
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070085 return;
86 }
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050087 if (mapperResponse.empty())
88 {
89 log<level::ERR>("Error reading mapper response");
90 return;
91 }
92
93 const auto& host = mapperResponse.cbegin()->first;
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050094 auto m =
95 b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL, "Create");
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050096 m.append(APPLICATION_CORED, files);
97 b.call_noreply(m);
Jayanth Othayothd02153c2017-07-02 22:29:42 -050098}
99
Jayanth Othayothd02153c2017-07-02 22:29:42 -0500100} // namespace core
101} // namespace dump
102} // namespace phosphor