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