forked from openbmc/phosphor-debug-collector
-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_manager.cpp
99 lines (85 loc) · 2.84 KB
/
core_manager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#include "config.h"
#include "core_manager.hpp"
#include <experimental/filesystem>
#include <phosphor-logging/log.hpp>
#include <regex>
#include <sdbusplus/exception.hpp>
namespace phosphor
{
namespace dump
{
namespace core
{
using namespace phosphor::logging;
using namespace std;
void Manager::watchCallback(const UserMap& fileInfo)
{
vector<string> files;
for (const auto& i : fileInfo)
{
namespace fs = std::experimental::filesystem;
fs::path file(i.first);
std::string name = file.filename();
/*
As per coredump source code systemd-coredump uses below format
https://github.com/systemd/systemd/blob/master/src/coredump/coredump.c
/var/lib/systemd/coredump/core.%s.%s." SD_ID128_FORMAT_STR “
systemd-coredump also creates temporary file in core file path prior
to actual core file creation. Checking the file name format will help
to limit dump creation only for the new core files.
*/
if ("core" == name.substr(0, name.find('.')))
{
// Consider only file name start with "core."
files.push_back(file);
}
}
if (!files.empty())
{
createHelper(files);
}
}
void Manager::createHelper(const vector<string>& files)
{
constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper";
constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper";
constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper";
constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Dump.Internal.Create");
constexpr auto APPLICATION_CORED =
"xyz.openbmc_project.Dump.Internal.Create.Type.ApplicationCored";
auto b = sdbusplus::bus::new_default();
auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
MAPPER_INTERFACE, "GetObject");
mapper.append(OBJ_INTERNAL, vector<string>({IFACE_INTERNAL}));
auto mapperResponseMsg = b.call(mapper);
if (mapperResponseMsg.is_method_error())
{
log<level::ERR>("Error in mapper call");
return;
}
map<string, vector<string>> mapperResponse;
try
{
mapperResponseMsg.read(mapperResponse);
}
catch (const sdbusplus::exception::SdBusError& e)
{
log<level::ERR>(
"Failed to parse dump create message", entry("ERROR=%s", e.what()),
entry("REPLY_SIG=%s", mapperResponseMsg.get_signature()));
return;
}
if (mapperResponse.empty())
{
log<level::ERR>("Error reading mapper response");
return;
}
const auto& host = mapperResponse.cbegin()->first;
auto m =
b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL, "Create");
m.append(APPLICATION_CORED, files);
b.call_noreply(m);
}
} // namespace core
} // namespace dump
} // namespace phosphor