blob: 19b80a2d8a083602c7fd309b0c24f1b3bd61e8cd [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
5#include <experimental/filesystem>
6#include <phosphor-logging/log.hpp>
7#include <regex>
8#include <sdbusplus/exception.hpp>
Jayanth Othayothd02153c2017-07-02 22:29:42 -05009
10namespace phosphor
11{
12namespace dump
13{
14namespace core
15{
Jayanth Othayothd02153c2017-07-02 22:29:42 -050016
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050017using namespace phosphor::logging;
18using 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 Othayoth9a56bfa2017-08-26 03:03:47 -050026 namespace fs = std::experimental::filesystem;
27 fs::path file(i.first);
28 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