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> |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 5 | |
| 6 | #include "core_manager.hpp" |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 7 | #include "config.h" |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 8 | |
| 9 | namespace phosphor |
| 10 | { |
| 11 | namespace dump |
| 12 | { |
| 13 | namespace core |
| 14 | { |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 15 | |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 16 | using namespace phosphor::logging; |
| 17 | using namespace std; |
| 18 | |
Jayanth Othayoth | bf6ec60 | 2017-08-28 01:48:49 -0500 | [diff] [blame] | 19 | void Manager::watchCallback(const UserMap& fileInfo) |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 20 | { |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 21 | vector<string> files; |
| 22 | |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 23 | for (const auto& i : fileInfo) |
| 24 | { |
Jayanth Othayoth | 9a56bfa | 2017-08-26 03:03:47 -0500 | [diff] [blame] | 25 | namespace fs = std::experimental::filesystem; |
| 26 | fs::path file(i.first); |
| 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 | */ |
| 37 | if("core" == name.substr(0, name.find('.'))) |
| 38 | { |
| 39 | //Consider only file name start with "core." |
| 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(); |
| 60 | auto mapper = b.new_method_call( |
| 61 | MAPPER_BUSNAME, |
| 62 | MAPPER_PATH, |
| 63 | MAPPER_INTERFACE, |
| 64 | "GetObject"); |
| 65 | mapper.append(OBJ_INTERNAL, vector<string>({IFACE_INTERNAL})); |
| 66 | |
| 67 | auto mapperResponseMsg = b.call(mapper); |
| 68 | if (mapperResponseMsg.is_method_error()) |
| 69 | { |
| 70 | log<level::ERR>("Error in mapper call"); |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | map<string, vector<string>> mapperResponse; |
| 75 | mapperResponseMsg.read(mapperResponse); |
| 76 | if (mapperResponse.empty()) |
| 77 | { |
| 78 | log<level::ERR>("Error reading mapper response"); |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | const auto& host = mapperResponse.cbegin()->first; |
| 83 | auto m = b.new_method_call( |
| 84 | host.c_str(), |
| 85 | OBJ_INTERNAL, |
| 86 | IFACE_INTERNAL, |
| 87 | "Create"); |
| 88 | m.append(APPLICATION_CORED, files); |
| 89 | b.call_noreply(m); |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 90 | } |
| 91 | |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 92 | } // namespace core |
| 93 | } // namespace dump |
| 94 | } // namespace phosphor |