Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <map> |
| 4 | |
| 5 | #include "dump_utils.hpp" |
| 6 | #include "watch.hpp" |
Jayanth Othayoth | bf6ec60 | 2017-08-28 01:48:49 -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 | bf6ec60 | 2017-08-28 01:48:49 -0500 | [diff] [blame] | 15 | using Watch = phosphor::dump::inotify::Watch; |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 16 | using UserMap = phosphor::dump::inotify::UserMap; |
| 17 | |
Jayanth Othayoth | 7f2f802 | 2017-09-22 11:22:25 -0500 | [diff] [blame] | 18 | /** workaround: Watches for IN_CREATE event for the |
| 19 | * ubi filesystem based systemd-coredump core path |
| 20 | * Refer openbmc/issues/#2287 for more details. |
| 21 | */ |
| 22 | #ifdef UBI_CORE_FILE_WORKAROUND |
| 23 | static constexpr auto coreFileEvent = IN_CREATE; |
| 24 | #else |
| 25 | static constexpr auto coreFileEvent = IN_CLOSE_WRITE; |
| 26 | #endif |
| 27 | |
Jayanth Othayoth | bf6ec60 | 2017-08-28 01:48:49 -0500 | [diff] [blame] | 28 | /** @class Manager |
| 29 | * @brief OpenBMC Core manager implementation. |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 30 | */ |
Jayanth Othayoth | bf6ec60 | 2017-08-28 01:48:49 -0500 | [diff] [blame] | 31 | class Manager |
| 32 | { |
| 33 | public: |
| 34 | Manager() = delete; |
| 35 | Manager(const Manager&) = default; |
| 36 | Manager& operator=(const Manager&) = delete; |
| 37 | Manager(Manager&&) = delete; |
| 38 | Manager& operator=(Manager&&) = delete; |
| 39 | virtual ~Manager() = default; |
Jayanth Othayoth | d3273ea | 2017-07-12 22:55:32 -0500 | [diff] [blame] | 40 | |
Jayanth Othayoth | bf6ec60 | 2017-08-28 01:48:49 -0500 | [diff] [blame] | 41 | /** @brief Constructor to create core watch object. |
| 42 | * @param[in] event - Dump manager sd_event loop. |
| 43 | */ |
| 44 | Manager(const EventPtr& event) : |
| 45 | eventLoop(event.get()), |
| 46 | coreWatch(eventLoop, |
| 47 | IN_NONBLOCK, |
Jayanth Othayoth | 7f2f802 | 2017-09-22 11:22:25 -0500 | [diff] [blame] | 48 | coreFileEvent, |
Jayanth Othayoth | bf6ec60 | 2017-08-28 01:48:49 -0500 | [diff] [blame] | 49 | EPOLLIN, |
| 50 | CORE_FILE_DIR, |
| 51 | std::bind( |
| 52 | std::mem_fn( |
| 53 | &phosphor::dump::core::Manager::watchCallback), |
| 54 | this, std::placeholders::_1)) |
| 55 | {} |
| 56 | |
| 57 | private: |
| 58 | /** @brief Helper function for initiating dump request using |
| 59 | * D-bus internal create interface. |
| 60 | * @param [in] files - Core files list |
| 61 | */ |
| 62 | void createHelper(const std::vector<std::string>& files); |
| 63 | |
| 64 | |
| 65 | /** @brief Implementation of core watch call back |
| 66 | * @param [in] fileInfo - map of file info path:event |
| 67 | */ |
| 68 | void watchCallback(const UserMap& fileInfo); |
| 69 | |
| 70 | /** @brief sdbusplus Dump event loop */ |
| 71 | EventPtr eventLoop; |
| 72 | |
| 73 | /** @brief Core watch object */ |
| 74 | Watch coreWatch; |
| 75 | }; |
| 76 | |
Jayanth Othayoth | d02153c | 2017-07-02 22:29:42 -0500 | [diff] [blame] | 77 | } // namepsace core |
| 78 | } // namespace dump |
| 79 | } // namespace phosphor |