summaryrefslogtreecommitdiffstats
path: root/core_manager.hpp
blob: 1a799820bfbd09aaf06ba68dfd6f6ed448b19a42 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#pragma once

#include <map>

#include "dump_utils.hpp"
#include "watch.hpp"
#include "config.h"

namespace phosphor
{
namespace dump
{
namespace core
{
using Watch = phosphor::dump::inotify::Watch;
using UserMap = phosphor::dump::inotify::UserMap;

/** workaround: Watches for IN_CREATE event for the
 *  ubi filesystem based systemd-coredump core path
 *  Refer openbmc/issues/#2287 for more details.
 */
#ifdef UBI_CORE_FILE_WORKAROUND
    static constexpr auto coreFileEvent = IN_CREATE;
#else
    static constexpr auto coreFileEvent = IN_CLOSE_WRITE;
#endif

/** @class Manager
 *  @brief OpenBMC Core manager implementation.
 */
class Manager
{
    public:
        Manager() = delete;
        Manager(const Manager&) = default;
        Manager& operator=(const Manager&) = delete;
        Manager(Manager&&) = delete;
        Manager& operator=(Manager&&) = delete;
        virtual ~Manager() = default;

        /** @brief Constructor to create core watch object.
         *  @param[in] event - Dump manager sd_event loop.
         */
        Manager(const EventPtr& event) :
            eventLoop(event.get()),
            coreWatch(eventLoop,
                      IN_NONBLOCK,
                      coreFileEvent,
                      EPOLLIN,
                      CORE_FILE_DIR,
                      std::bind(
                          std::mem_fn(
                              &phosphor::dump::core::Manager::watchCallback),
                          this, std::placeholders::_1))
        {}

    private:
        /** @brief Helper function for initiating dump request using
         *         D-bus internal create interface.
         *  @param [in] files - Core files list
         */
        void createHelper(const std::vector<std::string>& files);


        /** @brief Implementation of core watch call back
         * @param [in] fileInfo - map of file info  path:event
         */
        void watchCallback(const UserMap& fileInfo);

        /** @brief sdbusplus Dump event loop */
        EventPtr eventLoop;

        /** @brief Core watch object */
        Watch coreWatch;
};

} // namepsace core
} // namespace dump
} // namespace phosphor
OpenPOWER on IntegriCloud