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