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