Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 1 | #include <unistd.h> |
Jayanth Othayoth | bcb174b | 2017-07-02 06:29:24 -0500 | [diff] [blame] | 2 | #include <sys/inotify.h> |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 3 | |
| 4 | #include <phosphor-logging/elog-errors.hpp> |
| 5 | |
| 6 | #include "dump_manager.hpp" |
| 7 | #include "dump_internal.hpp" |
| 8 | #include "xyz/openbmc_project/Common/error.hpp" |
| 9 | #include "config.h" |
| 10 | |
| 11 | namespace phosphor |
| 12 | { |
| 13 | namespace dump |
| 14 | { |
| 15 | |
| 16 | using namespace sdbusplus::xyz::openbmc_project::Common::Error; |
| 17 | using namespace phosphor::logging; |
| 18 | |
| 19 | namespace internal |
| 20 | { |
| 21 | |
| 22 | void Manager::create( |
| 23 | Type type, |
| 24 | std::vector<std::string> fullPaths) |
| 25 | { |
| 26 | // TODO openbmc/openbmc#1795 |
| 27 | // Add implementaion of internal create function. |
| 28 | } |
| 29 | |
| 30 | } //namepsace internal |
| 31 | |
| 32 | uint32_t Manager::createDump() |
| 33 | { |
| 34 | std::vector<std::string> paths; |
| 35 | |
| 36 | return captureDump(Type::UserRequested, paths); |
| 37 | } |
| 38 | |
| 39 | uint32_t Manager::captureDump( |
| 40 | Type type, |
| 41 | const std::vector<std::string>& fullPaths) |
| 42 | { |
| 43 | pid_t pid = fork(); |
| 44 | |
| 45 | // TODO openbmc/openbmc#1795 |
| 46 | // Add Dump location info. |
| 47 | if (pid == 0) |
| 48 | { |
| 49 | execl("/usr/bin/ffdc", "ffdc", nullptr); |
| 50 | |
| 51 | //ffdc script execution is failed. |
| 52 | auto error = errno; |
| 53 | log<level::ERR>("Error occurred during ffdc function execution", |
| 54 | entry("ERRNO=%d", error)); |
| 55 | elog<InternalFailure>(); |
| 56 | } |
| 57 | else if (pid > 0) |
| 58 | { |
| 59 | auto rc = sd_event_add_child(eventLoop.get(), |
| 60 | nullptr, |
| 61 | pid, |
| 62 | WEXITED | WSTOPPED, |
| 63 | callback, |
| 64 | nullptr); |
| 65 | if (0 > rc) |
| 66 | { |
| 67 | // Failed to add to event loop |
| 68 | log<level::ERR>("Error occurred during the sd_event_add_child call", |
| 69 | entry("rc=%d", rc)); |
| 70 | elog<InternalFailure>(); |
| 71 | } |
| 72 | } |
| 73 | else |
| 74 | { |
| 75 | auto error = errno; |
| 76 | log<level::ERR>("Error occurred during fork", |
| 77 | entry("ERRNO=%d", error)); |
| 78 | elog<InternalFailure>(); |
| 79 | } |
| 80 | |
| 81 | return ++lastEntryId; |
| 82 | } |
| 83 | |
| 84 | void Manager::createEntry(const fs::path& file) |
| 85 | { |
| 86 | // TODO openbmc/openbmc#1795 |
| 87 | // Get Dump ID and Epoch time from Dump file name. |
| 88 | // Validate the Dump file name. |
| 89 | auto id = lastEntryId; |
| 90 | |
| 91 | //Get Epoch time. |
| 92 | auto ms = std::chrono::duration_cast<std::chrono::milliseconds>( |
| 93 | std::chrono::system_clock::now().time_since_epoch()).count(); |
| 94 | |
| 95 | // Entry Object path. |
| 96 | auto objPath = fs::path(OBJ_ENTRY) / std::to_string(id); |
| 97 | |
| 98 | auto size = fs::file_size(file); |
| 99 | |
| 100 | entries.insert(std::make_pair(id, |
| 101 | std::make_unique<Entry>( |
| 102 | bus, |
| 103 | objPath.c_str(), |
| 104 | id, |
| 105 | ms, |
| 106 | size, |
| 107 | file, |
| 108 | *this))); |
| 109 | } |
| 110 | |
| 111 | void Manager::erase(uint32_t entryId) |
| 112 | { |
| 113 | entries.erase(entryId); |
| 114 | } |
| 115 | |
Jayanth Othayoth | bcb174b | 2017-07-02 06:29:24 -0500 | [diff] [blame] | 116 | void Manager::watchCallback(const UserMap& fileInfo) |
| 117 | { |
| 118 | for (const auto& i : fileInfo) |
| 119 | { |
| 120 | // For any new dump file create dump entry object. |
| 121 | if (IN_CLOSE_WRITE == i.second) |
| 122 | { |
| 123 | createEntry(i.first); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 128 | } //namespace dump |
| 129 | } //namespace phosphor |