diff options
author | Jayanth Othayoth <ojayanth@in.ibm.com> | 2017-06-14 07:17:21 -0500 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-06-29 18:36:04 +0000 |
commit | a320c7cafcab3a967de9a1149a5e34e02699d382 (patch) | |
tree | c676d1b03407a0092d9b25256bbc04ab73a5f32b /dump_manager.cpp | |
parent | a19440dc9e62ffc3f8f7d1f46f0801f2b25cd0cf (diff) | |
download | phosphor-debug-collector-a320c7cafcab3a967de9a1149a5e34e02699d382.tar.gz phosphor-debug-collector-a320c7cafcab3a967de9a1149a5e34e02699d382.zip |
Implementation of create interface.
Both the external and internal Dump managers define "Create"
interfaces. This commit implements these.
Change-Id: If857ec6ea7267fd72e9b420e6b44fa68b6abab66
Signed-off-by: Jayanth Othayoth <ojayanth@in.ibm.com>
Diffstat (limited to 'dump_manager.cpp')
-rw-r--r-- | dump_manager.cpp | 116 |
1 files changed, 116 insertions, 0 deletions
diff --git a/dump_manager.cpp b/dump_manager.cpp new file mode 100644 index 0000000..d0376a5 --- /dev/null +++ b/dump_manager.cpp @@ -0,0 +1,116 @@ +#include <unistd.h> + +#include <phosphor-logging/elog-errors.hpp> + +#include "dump_manager.hpp" +#include "dump_internal.hpp" +#include "xyz/openbmc_project/Common/error.hpp" +#include "config.h" + +namespace phosphor +{ +namespace dump +{ + +using namespace sdbusplus::xyz::openbmc_project::Common::Error; +using namespace phosphor::logging; + +namespace internal +{ + +void Manager::create( + Type type, + std::vector<std::string> fullPaths) +{ + // TODO openbmc/openbmc#1795 + // Add implementaion of internal create function. +} + +} //namepsace internal + +uint32_t Manager::createDump() +{ + std::vector<std::string> paths; + + return captureDump(Type::UserRequested, paths); +} + +uint32_t Manager::captureDump( + Type type, + const std::vector<std::string>& fullPaths) +{ + pid_t pid = fork(); + + // TODO openbmc/openbmc#1795 + // Add Dump location info. + if (pid == 0) + { + execl("/usr/bin/ffdc", "ffdc", nullptr); + + //ffdc script execution is failed. + auto error = errno; + log<level::ERR>("Error occurred during ffdc function execution", + entry("ERRNO=%d", error)); + elog<InternalFailure>(); + } + else if (pid > 0) + { + auto rc = sd_event_add_child(eventLoop.get(), + nullptr, + pid, + WEXITED | WSTOPPED, + callback, + nullptr); + if (0 > rc) + { + // Failed to add to event loop + log<level::ERR>("Error occurred during the sd_event_add_child call", + entry("rc=%d", rc)); + elog<InternalFailure>(); + } + } + else + { + auto error = errno; + log<level::ERR>("Error occurred during fork", + entry("ERRNO=%d", error)); + elog<InternalFailure>(); + } + + return ++lastEntryId; +} + +void Manager::createEntry(const fs::path& file) +{ + // TODO openbmc/openbmc#1795 + // Get Dump ID and Epoch time from Dump file name. + // Validate the Dump file name. + auto id = lastEntryId; + + //Get Epoch time. + auto ms = std::chrono::duration_cast<std::chrono::milliseconds>( + std::chrono::system_clock::now().time_since_epoch()).count(); + + // Entry Object path. + auto objPath = fs::path(OBJ_ENTRY) / std::to_string(id); + + auto size = fs::file_size(file); + + entries.insert(std::make_pair(id, + std::make_unique<Entry>( + bus, + objPath.c_str(), + id, + ms, + size, + file, + *this))); +} + +void Manager::erase(uint32_t entryId) +{ + entries.erase(entryId); +} + +} //namespace dump +} //namespace phosphor |