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