blob: 1a799820bfbd09aaf06ba68dfd6f6ed448b19a42 [file] [log] [blame]
Jayanth Othayothd02153c2017-07-02 22:29:42 -05001#pragma once
2
3#include <map>
4
5#include "dump_utils.hpp"
6#include "watch.hpp"
Jayanth Othayothbf6ec602017-08-28 01:48:49 -05007#include "config.h"
Jayanth Othayothd02153c2017-07-02 22:29:42 -05008
9namespace phosphor
10{
11namespace dump
12{
13namespace core
14{
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050015using Watch = phosphor::dump::inotify::Watch;
Jayanth Othayothd02153c2017-07-02 22:29:42 -050016using UserMap = phosphor::dump::inotify::UserMap;
17
Jayanth Othayoth7f2f8022017-09-22 11:22:25 -050018/** 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 Othayothbf6ec602017-08-28 01:48:49 -050028/** @class Manager
29 * @brief OpenBMC Core manager implementation.
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050030 */
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050031class 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 Othayothd3273ea2017-07-12 22:55:32 -050040
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050041 /** @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 Othayoth7f2f8022017-09-22 11:22:25 -050048 coreFileEvent,
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050049 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 Othayothd02153c2017-07-02 22:29:42 -050077} // namepsace core
78} // namespace dump
79} // namespace phosphor