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"; |
| 55 | constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Dump.Internal.Create"); |
| 56 | constexpr auto APPLICATION_CORED = |
Jayanth Othayoth | 9a56bfa | 2017-08-26 03:03:47 -0500 | [diff] [blame] | 57 | "xyz.openbmc_project.Dump.Internal.Create.Type.ApplicationCored"; |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 58 | |
| 59 | auto b = sdbusplus::bus::new_default(); |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 60 | auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 61 | MAPPER_INTERFACE, "GetObject"); |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 62 | mapper.append(OBJ_INTERNAL, vector<string>({IFACE_INTERNAL})); |
| 63 | |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 64 | map<string, vector<string>> mapperResponse; |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 65 | try |
| 66 | { |
Lei YU | 0eadeb7 | 2021-07-23 15:47:42 +0800 | [diff] [blame] | 67 | auto mapperResponseMsg = b.call(mapper); |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 68 | mapperResponseMsg.read(mapperResponse); |
| 69 | } |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 70 | catch (const sdbusplus::exception_t& e) |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 71 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 72 | 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] | 73 | return; |
| 74 | } |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 75 | if (mapperResponse.empty()) |
| 76 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 77 | lg2::error("Error reading mapper response"); |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 78 | return; |
| 79 | } |
| 80 | |
| 81 | const auto& host = mapperResponse.cbegin()->first; |
Patrick Williams | 78e8840 | 2023-05-10 07:50:48 -0500 | [diff] [blame] | 82 | auto m = b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL, |
| 83 | "Create"); |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 84 | m.append(APPLICATION_CORED, files); |
Lei YU | 0eadeb7 | 2021-07-23 15:47:42 +0800 | [diff] [blame] | 85 | try |
| 86 | { |
| 87 | b.call_noreply(m); |
| 88 | } |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 89 | catch (const sdbusplus::exception_t& e) |
Lei YU | 0eadeb7 | 2021-07-23 15:47:42 +0800 | [diff] [blame] | 90 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 91 | lg2::error("Failed to create dump: {ERROR}", "ERROR", e); |
Lei YU | 0eadeb7 | 2021-07-23 15:47:42 +0800 | [diff] [blame] | 92 | } |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 93 | } |
| 94 | |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 95 | } // namespace core |
| 96 | } // namespace dump |
| 97 | } // namespace phosphor |