blob: 18b7125ae1ce1b5d436e623aca71161cf7afe092 [file] [log] [blame]
Jayanth Othayothd02153c2017-07-02 22:29:42 -05001#pragma once
2
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05003#include "config.h"
Jayanth Othayothd02153c2017-07-02 22:29:42 -05004
5#include "dump_utils.hpp"
6#include "watch.hpp"
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05007
8#include <map>
Jayanth Othayothd02153c2017-07-02 22:29:42 -05009
10namespace phosphor
11{
12namespace dump
13{
14namespace core
15{
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050016using Watch = phosphor::dump::inotify::Watch;
Jayanth Othayothd02153c2017-07-02 22:29:42 -050017using UserMap = phosphor::dump::inotify::UserMap;
18
Jayanth Othayoth7f2f8022017-09-22 11:22:25 -050019/** workaround: Watches for IN_CREATE event for the
20 * ubi filesystem based systemd-coredump core path
21 * Refer openbmc/issues/#2287 for more details.
22 */
23#ifdef UBI_CORE_FILE_WORKAROUND
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050024static constexpr auto coreFileEvent = IN_CREATE;
Jayanth Othayoth7f2f8022017-09-22 11:22:25 -050025#else
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050026static constexpr auto coreFileEvent = IN_CLOSE_WRITE;
Jayanth Othayoth7f2f8022017-09-22 11:22:25 -050027#endif
28
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050029/** @class Manager
30 * @brief OpenBMC Core manager implementation.
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050031 */
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050032class Manager
33{
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050034 public:
35 Manager() = delete;
36 Manager(const Manager&) = default;
37 Manager& operator=(const Manager&) = delete;
38 Manager(Manager&&) = delete;
39 Manager& operator=(Manager&&) = delete;
40 virtual ~Manager() = default;
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050041
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050042 /** @brief Constructor to create core watch object.
43 * @param[in] event - Dump manager sd_event loop.
44 */
45 Manager(const EventPtr& event) :
46 eventLoop(event.get()),
47 coreWatch(eventLoop, IN_NONBLOCK, coreFileEvent, EPOLLIN, CORE_FILE_DIR,
48 std::bind(std::mem_fn(
49 &phosphor::dump::core::Manager::watchCallback),
50 this, std::placeholders::_1))
51 {
52 }
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050053
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050054 private:
55 /** @brief Helper function for initiating dump request using
56 * D-bus internal create interface.
57 * @param [in] files - Core files list
58 */
59 void createHelper(const std::vector<std::string>& files);
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050060
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050061 /** @brief Implementation of core watch call back
62 * @param [in] fileInfo - map of file info path:event
63 */
64 void watchCallback(const UserMap& fileInfo);
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050065
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050066 /** @brief sdbusplus Dump event loop */
67 EventPtr eventLoop;
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050068
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050069 /** @brief Core watch object */
70 Watch coreWatch;
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050071};
72
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050073} // namespace core
Jayanth Othayothd02153c2017-07-02 22:29:42 -050074} // namespace dump
75} // namespace phosphor