1 #include "config.h" 2 3 #include "dump-extensions.hpp" 4 #include "dump_internal.hpp" 5 #include "dump_manager.hpp" 6 #include "dump_manager_bmc.hpp" 7 #include "elog_watch.hpp" 8 #include "watch.hpp" 9 #include "xyz/openbmc_project/Common/error.hpp" 10 11 #include <memory> 12 #include <phosphor-logging/elog-errors.hpp> 13 #include <sdbusplus/bus.hpp> 14 #include <vector> 15 16 int main() 17 { 18 using namespace phosphor::logging; 19 using InternalFailure = 20 sdbusplus::xyz::openbmc_project::Common::Error::InternalFailure; 21 22 auto bus = sdbusplus::bus::new_default(); 23 sd_event* event = nullptr; 24 auto rc = sd_event_default(&event); 25 if (rc < 0) 26 { 27 log<level::ERR>("Error occurred during the sd_event_default", 28 entry("RC=%d", rc)); 29 report<InternalFailure>(); 30 return rc; 31 } 32 phosphor::dump::EventPtr eventP{event}; 33 event = nullptr; 34 35 // Blocking SIGCHLD is needed for calling sd_event_add_child 36 sigset_t mask; 37 if (sigemptyset(&mask) < 0) 38 { 39 log<level::ERR>("Unable to initialize signal set", 40 entry("ERRNO=%d", errno)); 41 return EXIT_FAILURE; 42 } 43 44 if (sigaddset(&mask, SIGCHLD) < 0) 45 { 46 log<level::ERR>("Unable to add signal to signal set", 47 entry("ERRNO=%d", errno)); 48 return EXIT_FAILURE; 49 } 50 51 // Block SIGCHLD first, so that the event loop can handle it 52 if (sigprocmask(SIG_BLOCK, &mask, nullptr) < 0) 53 { 54 log<level::ERR>("Unable to block signal", entry("ERRNO=%d", errno)); 55 return EXIT_FAILURE; 56 } 57 58 // Add sdbusplus ObjectManager for the 'root' path of the DUMP manager. 59 sdbusplus::server::manager::manager objManager(bus, DUMP_OBJPATH); 60 bus.request_name(DUMP_BUSNAME); 61 62 try 63 { 64 phosphor::dump::DumpManagerList dumpMgrList{}; 65 std::unique_ptr<phosphor::dump::bmc::Manager> bmcDumpMgr = 66 std::make_unique<phosphor::dump::bmc::Manager>( 67 bus, eventP, BMC_DUMP_OBJPATH, BMC_DUMP_OBJ_ENTRY, 68 BMC_DUMP_PATH); 69 70 phosphor::dump::bmc::internal::Manager mgr(bus, *bmcDumpMgr, 71 OBJ_INTERNAL); 72 dumpMgrList.push_back(std::move(bmcDumpMgr)); 73 74 phosphor::dump::loadExtensions(bus, dumpMgrList); 75 76 // Restore dbus objects of all dumps 77 for (auto& dmpMgr : dumpMgrList) 78 { 79 dmpMgr->restore(); 80 } 81 82 phosphor::dump::elog::Watch eWatch(bus, mgr); 83 bus.attach_event(eventP.get(), SD_EVENT_PRIORITY_NORMAL); 84 85 auto rc = sd_event_loop(eventP.get()); 86 if (rc < 0) 87 { 88 log<level::ERR>("Error occurred during the sd_event_loop", 89 entry("RC=%d", rc)); 90 elog<InternalFailure>(); 91 } 92 } 93 catch (InternalFailure& e) 94 { 95 commit<InternalFailure>(); 96 return -1; 97 } 98 99 return 0; 100 } 101