1 #include "config.h"
2 
3 #include "dump-extensions.hpp"
4 #include "dump_manager.hpp"
5 #include "dump_manager_bmc.hpp"
6 #include "dump_manager_faultlog.hpp"
7 #include "elog_watch.hpp"
8 #include "watch.hpp"
9 #include "xyz/openbmc_project/Common/error.hpp"
10 
11 #include <phosphor-logging/elog-errors.hpp>
12 #include <phosphor-logging/lg2.hpp>
13 #include <sdbusplus/bus.hpp>
14 
15 #include <memory>
16 #include <vector>
17 
main()18 int main()
19 {
20     using namespace phosphor::logging;
21     using InternalFailure =
22         sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
23 
24     auto bus = sdbusplus::bus::new_default();
25     sd_event* event = nullptr;
26     auto rc = sd_event_default(&event);
27     if (rc < 0)
28     {
29         lg2::error("Error occurred during the sd_event_default, rc: {RC}", "RC",
30                    rc);
31         report<InternalFailure>();
32         return rc;
33     }
34     phosphor::dump::EventPtr eventP{event};
35     event = nullptr;
36 
37     // Blocking SIGCHLD is needed for calling sd_event_add_child
38     sigset_t mask;
39     if (sigemptyset(&mask) < 0)
40     {
41         lg2::error("Unable to initialize signal set, errno: {ERRNO}", "ERRNO",
42                    errno);
43         return EXIT_FAILURE;
44     }
45 
46     if (sigaddset(&mask, SIGCHLD) < 0)
47     {
48         lg2::error("Unable to add signal to signal set, errno: {ERRNO}",
49                    "ERRNO", errno);
50         return EXIT_FAILURE;
51     }
52 
53     // Block SIGCHLD first, so that the event loop can handle it
54     if (sigprocmask(SIG_BLOCK, &mask, nullptr) < 0)
55     {
56         lg2::error("Unable to block signal, errno: {ERRNO}", "ERRNO", errno);
57         return EXIT_FAILURE;
58     }
59 
60     // Add sdbusplus ObjectManager for the 'root' path of the DUMP manager.
61     sdbusplus::server::manager_t objManager(bus, DUMP_OBJPATH);
62 
63     try
64     {
65         phosphor::dump::DumpManagerList dumpMgrList{};
66         std::unique_ptr<phosphor::dump::bmc::Manager> bmcDumpMgr =
67             std::make_unique<phosphor::dump::bmc::Manager>(
68                 bus, eventP, BMC_DUMP_OBJPATH, BMC_DUMP_OBJ_ENTRY,
69                 BMC_DUMP_PATH);
70 
71         phosphor::dump::bmc::Manager* ptrBmcDumpMgr = bmcDumpMgr.get();
72 
73         dumpMgrList.push_back(std::move(bmcDumpMgr));
74 
75         std::unique_ptr<phosphor::dump::faultlog::Manager> faultLogMgr =
76             std::make_unique<phosphor::dump::faultlog::Manager>(
77                 bus, FAULTLOG_DUMP_OBJPATH, FAULTLOG_DUMP_OBJ_ENTRY,
78                 FAULTLOG_DUMP_PATH);
79         dumpMgrList.push_back(std::move(faultLogMgr));
80 
81         phosphor::dump::loadExtensions(bus, dumpMgrList);
82 
83         // Restore dbus objects of all dumps
84         for (auto& dmpMgr : dumpMgrList)
85         {
86             dmpMgr->restore();
87         }
88 
89         phosphor::dump::elog::Watch eWatch(bus, *ptrBmcDumpMgr);
90 
91         bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL);
92 
93         // Daemon is all set up so claim the busname now.
94         bus.request_name(DUMP_BUSNAME);
95 
96         auto rc = sd_event_loop(eventP.get());
97         if (rc < 0)
98         {
99             lg2::error("Error occurred during the sd_event_loop, rc: {RC}",
100                        "RC", rc);
101             elog<InternalFailure>();
102         }
103     }
104     catch (const InternalFailure& e)
105     {
106         commit<InternalFailure>();
107         return -1;
108     }
109 
110     return 0;
111 }
112