blob: beddd891c66d451a68396eb9c6279896a5ebd8ee [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 Othayothd3273ea2017-07-12 22:55:32 -050025 // Get list of debug files.
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050026 if (IN_CLOSE_WRITE != i.second)
Jayanth Othayothd02153c2017-07-02 22:29:42 -050027 {
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050028 continue;
29 }
30
31 namespace fs = std::experimental::filesystem;
32 fs::path file(i.first);
33 std::string name = file.filename();
34
35 /*
36 As per coredump source code systemd-coredump uses below format
37 https://github.com/systemd/systemd/blob/master/src/coredump/coredump.c
38 /var/lib/systemd/coredump/core.%s.%s." SD_ID128_FORMAT_STR “
39 systemd-coredump also creates temporary file in core file path prior
40 to actual core file creation. Checking the file name format will help
41 to limit dump creation only for the new core files.
42 */
43 if("core" == name.substr(0, name.find('.')))
44 {
45 //Consider only file name start with "core."
46 files.push_back(file);
Jayanth Othayothd02153c2017-07-02 22:29:42 -050047 }
48 }
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050049
50 if (!files.empty())
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050051 {
52 createHelper(files);
53 }
54}
55
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050056void Manager::createHelper(const vector<string>& files)
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050057{
58 constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
59 constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
60 constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
61 constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Dump.Internal.Create");
62 constexpr auto APPLICATION_CORED =
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050063 "xyz.openbmc_project.Dump.Internal.Create.Type.ApplicationCored";
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050064
65 auto b = sdbusplus::bus::new_default();
66 auto mapper = b.new_method_call(
67 MAPPER_BUSNAME,
68 MAPPER_PATH,
69 MAPPER_INTERFACE,
70 "GetObject");
71 mapper.append(OBJ_INTERNAL, vector<string>({IFACE_INTERNAL}));
72
73 auto mapperResponseMsg = b.call(mapper);
74 if (mapperResponseMsg.is_method_error())
75 {
76 log<level::ERR>("Error in mapper call");
77 return;
78 }
79
80 map<string, vector<string>> mapperResponse;
81 mapperResponseMsg.read(mapperResponse);
82 if (mapperResponse.empty())
83 {
84 log<level::ERR>("Error reading mapper response");
85 return;
86 }
87
88 const auto& host = mapperResponse.cbegin()->first;
89 auto m = b.new_method_call(
90 host.c_str(),
91 OBJ_INTERNAL,
92 IFACE_INTERNAL,
93 "Create");
94 m.append(APPLICATION_CORED, files);
95 b.call_noreply(m);
Jayanth Othayothd02153c2017-07-02 22:29:42 -050096}
97
Jayanth Othayothd02153c2017-07-02 22:29:42 -050098} // namespace core
99} // namespace dump
100} // namespace phosphor