blob: ee887edb855d61a3364ec8e567148e95c74177ce [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
Chirag Sharmae22aca72021-01-18 09:55:29 -060019/** workaround: Watches for IN_CLOSE_WRITE event for the
20 * jffs filesystem based systemd-coredump core path
Jayanth Othayoth7f2f8022017-09-22 11:22:25 -050021 * Refer openbmc/issues/#2287 for more details.
Chirag Sharmae22aca72021-01-18 09:55:29 -060022 *
23 * JFFS_CORE_FILE_WORKAROUND will be enabled for jffs and
24 * for other file system it will be disabled.
Jayanth Othayoth7f2f8022017-09-22 11:22:25 -050025 */
Chirag Sharmae22aca72021-01-18 09:55:29 -060026#ifdef JFFS_CORE_FILE_WORKAROUND
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050027static constexpr auto coreFileEvent = IN_CLOSE_WRITE;
Chirag Sharmae22aca72021-01-18 09:55:29 -060028#else
29static constexpr auto coreFileEvent = IN_CREATE;
Jayanth Othayoth7f2f8022017-09-22 11:22:25 -050030#endif
31
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050032/** @class Manager
33 * @brief OpenBMC Core manager implementation.
Jayanth Othayothd3273ea2017-07-12 22:55:32 -050034 */
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050035class Manager
36{
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050037 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 Othayothd3273ea2017-07-12 22:55:32 -050044
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050045 /** @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 Othayoth0af74a52021-04-08 03:55:21 -050054 {}
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050055
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050056 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);
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050062
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050063 /** @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 Othayothbf6ec602017-08-28 01:48:49 -050067
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050068 /** @brief sdbusplus Dump event loop */
69 EventPtr eventLoop;
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050070
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050071 /** @brief Core watch object */
72 Watch coreWatch;
Jayanth Othayothbf6ec602017-08-28 01:48:49 -050073};
74
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050075} // namespace core
Jayanth Othayothd02153c2017-07-02 22:29:42 -050076} // namespace dump
77} // namespace phosphor