1224882b0SJayanth Othayoth #include "config.h" 2cb65ffceSJayanth Othayoth 3a320c7caSJayanth Othayoth #include "dump_internal.hpp" 4cb65ffceSJayanth Othayoth #include "dump_manager.hpp" 5d0f0064eSJayanth Othayoth #include "elog_watch.hpp" 6cb65ffceSJayanth Othayoth #include "watch.hpp" 7cb65ffceSJayanth Othayoth #include "xyz/openbmc_project/Common/error.hpp" 8cb65ffceSJayanth Othayoth 9cb65ffceSJayanth Othayoth #include <phosphor-logging/elog-errors.hpp> 10cb65ffceSJayanth Othayoth #include <sdbusplus/bus.hpp> 11224882b0SJayanth Othayoth 12*bb410df7SRamesh Iyyar int main() 13224882b0SJayanth Othayoth { 14a320c7caSJayanth Othayoth using namespace phosphor::logging; 15a320c7caSJayanth Othayoth using InternalFailure = 16a320c7caSJayanth Othayoth sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; 17a320c7caSJayanth Othayoth 18671fc7f3SJayanth Othayoth auto bus = sdbusplus::bus::new_default(); 19a320c7caSJayanth Othayoth sd_event* event = nullptr; 20a320c7caSJayanth Othayoth auto rc = sd_event_default(&event); 21a320c7caSJayanth Othayoth if (rc < 0) 22a320c7caSJayanth Othayoth { 23a320c7caSJayanth Othayoth log<level::ERR>("Error occurred during the sd_event_default", 2411eaab7bSGunnar Mills entry("RC=%d", rc)); 25a320c7caSJayanth Othayoth report<InternalFailure>(); 26a320c7caSJayanth Othayoth return rc; 27a320c7caSJayanth Othayoth } 28a320c7caSJayanth Othayoth phosphor::dump::EventPtr eventP{event}; 29a320c7caSJayanth Othayoth event = nullptr; 30224882b0SJayanth Othayoth 3119ad0e8aSAlexander Filippov // Blocking SIGCHLD is needed for calling sd_event_add_child 3219ad0e8aSAlexander Filippov sigset_t mask; 3319ad0e8aSAlexander Filippov if (sigemptyset(&mask) < 0) 3419ad0e8aSAlexander Filippov { 3519ad0e8aSAlexander Filippov log<level::ERR>("Unable to initialize signal set", 3619ad0e8aSAlexander Filippov entry("ERRNO=%d", errno)); 3719ad0e8aSAlexander Filippov return EXIT_FAILURE; 3819ad0e8aSAlexander Filippov } 3919ad0e8aSAlexander Filippov 4019ad0e8aSAlexander Filippov if (sigaddset(&mask, SIGCHLD) < 0) 4119ad0e8aSAlexander Filippov { 4219ad0e8aSAlexander Filippov log<level::ERR>("Unable to add signal to signal set", 4319ad0e8aSAlexander Filippov entry("ERRNO=%d", errno)); 4419ad0e8aSAlexander Filippov return EXIT_FAILURE; 4519ad0e8aSAlexander Filippov } 4619ad0e8aSAlexander Filippov 4719ad0e8aSAlexander Filippov // Block SIGCHLD first, so that the event loop can handle it 4819ad0e8aSAlexander Filippov if (sigprocmask(SIG_BLOCK, &mask, nullptr) < 0) 4919ad0e8aSAlexander Filippov { 5019ad0e8aSAlexander Filippov log<level::ERR>("Unable to block signal", entry("ERRNO=%d", errno)); 5119ad0e8aSAlexander Filippov return EXIT_FAILURE; 5219ad0e8aSAlexander Filippov } 5319ad0e8aSAlexander Filippov 54224882b0SJayanth Othayoth // Add sdbusplus ObjectManager for the 'root' path of the DUMP manager. 55224882b0SJayanth Othayoth sdbusplus::server::manager::manager objManager(bus, DUMP_OBJPATH); 56224882b0SJayanth Othayoth bus.request_name(DUMP_BUSNAME); 57224882b0SJayanth Othayoth 58a320c7caSJayanth Othayoth try 59224882b0SJayanth Othayoth { 60a320c7caSJayanth Othayoth phosphor::dump::Manager manager(bus, eventP, DUMP_OBJPATH); 6143096598SJayanth Othayoth // Restore dump d-bus objects. 6243096598SJayanth Othayoth manager.restore(); 63d3273eadSJayanth Othayoth phosphor::dump::internal::Manager mgr(bus, manager, OBJ_INTERNAL); 64d0f0064eSJayanth Othayoth phosphor::dump::elog::Watch eWatch(bus, mgr); 65a320c7caSJayanth Othayoth bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL); 66bcb174bdSJayanth Othayoth 67a320c7caSJayanth Othayoth auto rc = sd_event_loop(eventP.get()); 68a320c7caSJayanth Othayoth if (rc < 0) 69a320c7caSJayanth Othayoth { 70a320c7caSJayanth Othayoth log<level::ERR>("Error occurred during the sd_event_loop", 7111eaab7bSGunnar Mills entry("RC=%d", rc)); 72a320c7caSJayanth Othayoth elog<InternalFailure>(); 73a320c7caSJayanth Othayoth } 74a320c7caSJayanth Othayoth } 75a320c7caSJayanth Othayoth catch (InternalFailure& e) 76a320c7caSJayanth Othayoth { 77a320c7caSJayanth Othayoth commit<InternalFailure>(); 78a320c7caSJayanth Othayoth return -1; 79224882b0SJayanth Othayoth } 80224882b0SJayanth Othayoth 81224882b0SJayanth Othayoth return 0; 82224882b0SJayanth Othayoth } 83