Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 1 | #include "config.h" |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 2 | |
| 3 | #include "core_manager.hpp" |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 4 | |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 5 | #include <phosphor-logging/lg2.hpp> |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 6 | #include <sdbusplus/exception.hpp> |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 7 | |
Jayanth Othayoth | 0af74a5 | 2021-04-08 03:55:21 -0500 | [diff] [blame] | 8 | #include <filesystem> |
| 9 | #include <regex> |
| 10 | |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 11 | namespace phosphor |
| 12 | { |
| 13 | namespace dump |
| 14 | { |
| 15 | namespace core |
| 16 | { |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 17 | |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 18 | using namespace std; |
| 19 | |
Jayanth Othayoth | bf6ec60 | 2017-08-28 01:48:49 -0500 | [diff] [blame] | 20 | void Manager::watchCallback(const UserMap& fileInfo) |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 21 | { |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 22 | vector<string> files; |
| 23 | |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 24 | for (const auto& i : fileInfo) |
| 25 | { |
Jayanth Othayoth | 3fc6df4 | 2021-04-08 03:45:24 -0500 | [diff] [blame] | 26 | std::filesystem::path file(i.first); |
Jayanth Othayoth | 9a56bfa | 2017-08-26 03:03:47 -0500 | [diff] [blame] | 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 | */ |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 37 | if ("core" == name.substr(0, name.find('.'))) |
Jayanth Othayoth | 9a56bfa | 2017-08-26 03:03:47 -0500 | [diff] [blame] | 38 | { |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 39 | // Consider only file name start with "core." |
Jayanth Othayoth | 9a56bfa | 2017-08-26 03:03:47 -0500 | [diff] [blame] | 40 | files.push_back(file); |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 41 | } |
| 42 | } |
Jayanth Othayoth | 9a56bfa | 2017-08-26 03:03:47 -0500 | [diff] [blame] | 43 | |
| 44 | if (!files.empty()) |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 45 | { |
| 46 | createHelper(files); |
| 47 | } |
| 48 | } |
| 49 | |
Jayanth Othayoth | bf6ec60 | 2017-08-28 01:48:49 -0500 | [diff] [blame] | 50 | void Manager::createHelper(const vector<string>& files) |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 51 | { |
| 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"; |
Dhruvaraj Subhashchandran | 247159b | 2023-06-29 05:17:35 -0500 | [diff] [blame] | 55 | constexpr auto DUMP_CREATE_IFACE = "xyz.openbmc_project.Dump.Create"; |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 56 | |
| 57 | auto b = sdbusplus::bus::new_default(); |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 58 | auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 59 | MAPPER_INTERFACE, "GetObject"); |
Dhruvaraj Subhashchandran | 247159b | 2023-06-29 05:17:35 -0500 | [diff] [blame] | 60 | mapper.append(BMC_DUMP_OBJPATH, vector<string>({DUMP_CREATE_IFACE})); |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 61 | |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 62 | map<string, vector<string>> mapperResponse; |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 63 | try |
| 64 | { |
Lei YU | 0eadeb7 | 2021-07-23 15:47:42 +0800 | [diff] [blame] | 65 | auto mapperResponseMsg = b.call(mapper); |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 66 | mapperResponseMsg.read(mapperResponse); |
| 67 | } |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 68 | catch (const sdbusplus::exception_t& e) |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 69 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 70 | lg2::error("Failed to GetObject on Dump.Internal: {ERROR}", "ERROR", e); |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 71 | return; |
| 72 | } |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 73 | if (mapperResponse.empty()) |
| 74 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 75 | lg2::error("Error reading mapper response"); |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 76 | return; |
| 77 | } |
| 78 | |
| 79 | const auto& host = mapperResponse.cbegin()->first; |
Dhruvaraj Subhashchandran | 247159b | 2023-06-29 05:17:35 -0500 | [diff] [blame] | 80 | auto m = b.new_method_call(host.c_str(), BMC_DUMP_OBJPATH, |
| 81 | DUMP_CREATE_IFACE, "CreateDump"); |
| 82 | phosphor::dump::DumpCreateParams params; |
| 83 | using CreateParameters = |
| 84 | sdbusplus::common::xyz::openbmc_project::dump::Create::CreateParameters; |
| 85 | using DumpType = |
| 86 | sdbusplus::common::xyz::openbmc_project::dump::Create::DumpType; |
| 87 | using DumpIntr = sdbusplus::common::xyz::openbmc_project::dump::Create; |
| 88 | params[DumpIntr::convertCreateParametersToString( |
| 89 | CreateParameters::DumpType)] = |
| 90 | DumpIntr::convertDumpTypeToString(DumpType::ApplicationCored); |
| 91 | params[DumpIntr::convertCreateParametersToString( |
| 92 | CreateParameters::FilePath)] = files.front(); |
| 93 | m.append(params); |
Lei YU | 0eadeb7 | 2021-07-23 15:47:42 +0800 | [diff] [blame] | 94 | try |
| 95 | { |
| 96 | b.call_noreply(m); |
| 97 | } |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 98 | catch (const sdbusplus::exception_t& e) |
Lei YU | 0eadeb7 | 2021-07-23 15:47:42 +0800 | [diff] [blame] | 99 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 100 | lg2::error("Failed to create dump: {ERROR}", "ERROR", e); |
Lei YU | 0eadeb7 | 2021-07-23 15:47:42 +0800 | [diff] [blame] | 101 | } |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 102 | } |
| 103 | |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 104 | } // namespace core |
| 105 | } // namespace dump |
| 106 | } // namespace phosphor |