1 #pragma once
2 
3 #include "config.h"
4 
5 #include "dump_utils.hpp"
6 #include "watch.hpp"
7 
8 #include <map>
9 
10 namespace phosphor
11 {
12 namespace dump
13 {
14 namespace core
15 {
16 using Watch = phosphor::dump::inotify::Watch;
17 using UserMap = phosphor::dump::inotify::UserMap;
18 
19 /** workaround: Watches for IN_CLOSE_WRITE event for the
20  *  jffs filesystem based systemd-coredump core path
21  *  Refer openbmc/issues/#2287 for more details.
22  *
23  *  JFFS_CORE_FILE_WORKAROUND will be enabled for jffs and
24  *  for other file system it will be disabled.
25  */
26 #ifdef JFFS_CORE_FILE_WORKAROUND
27 static constexpr auto coreFileEvent = IN_CLOSE_WRITE;
28 #else
29 static constexpr auto coreFileEvent = IN_CREATE;
30 #endif
31 
32 /** @class Manager
33  *  @brief OpenBMC Core manager implementation.
34  */
35 class Manager
36 {
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;
44 
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))
54     {}
55 
56   private:
57     /** @brief Helper function for initiating dump request using
58      *         D-bus internal create interface.
59      *  @param [in] files - Core files list
60      */
61     void createHelper(const std::vector<std::string>& files);
62 
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);
67 
68     /** @brief sdbusplus Dump event loop */
69     EventPtr eventLoop;
70 
71     /** @brief Core watch object */
72     Watch coreWatch;
73 };
74 
75 } // namespace core
76 } // namespace dump
77 } // namespace phosphor
78