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 | |
George Liu | 858fbb2 | 2021-07-01 12:25:44 +0800 | [diff] [blame] | 5 | #include <fmt/core.h> |
| 6 | |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 7 | #include <phosphor-logging/log.hpp> |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 8 | #include <sdbusplus/exception.hpp> |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 9 | |
Jayanth Othayoth | 0af74a5 | 2021-04-08 03:55:21 -0500 | [diff] [blame] | 10 | #include <filesystem> |
| 11 | #include <regex> |
| 12 | |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 13 | namespace phosphor |
| 14 | { |
| 15 | namespace dump |
| 16 | { |
| 17 | namespace core |
| 18 | { |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 19 | |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 20 | using namespace phosphor::logging; |
| 21 | using namespace std; |
| 22 | |
Jayanth Othayoth | bf6ec60 | 2017-08-28 01:48:49 -0500 | [diff] [blame] | 23 | void Manager::watchCallback(const UserMap& fileInfo) |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 24 | { |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 25 | vector<string> files; |
| 26 | |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 27 | for (const auto& i : fileInfo) |
| 28 | { |
Jayanth Othayoth | 3fc6df4 | 2021-04-08 03:45:24 -0500 | [diff] [blame] | 29 | std::filesystem::path file(i.first); |
Jayanth Othayoth | 9a56bfa | 2017-08-26 03:03:47 -0500 | [diff] [blame] | 30 | std::string name = file.filename(); |
| 31 | |
| 32 | /* |
| 33 | As per coredump source code systemd-coredump uses below format |
| 34 | https://github.com/systemd/systemd/blob/master/src/coredump/coredump.c |
| 35 | /var/lib/systemd/coredump/core.%s.%s." SD_ID128_FORMAT_STR “ |
| 36 | systemd-coredump also creates temporary file in core file path prior |
| 37 | to actual core file creation. Checking the file name format will help |
| 38 | to limit dump creation only for the new core files. |
| 39 | */ |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 40 | if ("core" == name.substr(0, name.find('.'))) |
Jayanth Othayoth | 9a56bfa | 2017-08-26 03:03:47 -0500 | [diff] [blame] | 41 | { |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 42 | // Consider only file name start with "core." |
Jayanth Othayoth | 9a56bfa | 2017-08-26 03:03:47 -0500 | [diff] [blame] | 43 | files.push_back(file); |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 44 | } |
| 45 | } |
Jayanth Othayoth | 9a56bfa | 2017-08-26 03:03:47 -0500 | [diff] [blame] | 46 | |
| 47 | if (!files.empty()) |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 48 | { |
| 49 | createHelper(files); |
| 50 | } |
| 51 | } |
| 52 | |
Jayanth Othayoth | bf6ec60 | 2017-08-28 01:48:49 -0500 | [diff] [blame] | 53 | void Manager::createHelper(const vector<string>& files) |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 54 | { |
| 55 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 56 | constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; |
| 57 | constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; |
| 58 | constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Dump.Internal.Create"); |
| 59 | constexpr auto APPLICATION_CORED = |
Jayanth Othayoth | 9a56bfa | 2017-08-26 03:03:47 -0500 | [diff] [blame] | 60 | "xyz.openbmc_project.Dump.Internal.Create.Type.ApplicationCored"; |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 61 | |
| 62 | auto b = sdbusplus::bus::new_default(); |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 63 | auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, |
| 64 | MAPPER_INTERFACE, "GetObject"); |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 65 | mapper.append(OBJ_INTERNAL, vector<string>({IFACE_INTERNAL})); |
| 66 | |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 67 | map<string, vector<string>> mapperResponse; |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 68 | try |
| 69 | { |
Lei YU | 0eadeb7 | 2021-07-23 15:47:42 +0800 | [diff] [blame] | 70 | auto mapperResponseMsg = b.call(mapper); |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 71 | mapperResponseMsg.read(mapperResponse); |
| 72 | } |
Patrick Williams | 52ac69c | 2021-09-02 09:37:16 -0500 | [diff] [blame] | 73 | catch (const sdbusplus::exception::exception& e) |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 74 | { |
Lei YU | 0eadeb7 | 2021-07-23 15:47:42 +0800 | [diff] [blame] | 75 | log<level::ERR>( |
| 76 | fmt::format("Failed to GetObject on Dump.Internal: {}", e.what()) |
| 77 | .c_str()); |
William A. Kennington III | 15cd3ce | 2018-05-15 11:34:44 -0700 | [diff] [blame] | 78 | return; |
| 79 | } |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 80 | if (mapperResponse.empty()) |
| 81 | { |
| 82 | log<level::ERR>("Error reading mapper response"); |
| 83 | return; |
| 84 | } |
| 85 | |
| 86 | const auto& host = mapperResponse.cbegin()->first; |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 87 | auto m = |
| 88 | b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL, "Create"); |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 89 | m.append(APPLICATION_CORED, files); |
Lei YU | 0eadeb7 | 2021-07-23 15:47:42 +0800 | [diff] [blame] | 90 | try |
| 91 | { |
| 92 | b.call_noreply(m); |
| 93 | } |
Patrick Williams | 52ac69c | 2021-09-02 09:37:16 -0500 | [diff] [blame] | 94 | catch (const sdbusplus::exception::exception& e) |
Lei YU | 0eadeb7 | 2021-07-23 15:47:42 +0800 | [diff] [blame] | 95 | { |
| 96 | log<level::ERR>( |
| 97 | fmt::format("Failed to create dump: {}", e.what()).c_str()); |
| 98 | } |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 99 | } |
| 100 | |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 101 | } // namespace core |
| 102 | } // namespace dump |
| 103 | } // namespace phosphor |