blob: ce858e4a849decefdadf564902b9a2173ccfc599 [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
George Liu858fbb22021-07-01 12:25:44 +080011#include <fmt/core.h>
12
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050013#include <phosphor-logging/elog-errors.hpp>
14#include <sdbusplus/bus.hpp>
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050015
16#include <memory>
Dhruvaraj Subhashchandran8b9b4692020-09-24 11:59:42 -050017#include <vector>
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050018
Ramesh Iyyarbb410df2020-08-03 03:13:04 -050019int main()
Jayanth Othayoth224882b2017-05-04 05:46:45 -050020{
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050021 using namespace phosphor::logging;
22 using InternalFailure =
23 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
24
Jayanth Othayoth671fc7f2017-06-14 08:01:41 -050025 auto bus = sdbusplus::bus::new_default();
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050026 sd_event* event = nullptr;
27 auto rc = sd_event_default(&event);
28 if (rc < 0)
29 {
George Liu858fbb22021-07-01 12:25:44 +080030 log<level::ERR>(
31 fmt::format("Error occurred during the sd_event_default, rc({})",
32 rc)
33 .c_str());
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050034 report<InternalFailure>();
35 return rc;
36 }
37 phosphor::dump::EventPtr eventP{event};
38 event = nullptr;
Jayanth Othayoth224882b2017-05-04 05:46:45 -050039
Alexander Filippov19ad0e82020-06-26 13:22:01 +030040 // Blocking SIGCHLD is needed for calling sd_event_add_child
41 sigset_t mask;
42 if (sigemptyset(&mask) < 0)
43 {
George Liu858fbb22021-07-01 12:25:44 +080044 log<level::ERR>(
45 fmt::format("Unable to initialize signal set, errno({})", errno)
46 .c_str());
Alexander Filippov19ad0e82020-06-26 13:22:01 +030047 return EXIT_FAILURE;
48 }
49
50 if (sigaddset(&mask, SIGCHLD) < 0)
51 {
George Liu858fbb22021-07-01 12:25:44 +080052 log<level::ERR>(
53 fmt::format("Unable to add signal to signal set, errno({})", errno)
54 .c_str());
Alexander Filippov19ad0e82020-06-26 13:22:01 +030055 return EXIT_FAILURE;
56 }
57
58 // Block SIGCHLD first, so that the event loop can handle it
59 if (sigprocmask(SIG_BLOCK, &mask, nullptr) < 0)
60 {
George Liu858fbb22021-07-01 12:25:44 +080061 log<level::ERR>(
62 fmt::format("Unable to block signal, errno({})", errno).c_str());
Alexander Filippov19ad0e82020-06-26 13:22:01 +030063 return EXIT_FAILURE;
64 }
65
Jayanth Othayoth224882b2017-05-04 05:46:45 -050066 // Add sdbusplus ObjectManager for the 'root' path of the DUMP manager.
67 sdbusplus::server::manager::manager objManager(bus, DUMP_OBJPATH);
Jayanth Othayoth224882b2017-05-04 05:46:45 -050068
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050069 try
Jayanth Othayoth224882b2017-05-04 05:46:45 -050070 {
Dhruvaraj Subhashchandran8b9b4692020-09-24 11:59:42 -050071 phosphor::dump::DumpManagerList dumpMgrList{};
72 std::unique_ptr<phosphor::dump::bmc::Manager> bmcDumpMgr =
73 std::make_unique<phosphor::dump::bmc::Manager>(
74 bus, eventP, BMC_DUMP_OBJPATH, BMC_DUMP_OBJ_ENTRY,
75 BMC_DUMP_PATH);
76
77 phosphor::dump::bmc::internal::Manager mgr(bus, *bmcDumpMgr,
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050078 OBJ_INTERNAL);
Dhruvaraj Subhashchandran8b9b4692020-09-24 11:59:42 -050079 dumpMgrList.push_back(std::move(bmcDumpMgr));
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
Jayanth Othayothd0f00642017-09-04 06:26:30 -050089 phosphor::dump::elog::Watch eWatch(bus, mgr);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050090 bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL);
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050091
Patrick Williams9e682c52022-04-01 17:03:45 -050092 // Daemon is all set up so claim the busname now.
93 bus.request_name(DUMP_BUSNAME);
94
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050095 auto rc = sd_event_loop(eventP.get());
96 if (rc < 0)
97 {
George Liu858fbb22021-07-01 12:25:44 +080098 log<level::ERR>(
99 fmt::format("Error occurred during the sd_event_loop, rc({})",
100 rc)
101 .c_str());
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500102 elog<InternalFailure>();
103 }
104 }
Patrick Williams9d2d7222021-10-06 12:44:44 -0500105 catch (const InternalFailure& e)
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500106 {
107 commit<InternalFailure>();
108 return -1;
Jayanth Othayoth224882b2017-05-04 05:46:45 -0500109 }
110
111 return 0;
112}