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