blob: a3ce92098e0da4fa2c1383f4418fa3aac073c238 [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 Othayothcb65ffc2018-10-16 08:29:32 -05004#include "dump_manager.hpp"
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -05005#include "dump_manager_bmc.hpp"
Claire Weinan919f71c2022-03-01 19:02:07 -08006#include "dump_manager_faultlog.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>
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050012#include <phosphor-logging/lg2.hpp>
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050013#include <sdbusplus/bus.hpp>
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050014
15#include <memory>
Dhruvaraj Subhashchandran8b9b4692020-09-24 11:59:42 -050016#include <vector>
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050017
Ramesh Iyyarbb410df2020-08-03 03:13:04 -050018int main()
Jayanth Othayoth224882b2017-05-04 05:46:45 -050019{
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050020 using namespace phosphor::logging;
21 using InternalFailure =
22 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
23
Jayanth Othayoth671fc7f2017-06-14 08:01:41 -050024 auto bus = sdbusplus::bus::new_default();
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050025 sd_event* event = nullptr;
26 auto rc = sd_event_default(&event);
27 if (rc < 0)
28 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050029 lg2::error("Error occurred during the sd_event_default, rc: {RC}", "RC",
30 rc);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050031 report<InternalFailure>();
32 return rc;
33 }
34 phosphor::dump::EventPtr eventP{event};
35 event = nullptr;
Jayanth Othayoth224882b2017-05-04 05:46:45 -050036
Alexander Filippov19ad0e82020-06-26 13:22:01 +030037 // Blocking SIGCHLD is needed for calling sd_event_add_child
38 sigset_t mask;
39 if (sigemptyset(&mask) < 0)
40 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050041 lg2::error("Unable to initialize signal set, errno: {ERRNO}", "ERRNO",
42 errno);
Alexander Filippov19ad0e82020-06-26 13:22:01 +030043 return EXIT_FAILURE;
44 }
45
46 if (sigaddset(&mask, SIGCHLD) < 0)
47 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050048 lg2::error("Unable to add signal to signal set, errno: {ERRNO}",
49 "ERRNO", errno);
Alexander Filippov19ad0e82020-06-26 13:22:01 +030050 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 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050056 lg2::error("Unable to block signal, errno: {ERRNO}", "ERRNO", errno);
Alexander Filippov19ad0e82020-06-26 13:22:01 +030057 return EXIT_FAILURE;
58 }
59
Jayanth Othayoth224882b2017-05-04 05:46:45 -050060 // Add sdbusplus ObjectManager for the 'root' path of the DUMP manager.
Patrick Williams9b18bf22022-07-22 19:26:55 -050061 sdbusplus::server::manager_t objManager(bus, DUMP_OBJPATH);
Jayanth Othayoth224882b2017-05-04 05:46:45 -050062
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
Dhruvaraj Subhashchandrane4350f92023-06-29 05:57:47 -050071 phosphor::dump::bmc::Manager* ptrBmcDumpMgr = bmcDumpMgr.get();
72
Dhruvaraj Subhashchandran8b9b4692020-09-24 11:59:42 -050073 dumpMgrList.push_back(std::move(bmcDumpMgr));
74
Claire Weinan919f71c2022-03-01 19:02:07 -080075 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
Dhruvaraj Subhashchandran8b9b4692020-09-24 11:59:42 -050081 phosphor::dump::loadExtensions(bus, dumpMgrList);
82
83 // Restore dbus objects of all dumps
84 for (auto& dmpMgr : dumpMgrList)
85 {
86 dmpMgr->restore();
87 }
88
Dhruvaraj Subhashchandrane4350f92023-06-29 05:57:47 -050089 phosphor::dump::elog::Watch eWatch(bus, *ptrBmcDumpMgr);
90
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
Patrick Williams9e682c52022-04-01 17:03:45 -050093 // Daemon is all set up so claim the busname now.
94 bus.request_name(DUMP_BUSNAME);
95
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050096 auto rc = sd_event_loop(eventP.get());
97 if (rc < 0)
98 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050099 lg2::error("Error occurred during the sd_event_loop, rc: {RC}",
100 "RC", rc);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500101 elog<InternalFailure>();
102 }
103 }
Patrick Williams9d2d7222021-10-06 12:44:44 -0500104 catch (const InternalFailure& e)
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500105 {
106 commit<InternalFailure>();
107 return -1;
Jayanth Othayoth224882b2017-05-04 05:46:45 -0500108 }
109
110 return 0;
111}