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" |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 7 | #include "elog_watch.hpp" |
Jayanth Othayoth | cb65ffc | 2018-10-16 08:29:32 -0500 | [diff] [blame] | 8 | #include "watch.hpp" |
| 9 | #include "xyz/openbmc_project/Common/error.hpp" |
| 10 | |
| 11 | #include <phosphor-logging/elog-errors.hpp> |
| 12 | #include <sdbusplus/bus.hpp> |
Jayanth Othayoth | 0af74a5 | 2021-04-08 03:55:21 -0500 | [diff] [blame] | 13 | |
| 14 | #include <memory> |
Dhruvaraj Subhashchandran | 8b9b469 | 2020-09-24 11:59:42 -0500 | [diff] [blame] | 15 | #include <vector> |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 16 | |
Ramesh Iyyar | bb410df | 2020-08-03 03:13:04 -0500 | [diff] [blame] | 17 | int main() |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 18 | { |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 19 | using namespace phosphor::logging; |
| 20 | using InternalFailure = |
| 21 | sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; |
| 22 | |
Jayanth Othayoth | 671fc7f | 2017-06-14 08:01:41 -0500 | [diff] [blame] | 23 | auto bus = sdbusplus::bus::new_default(); |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 24 | sd_event* event = nullptr; |
| 25 | auto rc = sd_event_default(&event); |
| 26 | if (rc < 0) |
| 27 | { |
| 28 | log<level::ERR>("Error occurred during the sd_event_default", |
Gunnar Mills | 11eaab7 | 2017-10-19 16:07:31 -0500 | [diff] [blame] | 29 | entry("RC=%d", rc)); |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 30 | report<InternalFailure>(); |
| 31 | return rc; |
| 32 | } |
| 33 | phosphor::dump::EventPtr eventP{event}; |
| 34 | event = nullptr; |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 35 | |
Alexander Filippov | 19ad0e8 | 2020-06-26 13:22:01 +0300 | [diff] [blame] | 36 | // Blocking SIGCHLD is needed for calling sd_event_add_child |
| 37 | sigset_t mask; |
| 38 | if (sigemptyset(&mask) < 0) |
| 39 | { |
| 40 | log<level::ERR>("Unable to initialize signal set", |
| 41 | entry("ERRNO=%d", errno)); |
| 42 | return EXIT_FAILURE; |
| 43 | } |
| 44 | |
| 45 | if (sigaddset(&mask, SIGCHLD) < 0) |
| 46 | { |
| 47 | log<level::ERR>("Unable to add signal to signal set", |
| 48 | entry("ERRNO=%d", errno)); |
| 49 | return EXIT_FAILURE; |
| 50 | } |
| 51 | |
| 52 | // Block SIGCHLD first, so that the event loop can handle it |
| 53 | if (sigprocmask(SIG_BLOCK, &mask, nullptr) < 0) |
| 54 | { |
| 55 | log<level::ERR>("Unable to block signal", entry("ERRNO=%d", errno)); |
| 56 | return EXIT_FAILURE; |
| 57 | } |
| 58 | |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 59 | // Add sdbusplus ObjectManager for the 'root' path of the DUMP manager. |
| 60 | sdbusplus::server::manager::manager objManager(bus, DUMP_OBJPATH); |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 61 | bus.request_name(DUMP_BUSNAME); |
| 62 | |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 63 | try |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 64 | { |
Dhruvaraj Subhashchandran | 8b9b469 | 2020-09-24 11:59:42 -0500 | [diff] [blame] | 65 | 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 | |
| 71 | phosphor::dump::bmc::internal::Manager mgr(bus, *bmcDumpMgr, |
Dhruvaraj Subhashchandran | fef66a9 | 2020-09-06 13:10:59 -0500 | [diff] [blame] | 72 | OBJ_INTERNAL); |
Dhruvaraj Subhashchandran | 8b9b469 | 2020-09-24 11:59:42 -0500 | [diff] [blame] | 73 | dumpMgrList.push_back(std::move(bmcDumpMgr)); |
| 74 | |
| 75 | phosphor::dump::loadExtensions(bus, dumpMgrList); |
| 76 | |
| 77 | // Restore dbus objects of all dumps |
| 78 | for (auto& dmpMgr : dumpMgrList) |
| 79 | { |
| 80 | dmpMgr->restore(); |
| 81 | } |
| 82 | |
Jayanth Othayoth | d0f0064 | 2017-09-04 06:26:30 -0500 | [diff] [blame] | 83 | phosphor::dump::elog::Watch eWatch(bus, mgr); |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 84 | bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL); |
Jayanth Othayoth | bcb174b | 2017-07-02 06:29:24 -0500 | [diff] [blame] | 85 | |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 86 | auto rc = sd_event_loop(eventP.get()); |
| 87 | if (rc < 0) |
| 88 | { |
| 89 | log<level::ERR>("Error occurred during the sd_event_loop", |
Gunnar Mills | 11eaab7 | 2017-10-19 16:07:31 -0500 | [diff] [blame] | 90 | entry("RC=%d", rc)); |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 91 | elog<InternalFailure>(); |
| 92 | } |
| 93 | } |
Jayanth Othayoth | a320c7c | 2017-06-14 07:17:21 -0500 | [diff] [blame] | 94 | catch (InternalFailure& e) |
| 95 | { |
| 96 | commit<InternalFailure>(); |
| 97 | return -1; |
Jayanth Othayoth | 224882b | 2017-05-04 05:46:45 -0500 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | return 0; |
| 101 | } |