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