blob: dfa1aeb75e771f71c275d15636a2701cc7b08a2b [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>
Jayanth Othayothd02153c2017-07-02 22:29:42 -05005
6#include "core_manager.hpp"
Jayanth Othayothd3273ea2017-07-12 22:55:32 -05007#include "config.h"
Jayanth Othayothd02153c2017-07-02 22:29:42 -05008
9namespace phosphor
10{
11namespace dump
12{
13namespace core
14{
Jayanth Othayothd02153c2017-07-02 22:29:42 -050015
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050016using namespace phosphor::logging;
17using namespace std;
18
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050019void Manager::watchCallback(const UserMap& fileInfo)
Jayanth Othayothd02153c2017-07-02 22:29:42 -050020{
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050021 vector<string> files;
22
Jayanth Othayothd02153c2017-07-02 22:29:42 -050023 for (const auto& i : fileInfo)
24 {
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050025 namespace fs = std::experimental::filesystem;
26 fs::path file(i.first);
27 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 */
37 if("core" == name.substr(0, name.find('.')))
38 {
39 //Consider only file name start with "core."
40 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";
55 constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Dump.Internal.Create");
56 constexpr auto APPLICATION_CORED =
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050057 "xyz.openbmc_project.Dump.Internal.Create.Type.ApplicationCored";
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050058
59 auto b = sdbusplus::bus::new_default();
60 auto mapper = b.new_method_call(
61 MAPPER_BUSNAME,
62 MAPPER_PATH,
63 MAPPER_INTERFACE,
64 "GetObject");
65 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;
75 mapperResponseMsg.read(mapperResponse);
76 if (mapperResponse.empty())
77 {
78 log<level::ERR>("Error reading mapper response");
79 return;
80 }
81
82 const auto& host = mapperResponse.cbegin()->first;
83 auto m = b.new_method_call(
84 host.c_str(),
85 OBJ_INTERNAL,
86 IFACE_INTERNAL,
87 "Create");
88 m.append(APPLICATION_CORED, files);
89 b.call_noreply(m);
Jayanth Othayothd02153c2017-07-02 22:29:42 -050090}
91
Jayanth Othayothd02153c2017-07-02 22:29:42 -050092} // namespace core
93} // namespace dump
94} // namespace phosphor