1224882b0SJayanth Othayoth #include "config.h" 2cb65ffceSJayanth Othayoth 3a320c7caSJayanth Othayoth #include "dump_internal.hpp" 4cb65ffceSJayanth Othayoth #include "dump_manager.hpp" 5*fef66a95SDhruvaraj Subhashchandran #include "dump_manager_bmc.hpp" 6*fef66a95SDhruvaraj Subhashchandran #include "dump_manager_system.hpp" 7d0f0064eSJayanth Othayoth #include "elog_watch.hpp" 8cb65ffceSJayanth Othayoth #include "watch.hpp" 9cb65ffceSJayanth Othayoth #include "xyz/openbmc_project/Common/error.hpp" 10cb65ffceSJayanth Othayoth 11cb65ffceSJayanth Othayoth #include <phosphor-logging/elog-errors.hpp> 12cb65ffceSJayanth Othayoth #include <sdbusplus/bus.hpp> 13224882b0SJayanth Othayoth 14bb410df7SRamesh Iyyar int main() 15224882b0SJayanth Othayoth { 16a320c7caSJayanth Othayoth using namespace phosphor::logging; 17a320c7caSJayanth Othayoth using InternalFailure = 18a320c7caSJayanth Othayoth sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; 19a320c7caSJayanth Othayoth 20671fc7f3SJayanth Othayoth auto bus = sdbusplus::bus::new_default(); 21a320c7caSJayanth Othayoth sd_event* event = nullptr; 22a320c7caSJayanth Othayoth auto rc = sd_event_default(&event); 23a320c7caSJayanth Othayoth if (rc < 0) 24a320c7caSJayanth Othayoth { 25a320c7caSJayanth Othayoth log<level::ERR>("Error occurred during the sd_event_default", 2611eaab7bSGunnar Mills entry("RC=%d", rc)); 27a320c7caSJayanth Othayoth report<InternalFailure>(); 28a320c7caSJayanth Othayoth return rc; 29a320c7caSJayanth Othayoth } 30a320c7caSJayanth Othayoth phosphor::dump::EventPtr eventP{event}; 31a320c7caSJayanth Othayoth event = nullptr; 32224882b0SJayanth Othayoth 3319ad0e8aSAlexander Filippov // Blocking SIGCHLD is needed for calling sd_event_add_child 3419ad0e8aSAlexander Filippov sigset_t mask; 3519ad0e8aSAlexander Filippov if (sigemptyset(&mask) < 0) 3619ad0e8aSAlexander Filippov { 3719ad0e8aSAlexander Filippov log<level::ERR>("Unable to initialize signal set", 3819ad0e8aSAlexander Filippov entry("ERRNO=%d", errno)); 3919ad0e8aSAlexander Filippov return EXIT_FAILURE; 4019ad0e8aSAlexander Filippov } 4119ad0e8aSAlexander Filippov 4219ad0e8aSAlexander Filippov if (sigaddset(&mask, SIGCHLD) < 0) 4319ad0e8aSAlexander Filippov { 4419ad0e8aSAlexander Filippov log<level::ERR>("Unable to add signal to signal set", 4519ad0e8aSAlexander Filippov entry("ERRNO=%d", errno)); 4619ad0e8aSAlexander Filippov return EXIT_FAILURE; 4719ad0e8aSAlexander Filippov } 4819ad0e8aSAlexander Filippov 4919ad0e8aSAlexander Filippov // Block SIGCHLD first, so that the event loop can handle it 5019ad0e8aSAlexander Filippov if (sigprocmask(SIG_BLOCK, &mask, nullptr) < 0) 5119ad0e8aSAlexander Filippov { 5219ad0e8aSAlexander Filippov log<level::ERR>("Unable to block signal", entry("ERRNO=%d", errno)); 5319ad0e8aSAlexander Filippov return EXIT_FAILURE; 5419ad0e8aSAlexander Filippov } 5519ad0e8aSAlexander Filippov 56224882b0SJayanth Othayoth // Add sdbusplus ObjectManager for the 'root' path of the DUMP manager. 57224882b0SJayanth Othayoth sdbusplus::server::manager::manager objManager(bus, DUMP_OBJPATH); 58224882b0SJayanth Othayoth bus.request_name(DUMP_BUSNAME); 59224882b0SJayanth Othayoth 60a320c7caSJayanth Othayoth try 61224882b0SJayanth Othayoth { 62*fef66a95SDhruvaraj Subhashchandran phosphor::dump::bmc::Manager bmcDumpMgr( 63*fef66a95SDhruvaraj Subhashchandran bus, eventP, BMC_DUMP_OBJPATH, BMC_DUMP_OBJ_ENTRY, BMC_DUMP_PATH); 6443096598SJayanth Othayoth // Restore dump d-bus objects. 65*fef66a95SDhruvaraj Subhashchandran bmcDumpMgr.restore(); 66*fef66a95SDhruvaraj Subhashchandran phosphor::dump::bmc::internal::Manager mgr(bus, bmcDumpMgr, 67*fef66a95SDhruvaraj Subhashchandran OBJ_INTERNAL); 68*fef66a95SDhruvaraj Subhashchandran phosphor::dump::system::Manager systemDumpMgr(bus, SYSTEM_DUMP_OBJPATH, 69*fef66a95SDhruvaraj Subhashchandran SYSTEM_DUMP_OBJ_ENTRY); 70d0f0064eSJayanth Othayoth phosphor::dump::elog::Watch eWatch(bus, mgr); 71a320c7caSJayanth Othayoth bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL); 72bcb174bdSJayanth Othayoth 73a320c7caSJayanth Othayoth auto rc = sd_event_loop(eventP.get()); 74a320c7caSJayanth Othayoth if (rc < 0) 75a320c7caSJayanth Othayoth { 76a320c7caSJayanth Othayoth log<level::ERR>("Error occurred during the sd_event_loop", 7711eaab7bSGunnar Mills entry("RC=%d", rc)); 78a320c7caSJayanth Othayoth elog<InternalFailure>(); 79a320c7caSJayanth Othayoth } 80a320c7caSJayanth Othayoth } 81a320c7caSJayanth Othayoth catch (InternalFailure& e) 82a320c7caSJayanth Othayoth { 83a320c7caSJayanth Othayoth commit<InternalFailure>(); 84a320c7caSJayanth Othayoth return -1; 85224882b0SJayanth Othayoth } 86224882b0SJayanth Othayoth 87224882b0SJayanth Othayoth return 0; 88224882b0SJayanth Othayoth } 89