blob: aa069a7d936005f193a033912206a06f975d72aa [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
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05005#include <phosphor-logging/log.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 phosphor::logging;
19using namespace std;
20
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050021void Manager::watchCallback(const UserMap& fileInfo)
Jayanth Othayothd02153c2017-07-02 22:29:42 -050022{
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050023 vector<string> files;
24
Jayanth Othayothd02153c2017-07-02 22:29:42 -050025 for (const auto& i : fileInfo)
26 {
Jayanth Othayoth3fc6df42021-04-08 03:45:24 -050027 std::filesystem::path file(i.first);
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050028 std::string name = file.filename();
29
30 /*
31 As per coredump source code systemd-coredump uses below format
32 https://github.com/systemd/systemd/blob/master/src/coredump/coredump.c
33 /var/lib/systemd/coredump/core.%s.%s." SD_ID128_FORMAT_STR “
34 systemd-coredump also creates temporary file in core file path prior
35 to actual core file creation. Checking the file name format will help
36 to limit dump creation only for the new core files.
37 */
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050038 if ("core" == name.substr(0, name.find('.')))
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050039 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050040 // Consider only file name start with "core."
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050041 files.push_back(file);
Jayanth Othayothd02153c2017-07-02 22:29:42 -050042 }
43 }
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050044
45 if (!files.empty())
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050046 {
47 createHelper(files);
48 }
49}
50
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050051void Manager::createHelper(const vector<string>& files)
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050052{
53 constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
54 constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
55 constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
56 constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Dump.Internal.Create");
57 constexpr auto APPLICATION_CORED =
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050058 "xyz.openbmc_project.Dump.Internal.Create.Type.ApplicationCored";
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050059
60 auto b = sdbusplus::bus::new_default();
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050061 auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
62 MAPPER_INTERFACE, "GetObject");
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050063 mapper.append(OBJ_INTERNAL, vector<string>({IFACE_INTERNAL}));
64
65 auto mapperResponseMsg = b.call(mapper);
66 if (mapperResponseMsg.is_method_error())
67 {
68 log<level::ERR>("Error in mapper call");
69 return;
70 }
71
72 map<string, vector<string>> mapperResponse;
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070073 try
74 {
75 mapperResponseMsg.read(mapperResponse);
76 }
77 catch (const sdbusplus::exception::SdBusError& e)
78 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050079 log<level::ERR>(
80 "Failed to parse dump create message", entry("ERROR=%s", e.what()),
81 entry("REPLY_SIG=%s", mapperResponseMsg.get_signature()));
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070082 return;
83 }
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050084 if (mapperResponse.empty())
85 {
86 log<level::ERR>("Error reading mapper response");
87 return;
88 }
89
90 const auto& host = mapperResponse.cbegin()->first;
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050091 auto m =
92 b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL, "Create");
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050093 m.append(APPLICATION_CORED, files);
94 b.call_noreply(m);
Jayanth Othayothd02153c2017-07-02 22:29:42 -050095}
96
Jayanth Othayothd02153c2017-07-02 22:29:42 -050097} // namespace core
98} // namespace dump
99} // namespace phosphor