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 | { |
| 15 | namespace manager |
| 16 | { |
| 17 | |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 18 | using namespace phosphor::logging; |
| 19 | using namespace std; |
| 20 | |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 21 | void watchCallback(const UserMap& fileInfo) |
| 22 | { |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 23 | vector<string> files; |
| 24 | |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 25 | for (const auto& i : fileInfo) |
| 26 | { |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 27 | // Get list of debug files. |
Jayanth Othayoth | 9a56bfa | 2017-08-26 03:03:47 -0500 | [diff] [blame^] | 28 | if (IN_CLOSE_WRITE != i.second) |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 29 | { |
Jayanth Othayoth | 9a56bfa | 2017-08-26 03:03:47 -0500 | [diff] [blame^] | 30 | continue; |
| 31 | } |
| 32 | |
| 33 | namespace fs = std::experimental::filesystem; |
| 34 | fs::path file(i.first); |
| 35 | std::string name = file.filename(); |
| 36 | |
| 37 | /* |
| 38 | As per coredump source code systemd-coredump uses below format |
| 39 | https://github.com/systemd/systemd/blob/master/src/coredump/coredump.c |
| 40 | /var/lib/systemd/coredump/core.%s.%s." SD_ID128_FORMAT_STR “ |
| 41 | systemd-coredump also creates temporary file in core file path prior |
| 42 | to actual core file creation. Checking the file name format will help |
| 43 | to limit dump creation only for the new core files. |
| 44 | */ |
| 45 | if("core" == name.substr(0, name.find('.'))) |
| 46 | { |
| 47 | //Consider only file name start with "core." |
| 48 | files.push_back(file); |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 49 | } |
| 50 | } |
Jayanth Othayoth | 9a56bfa | 2017-08-26 03:03:47 -0500 | [diff] [blame^] | 51 | |
| 52 | if (!files.empty()) |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 53 | { |
| 54 | createHelper(files); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | void createHelper(const vector<string>& files) |
| 59 | { |
| 60 | constexpr auto MAPPER_BUSNAME = "xyz.openbmc_project.ObjectMapper"; |
| 61 | constexpr auto MAPPER_PATH = "/xyz/openbmc_project/object_mapper"; |
| 62 | constexpr auto MAPPER_INTERFACE = "xyz.openbmc_project.ObjectMapper"; |
| 63 | constexpr auto IFACE_INTERNAL("xyz.openbmc_project.Dump.Internal.Create"); |
| 64 | constexpr auto APPLICATION_CORED = |
Jayanth Othayoth | 9a56bfa | 2017-08-26 03:03:47 -0500 | [diff] [blame^] | 65 | "xyz.openbmc_project.Dump.Internal.Create.Type.ApplicationCored"; |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 66 | |
| 67 | auto b = sdbusplus::bus::new_default(); |
| 68 | auto mapper = b.new_method_call( |
| 69 | MAPPER_BUSNAME, |
| 70 | MAPPER_PATH, |
| 71 | MAPPER_INTERFACE, |
| 72 | "GetObject"); |
| 73 | mapper.append(OBJ_INTERNAL, vector<string>({IFACE_INTERNAL})); |
| 74 | |
| 75 | auto mapperResponseMsg = b.call(mapper); |
| 76 | if (mapperResponseMsg.is_method_error()) |
| 77 | { |
| 78 | log<level::ERR>("Error in mapper call"); |
| 79 | return; |
| 80 | } |
| 81 | |
| 82 | map<string, vector<string>> mapperResponse; |
| 83 | mapperResponseMsg.read(mapperResponse); |
| 84 | if (mapperResponse.empty()) |
| 85 | { |
| 86 | log<level::ERR>("Error reading mapper response"); |
| 87 | return; |
| 88 | } |
| 89 | |
| 90 | const auto& host = mapperResponse.cbegin()->first; |
| 91 | auto m = b.new_method_call( |
| 92 | host.c_str(), |
| 93 | OBJ_INTERNAL, |
| 94 | IFACE_INTERNAL, |
| 95 | "Create"); |
| 96 | m.append(APPLICATION_CORED, files); |
| 97 | b.call_noreply(m); |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | } // namespace manager |
| 101 | } // namespace core |
| 102 | } // namespace dump |
| 103 | } // namespace phosphor |