blob: 207de537843bc23e6b40eabb881a121a7c1f9864 [file] [log] [blame]
Jayanth Othayotha320c7c2017-06-14 07:17:21 -05001#include "config.h"
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05002
Dhruvaraj Subhashchandran8b9b4692020-09-24 11:59:42 -05003#include "dump-extensions.hpp"
Jayanth Othayotha320c7c2017-06-14 07:17:21 -05004#include "dump_internal.hpp"
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05005#include "dump_manager.hpp"
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05006#include "dump_manager_bmc.hpp"
Jayanth Othayothd0f00642017-09-04 06:26:30 -05007#include "elog_watch.hpp"
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05008#include "watch.hpp"
9#include "xyz/openbmc_project/Common/error.hpp"
10
11#include <phosphor-logging/elog-errors.hpp>
12#include <sdbusplus/bus.hpp>
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050013
14#include <memory>
Dhruvaraj Subhashchandran8b9b4692020-09-24 11:59:42 -050015#include <vector>
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050016
Ramesh Iyyarbb410df2020-08-03 03:13:04 -050017int main()
Jayanth Othayoth224882b2017-05-04 05:46:45 -050018{
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050019 using namespace phosphor::logging;
20 using InternalFailure =
21 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
22
Jayanth Othayoth671fc7f2017-06-14 08:01:41 -050023 auto bus = sdbusplus::bus::new_default();
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050024 sd_event* event = nullptr;
25 auto rc = sd_event_default(&event);
26 if (rc < 0)
27 {
28 log<level::ERR>("Error occurred during the sd_event_default",
Gunnar Mills11eaab72017-10-19 16:07:31 -050029 entry("RC=%d", rc));
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050030 report<InternalFailure>();
31 return rc;
32 }
33 phosphor::dump::EventPtr eventP{event};
34 event = nullptr;
Jayanth Othayoth224882b2017-05-04 05:46:45 -050035
Alexander Filippov19ad0e82020-06-26 13:22:01 +030036 // Blocking SIGCHLD is needed for calling sd_event_add_child
37 sigset_t mask;
38 if (sigemptyset(&mask) < 0)
39 {
40 log<level::ERR>("Unable to initialize signal set",
41 entry("ERRNO=%d", errno));
42 return EXIT_FAILURE;
43 }
44
45 if (sigaddset(&mask, SIGCHLD) < 0)
46 {
47 log<level::ERR>("Unable to add signal to signal set",
48 entry("ERRNO=%d", errno));
49 return EXIT_FAILURE;
50 }
51
52 // Block SIGCHLD first, so that the event loop can handle it
53 if (sigprocmask(SIG_BLOCK, &mask, nullptr) < 0)
54 {
55 log<level::ERR>("Unable to block signal", entry("ERRNO=%d", errno));
56 return EXIT_FAILURE;
57 }
58
Jayanth Othayoth224882b2017-05-04 05:46:45 -050059 // Add sdbusplus ObjectManager for the 'root' path of the DUMP manager.
60 sdbusplus::server::manager::manager objManager(bus, DUMP_OBJPATH);
Jayanth Othayoth224882b2017-05-04 05:46:45 -050061 bus.request_name(DUMP_BUSNAME);
62
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050063 try
Jayanth Othayoth224882b2017-05-04 05:46:45 -050064 {
Dhruvaraj Subhashchandran8b9b4692020-09-24 11:59:42 -050065 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::internal::Manager mgr(bus, *bmcDumpMgr,
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050072 OBJ_INTERNAL);
Dhruvaraj Subhashchandran8b9b4692020-09-24 11:59:42 -050073 dumpMgrList.push_back(std::move(bmcDumpMgr));
74
75 phosphor::dump::loadExtensions(bus, dumpMgrList);
76
77 // Restore dbus objects of all dumps
78 for (auto& dmpMgr : dumpMgrList)
79 {
80 dmpMgr->restore();
81 }
82
Jayanth Othayothd0f00642017-09-04 06:26:30 -050083 phosphor::dump::elog::Watch eWatch(bus, mgr);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050084 bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL);
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050085
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050086 auto rc = sd_event_loop(eventP.get());
87 if (rc < 0)
88 {
89 log<level::ERR>("Error occurred during the sd_event_loop",
Gunnar Mills11eaab72017-10-19 16:07:31 -050090 entry("RC=%d", rc));
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050091 elog<InternalFailure>();
92 }
93 }
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050094 catch (InternalFailure& e)
95 {
96 commit<InternalFailure>();
97 return -1;
Jayanth Othayoth224882b2017-05-04 05:46:45 -050098 }
99
100 return 0;
101}