1 #include "config.h" 2 3 #include "core_manager.hpp" 4 5 #include <experimental/filesystem> 6 #include <phosphor-logging/log.hpp> 7 #include <regex> 8 #include <sdbusplus/exception.hpp> 9 10 namespace phosphor 11 { 12 namespace dump 13 { 14 namespace core 15 { 16 17 using namespace phosphor::logging; 18 using namespace std; 19 20 void Manager::watchCallback(const UserMap& fileInfo) 21 { 22 vector<string> files; 23 24 for (const auto& i : fileInfo) 25 { 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); 42 } 43 } 44 45 if (!files.empty()) 46 { 47 createHelper(files); 48 } 49 } 50 51 void Manager::createHelper(const vector<string>& files) 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 = 58 "xyz.openbmc_project.Dump.Internal.Create.Type.ApplicationCored"; 59 60 auto b = sdbusplus::bus::new_default(); 61 auto mapper = b.new_method_call(MAPPER_BUSNAME, MAPPER_PATH, 62 MAPPER_INTERFACE, "GetObject"); 63 mapper.append(OBJ_INTERNAL, vector<string>({IFACE_INTERNAL})); 64 65 auto mapperResponseMsg = b.call(mapper); 66 if (mapperResponseMsg.is_method_error()) 67 { 68 log<level::ERR>("Error in mapper call"); 69 return; 70 } 71 72 map<string, vector<string>> mapperResponse; 73 try 74 { 75 mapperResponseMsg.read(mapperResponse); 76 } 77 catch (const sdbusplus::exception::SdBusError& e) 78 { 79 log<level::ERR>( 80 "Failed to parse dump create message", entry("ERROR=%s", e.what()), 81 entry("REPLY_SIG=%s", mapperResponseMsg.get_signature())); 82 return; 83 } 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 = 92 b.new_method_call(host.c_str(), OBJ_INTERNAL, IFACE_INTERNAL, "Create"); 93 m.append(APPLICATION_CORED, files); 94 b.call_noreply(m); 95 } 96 97 } // namespace core 98 } // namespace dump 99 } // namespace phosphor 100