blob: 3ab726bcd53714c587ff0161e16ad58f6f7cd551 [file] [log] [blame]
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -05001#include <regex>
2#include <experimental/filesystem>
3
Jayanth Othayothd3273ea2017-07-12 22:55:32 -05004#include <phosphor-logging/log.hpp>
William A. Kennington III15cd3ce2018-05-15 11:34:44 -07005#include <sdbusplus/exception.hpp>
Jayanth Othayothd02153c2017-07-02 22:29:42 -05006
7#include "core_manager.hpp"
Jayanth Othayothd3273ea2017-07-12 22:55:32 -05008#include "config.h"
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 */
38 if("core" == name.substr(0, name.find('.')))
39 {
40 //Consider only file name start with "core."
41 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();
61 auto mapper = b.new_method_call(
62 MAPPER_BUSNAME,
63 MAPPER_PATH,
64 MAPPER_INTERFACE,
65 "GetObject");
66 mapper.append(OBJ_INTERNAL, vector<string>({IFACE_INTERNAL}));
67
68 auto mapperResponseMsg = b.call(mapper);
69 if (mapperResponseMsg.is_method_error())
70 {
71 log<level::ERR>("Error in mapper call");
72 return;
73 }
74
75 map<string, vector<string>> mapperResponse;
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070076 try
77 {
78 mapperResponseMsg.read(mapperResponse);
79 }
80 catch (const sdbusplus::exception::SdBusError& e)
81 {
82 log<level::ERR>("Failed to parse dump create message",
83 entry("ERROR=%s", e.what()),
84 entry("REPLY_SIG=%s", mapperResponseMsg.get_signature()));
85 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;
94 auto m = b.new_method_call(
95 host.c_str(),
96 OBJ_INTERNAL,
97 IFACE_INTERNAL,
98 "Create");
99 m.append(APPLICATION_CORED, files);
100 b.call_noreply(m);
Jayanth Othayothd02153c2017-07-02 22:29:42 -0500101}
102
Jayanth Othayothd02153c2017-07-02 22:29:42 -0500103} // namespace core
104} // namespace dump
105} // namespace phosphor