blob: 554d969c4c52e7bb9312c8bc9ad6676e2e9e4143 [file] [log] [blame]
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05001#include "config.h"
Jayanth Othayothd02153c2017-07-02 22:29:42 -05002
3#include "core_manager.hpp"
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05004
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -05005#include <phosphor-logging/lg2.hpp>
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05006#include <sdbusplus/exception.hpp>
Jayanth Othayothd02153c2017-07-02 22:29:42 -05007
Jayanth Othayoth0af74a52021-04-08 03:55:21 -05008#include <filesystem>
9#include <regex>
10
Jayanth Othayothd02153c2017-07-02 22:29:42 -050011namespace phosphor
12{
13namespace dump
14{
15namespace core
16{
Jayanth Othayothd02153c2017-07-02 22:29:42 -050017
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050018using 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 Othayoth3fc6df42021-04-08 03:45:24 -050026 std::filesystem::path file(i.first);
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050027 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 */
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050037 if ("core" == name.substr(0, name.find('.')))
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050038 {
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050039 // Consider only file name start with "core."
Jayanth Othayoth9a56bfa2017-08-26 03:03:47 -050040 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();
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050060 auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH,
61 MAPPER_INTERFACE, "GetObject");
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050062 mapper.append(OBJ_INTERNAL, vector<string>({IFACE_INTERNAL}));
63
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050064 map<string, vector<string>> mapperResponse;
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070065 try
66 {
Lei YU0eadeb72021-07-23 15:47:42 +080067 auto mapperResponseMsg = b.call(mapper);
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070068 mapperResponseMsg.read(mapperResponse);
69 }
Patrick Williams9b18bf22022-07-22 19:26:55 -050070 catch (const sdbusplus::exception_t& e)
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070071 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050072 lg2::error("Failed to GetObject on Dump.Internal: {ERROR}", "ERROR", e);
William A. Kennington III15cd3ce2018-05-15 11:34:44 -070073 return;
74 }
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050075 if (mapperResponse.empty())
76 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050077 lg2::error("Error reading mapper response");
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050078 return;
79 }
80
81 const auto& host = mapperResponse.cbegin()->first;
Patrick Williams78e88402023-05-10 07:50:48 -050082 auto m = b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL,
83 "Create");
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050084 m.append(APPLICATION_CORED, files);
Lei YU0eadeb72021-07-23 15:47:42 +080085 try
86 {
87 b.call_noreply(m);
88 }
Patrick Williams9b18bf22022-07-22 19:26:55 -050089 catch (const sdbusplus::exception_t& e)
Lei YU0eadeb72021-07-23 15:47:42 +080090 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050091 lg2::error("Failed to create dump: {ERROR}", "ERROR", e);
Lei YU0eadeb72021-07-23 15:47:42 +080092 }
Jayanth Othayothd02153c2017-07-02 22:29:42 -050093}
94
Jayanth Othayothd02153c2017-07-02 22:29:42 -050095} // namespace core
96} // namespace dump
97} // namespace phosphor