Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 1 | #include "config.h" |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 2 | |
Dhruvaraj Subhashchandran | 8b9b469 | 2020-09-24 11:59:42 -0500 | [diff] [blame] | 3 | #include "dump-extensions.hpp" |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 4 | #include "dump_internal.hpp" |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 5 | #include "dump_manager.hpp" |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 6 | #include "dump_manager_bmc.hpp" |
Claire Weinan | 919f71c | 2022-03-01 19:02:07 -0800 | [diff] [blame] | 7 | #include "dump_manager_faultlog.hpp" |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 8 | #include "elog_watch.hpp" |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 9 | #include "watch.hpp" |
| 10 | #include "xyz/openbmc_project/Common/error.hpp" |
| 11 | |
| 12 | #include <phosphor-logging/elog-errors.hpp> |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 13 | #include <phosphor-logging/lg2.hpp> |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 14 | #include <sdbusplus/bus.hpp> |
Jayanth Othayoth | 0af74a5 | 2021-04-08 03:55:21 -0500 | [diff] [blame] | 15 | |
| 16 | #include <memory> |
Dhruvaraj Subhashchandran | 8b9b469 | 2020-09-24 11:59:42 -0500 | [diff] [blame] | 17 | #include <vector> |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 18 | |
Ramesh Iyyar | bb410df | 2020-08-03 03:13:04 -0500 | [diff] [blame] | 19 | int main() |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 20 | { |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 21 | using namespace phosphor::logging; |
| 22 | using InternalFailure = |
| 23 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
| 24 | |
Jayanth Othayoth | 671fc7f | 2017-06-14 08:01:41 -0500 | [diff] [blame] | 25 | auto bus = sdbusplus::bus::new_default(); |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 26 | sd_event* event = nullptr; |
| 27 | auto rc = sd_event_default(&event); |
| 28 | if (rc < 0) |
| 29 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 30 | lg2::error("Error occurred during the sd_event_default, rc: {RC}", "RC", |
| 31 | rc); |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 32 | report<InternalFailure>(); |
| 33 | return rc; |
| 34 | } |
| 35 | phosphor::dump::EventPtr eventP{event}; |
| 36 | event = nullptr; |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 37 | |
Alexander Filippov | 19ad0e8 | 2020-06-26 13:22:01 +0300 | [diff] [blame] | 38 | // Blocking SIGCHLD is needed for calling sd_event_add_child |
| 39 | sigset_t mask; |
| 40 | if (sigemptyset(&mask) < 0) |
| 41 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 42 | lg2::error("Unable to initialize signal set, errno: {ERRNO}", "ERRNO", |
| 43 | errno); |
Alexander Filippov | 19ad0e8 | 2020-06-26 13:22:01 +0300 | [diff] [blame] | 44 | return EXIT_FAILURE; |
| 45 | } |
| 46 | |
| 47 | if (sigaddset(&mask, SIGCHLD) < 0) |
| 48 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 49 | lg2::error("Unable to add signal to signal set, errno: {ERRNO}", |
| 50 | "ERRNO", errno); |
Alexander Filippov | 19ad0e8 | 2020-06-26 13:22:01 +0300 | [diff] [blame] | 51 | 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 Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 57 | lg2::error("Unable to block signal, errno: {ERRNO}", "ERRNO", errno); |
Alexander Filippov | 19ad0e8 | 2020-06-26 13:22:01 +0300 | [diff] [blame] | 58 | return EXIT_FAILURE; |
| 59 | } |
| 60 | |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 61 | // Add sdbusplus ObjectManager for the 'root' path of the DUMP manager. |
Patrick Williams | 9b18bf2 | 2022-07-22 19:26:55 -0500 | [diff] [blame] | 62 | sdbusplus::server::manager_t objManager(bus, DUMP_OBJPATH); |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 63 | |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 64 | try |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 65 | { |
Dhruvaraj Subhashchandran | 8b9b469 | 2020-09-24 11:59:42 -0500 | [diff] [blame] | 66 | 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 Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 73 | OBJ_INTERNAL); |
Dhruvaraj Subhashchandran | 8b9b469 | 2020-09-24 11:59:42 -0500 | [diff] [blame] | 74 | dumpMgrList.push_back(std::move(bmcDumpMgr)); |
| 75 | |
Claire Weinan | 919f71c | 2022-03-01 19:02:07 -0800 | [diff] [blame] | 76 | 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 Subhashchandran | 8b9b469 | 2020-09-24 11:59:42 -0500 | [diff] [blame] | 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 Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 90 | phosphor::dump::elog::Watch eWatch(bus, mgr); |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 91 | bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL); |
Jayanth Othayoth | bcb174b | 2017-07-02 06:29:24 -0500 | [diff] [blame] | 92 | |
Patrick Williams | 9e682c5 | 2022-04-01 17:03:45 -0500 | [diff] [blame] | 93 | // Daemon is all set up so claim the busname now. |
| 94 | bus.request_name(DUMP_BUSNAME); |
| 95 | |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 96 | auto rc = sd_event_loop(eventP.get()); |
| 97 | if (rc < 0) |
| 98 | { |
Dhruvaraj Subhashchandran | d1f670f | 2023-06-05 22:19:25 -0500 | [diff] [blame] | 99 | lg2::error("Error occurred during the sd_event_loop, rc: {RC}", |
| 100 | "RC", rc); |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 101 | elog<InternalFailure>(); |
| 102 | } |
| 103 | } |
Patrick Williams | 9d2d722 | 2021-10-06 12:44:44 -0500 | [diff] [blame] | 104 | catch (const InternalFailure& e) |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 105 | { |
| 106 | commit<InternalFailure>(); |
| 107 | return -1; |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | return 0; |
| 111 | } |