blob: 7ee876a61a5221258d07d2551b7dcdc7b9263d8a [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 bus.request_name(DUMP_BUSNAME);
69
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050070 try
Jayanth Othayoth224882b2017-05-04 05:46:45 -050071 {
Dhruvaraj Subhashchandran8b9b4692020-09-24 11:59:42 -050072 phosphor::dump::DumpManagerList dumpMgrList{};
73 std::unique_ptr<phosphor::dump::bmc::Manager> bmcDumpMgr =
74 std::make_unique<phosphor::dump::bmc::Manager>(
75 bus, eventP, BMC_DUMP_OBJPATH, BMC_DUMP_OBJ_ENTRY,
76 BMC_DUMP_PATH);
77
78 phosphor::dump::bmc::internal::Manager mgr(bus, *bmcDumpMgr,
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050079 OBJ_INTERNAL);
Dhruvaraj Subhashchandran8b9b4692020-09-24 11:59:42 -050080 dumpMgrList.push_back(std::move(bmcDumpMgr));
81
82 phosphor::dump::loadExtensions(bus, dumpMgrList);
83
84 // Restore dbus objects of all dumps
85 for (auto& dmpMgr : dumpMgrList)
86 {
87 dmpMgr->restore();
88 }
89
Jayanth Othayothd0f00642017-09-04 06:26:30 -050090 phosphor::dump::elog::Watch eWatch(bus, mgr);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050091 bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL);
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050092
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050093 auto rc = sd_event_loop(eventP.get());
94 if (rc < 0)
95 {
George Liu858fbb22021-07-01 12:25:44 +080096 log<level::ERR>(
97 fmt::format("Error occurred during the sd_event_loop, rc({})",
98 rc)
99 .c_str());
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500100 elog<InternalFailure>();
101 }
102 }
Patrick Williams9d2d7222021-10-06 12:44:44 -0500103 catch (const InternalFailure& e)
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500104 {
105 commit<InternalFailure>();
106 return -1;
Jayanth Othayoth224882b2017-05-04 05:46:45 -0500107 }
108
109 return 0;
110}