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