blob: 402cea338d3e55ffd66f14c04488c13285a7029d [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
George Liu858fbb22021-07-01 12:25:44 +080012#include <fmt/core.h>
13
Jayanth Othayothcb65ffc2018-10-16 08:29:32 -050014#include <phosphor-logging/elog-errors.hpp>
15#include <sdbusplus/bus.hpp>
Jayanth Othayoth0af74a52021-04-08 03:55:21 -050016
17#include <memory>
Dhruvaraj Subhashchandran8b9b4692020-09-24 11:59:42 -050018#include <vector>
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050019
Ramesh Iyyarbb410df2020-08-03 03:13:04 -050020int main()
Jayanth Othayoth224882b2017-05-04 05:46:45 -050021{
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050022 using namespace phosphor::logging;
23 using InternalFailure =
24 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure;
25
Jayanth Othayoth671fc7f2017-06-14 08:01:41 -050026 auto bus = sdbusplus::bus::new_default();
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050027 sd_event* event = nullptr;
28 auto rc = sd_event_default(&event);
29 if (rc < 0)
30 {
George Liu858fbb22021-07-01 12:25:44 +080031 log<level::ERR>(
32 fmt::format("Error occurred during the sd_event_default, rc({})",
33 rc)
34 .c_str());
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050035 report<InternalFailure>();
36 return rc;
37 }
38 phosphor::dump::EventPtr eventP{event};
39 event = nullptr;
Jayanth Othayoth224882b2017-05-04 05:46:45 -050040
Alexander Filippov19ad0e82020-06-26 13:22:01 +030041 // Blocking SIGCHLD is needed for calling sd_event_add_child
42 sigset_t mask;
43 if (sigemptyset(&mask) < 0)
44 {
George Liu858fbb22021-07-01 12:25:44 +080045 log<level::ERR>(
46 fmt::format("Unable to initialize signal set, errno({})", errno)
47 .c_str());
Alexander Filippov19ad0e82020-06-26 13:22:01 +030048 return EXIT_FAILURE;
49 }
50
51 if (sigaddset(&mask, SIGCHLD) < 0)
52 {
George Liu858fbb22021-07-01 12:25:44 +080053 log<level::ERR>(
54 fmt::format("Unable to add signal to signal set, errno({})", errno)
55 .c_str());
Alexander Filippov19ad0e82020-06-26 13:22:01 +030056 return EXIT_FAILURE;
57 }
58
59 // Block SIGCHLD first, so that the event loop can handle it
60 if (sigprocmask(SIG_BLOCK, &mask, nullptr) < 0)
61 {
George Liu858fbb22021-07-01 12:25:44 +080062 log<level::ERR>(
63 fmt::format("Unable to block signal, errno({})", errno).c_str());
Alexander Filippov19ad0e82020-06-26 13:22:01 +030064 return EXIT_FAILURE;
65 }
66
Jayanth Othayoth224882b2017-05-04 05:46:45 -050067 // Add sdbusplus ObjectManager for the 'root' path of the DUMP manager.
Patrick Williams9b18bf22022-07-22 19:26:55 -050068 sdbusplus::server::manager_t objManager(bus, DUMP_OBJPATH);
Jayanth Othayoth224882b2017-05-04 05:46:45 -050069
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
Claire Weinan919f71c2022-03-01 19:02:07 -080082 std::unique_ptr<phosphor::dump::faultlog::Manager> faultLogMgr =
83 std::make_unique<phosphor::dump::faultlog::Manager>(
84 bus, FAULTLOG_DUMP_OBJPATH, FAULTLOG_DUMP_OBJ_ENTRY,
85 FAULTLOG_DUMP_PATH);
86 dumpMgrList.push_back(std::move(faultLogMgr));
87
Dhruvaraj Subhashchandran8b9b4692020-09-24 11:59:42 -050088 phosphor::dump::loadExtensions(bus, dumpMgrList);
89
90 // Restore dbus objects of all dumps
91 for (auto& dmpMgr : dumpMgrList)
92 {
93 dmpMgr->restore();
94 }
95
Jayanth Othayothd0f00642017-09-04 06:26:30 -050096 phosphor::dump::elog::Watch eWatch(bus, mgr);
Jayanth Othayotha320c7c2017-06-14 07:17:21 -050097 bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL);
Jayanth Othayothbcb174b2017-07-02 06:29:24 -050098
Patrick Williams9e682c52022-04-01 17:03:45 -050099 // Daemon is all set up so claim the busname now.
100 bus.request_name(DUMP_BUSNAME);
101
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500102 auto rc = sd_event_loop(eventP.get());
103 if (rc < 0)
104 {
George Liu858fbb22021-07-01 12:25:44 +0800105 log<level::ERR>(
106 fmt::format("Error occurred during the sd_event_loop, rc({})",
107 rc)
108 .c_str());
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500109 elog<InternalFailure>();
110 }
111 }
Patrick Williams9d2d7222021-10-06 12:44:44 -0500112 catch (const InternalFailure& e)
Jayanth Othayotha320c7c2017-06-14 07:17:21 -0500113 {
114 commit<InternalFailure>();
115 return -1;
Jayanth Othayoth224882b2017-05-04 05:46:45 -0500116 }
117
118 return 0;
119}