blob: 68b0bc04dd450c267c6faecb14500242c02923ea [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"
Claire Weinan919f71c2022-03-01 19:02:07 -08007#include "dump_manager_faultlog.hpp"
Jayanth Othayothd0f00642017-09-04 06:26:30 -05008#include "elog_watch.hpp"
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -05009#include "watch.hpp"
10#include "xyz/openbmc_project/Common/error.hpp"
11
12#include <phosphor-logging/elog-errors.hpp>
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050013#include <phosphor-logging/lg2.hpp>
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050014#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 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050030 lg2::error("Error occurred during the sd_event_default, rc: {RC}", "RC",
31 rc);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050032 report<InternalFailure>();
33 return rc;
34 }
35 phosphor::dump::EventPtr eventP{event};
36 event = nullptr;
Jayanth Othayoth224882b2017-05-04 05:46:45 -050037
Alexander Filippov19ad0e82020-06-26 13:22:01 +030038 // Blocking SIGCHLD is needed for calling sd_event_add_child
39 sigset_t mask;
40 if (sigemptyset(&mask) < 0)
41 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050042 lg2::error("Unable to initialize signal set, errno: {ERRNO}", "ERRNO",
43 errno);
Alexander Filippov19ad0e82020-06-26 13:22:01 +030044 return EXIT_FAILURE;
45 }
46
47 if (sigaddset(&mask, SIGCHLD) < 0)
48 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050049 lg2::error("Unable to add signal to signal set, errno: {ERRNO}",
50 "ERRNO", errno);
Alexander Filippov19ad0e82020-06-26 13:22:01 +030051 return EXIT_FAILURE;
52 }
53
54 // Block SIGCHLD first, so that the event loop can handle it
55 if (sigprocmask(SIG_BLOCK, &mask, nullptr) < 0)
56 {
Dhruvaraj Subhashchandrand1f670f2023-06-05 22:19:25 -050057 lg2::error("Unable to block signal, errno: {ERRNO}", "ERRNO", errno);
Alexander Filippov19ad0e82020-06-26 13:22:01 +030058 return EXIT_FAILURE;
59 }
60
Jayanth Othayoth224882b2017-05-04 05:46:45 -050061 // Add sdbusplus ObjectManager for the 'root' path of the DUMP manager.
Patrick Williams9b18bf22022-07-22 19:26:55 -050062 sdbusplus::server::manager_t objManager(bus, DUMP_OBJPATH);
Jayanth Othayoth224882b2017-05-04 05:46:45 -050063
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050064 try
Jayanth Othayoth224882b2017-05-04 05:46:45 -050065 {
Dhruvaraj Subhashchandran8b9b4692020-09-24 11:59:42 -050066 phosphor::dump::DumpManagerList dumpMgrList{};
67 std::unique_ptr<phosphor::dump::bmc::Manager> bmcDumpMgr =
68 std::make_unique<phosphor::dump::bmc::Manager>(
69 bus, eventP, BMC_DUMP_OBJPATH, BMC_DUMP_OBJ_ENTRY,
70 BMC_DUMP_PATH);
71
72 phosphor::dump::bmc::internal::Manager mgr(bus, *bmcDumpMgr,
Dhruvaraj Subhashchandranfef66a92020-09-06 13:10:59 -050073 OBJ_INTERNAL);
Dhruvaraj Subhashchandran8b9b4692020-09-24 11:59:42 -050074 dumpMgrList.push_back(std::move(bmcDumpMgr));
75
Claire Weinan919f71c2022-03-01 19:02:07 -080076 std::unique_ptr<phosphor::dump::faultlog::Manager> faultLogMgr =
77 std::make_unique<phosphor::dump::faultlog::Manager>(
78 bus, FAULTLOG_DUMP_OBJPATH, FAULTLOG_DUMP_OBJ_ENTRY,
79 FAULTLOG_DUMP_PATH);
80 dumpMgrList.push_back(std::move(faultLogMgr));
81
Dhruvaraj Subhashchandran8b9b4692020-09-24 11:59:42 -050082 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
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}