blob: bcd0cbecc2cecbf2a3fd708b82c033e77ae93d26 [file] [log] [blame]
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06001#include "config.h"
Patrick Venturef18bf832018-10-26 18:14:00 -07002
Matt Spinler99c2b402019-05-23 14:29:16 -05003#include "extensions.hpp"
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06004#include "log_manager.hpp"
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06005
Patrick Williams331c4852021-04-16 15:38:59 -05006#include <filesystem>
Patrick Williams5f285c52021-07-27 21:25:38 -05007#include <phosphor-logging/lg2.hpp>
Patrick Venturef18bf832018-10-26 18:14:00 -07008#include <sdbusplus/bus.hpp>
9#include <sdbusplus/server/manager.hpp>
Matt Spinler8ebfd312019-06-03 12:43:59 -050010#include <sdeventplus/event.hpp>
Patrick Venturef18bf832018-10-26 18:14:00 -070011
William A. Kennington IIIb6b25572021-05-19 17:09:41 -070012#include "config_main.h"
13
Patrick Williamsf40323d2021-04-16 15:35:17 -050014int main(int /*argc*/, char* /*argv*/[])
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060015{
Patrick Williams5f285c52021-07-27 21:25:38 -050016 PHOSPHOR_LOG2_USING_WITH_FLAGS;
17
Adriana Kobylakf477fe22017-01-06 11:56:41 -060018 auto bus = sdbusplus::bus::new_default();
Matt Spinler8ebfd312019-06-03 12:43:59 -050019 auto event = sdeventplus::Event::get_default();
20 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
Adriana Kobylakf477fe22017-01-06 11:56:41 -060021
Adriana Kobylak70bb6bc2017-02-21 19:51:52 -060022 // Add sdbusplus ObjectManager for the 'root' path of the logging manager.
23 sdbusplus::server::manager::manager objManager(bus, OBJ_LOGGING);
Adriana Kobylakf477fe22017-01-06 11:56:41 -060024
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050025 phosphor::logging::internal::Manager iMgr(bus, OBJ_INTERNAL);
26
27 phosphor::logging::Manager mgr(bus, OBJ_LOGGING, iMgr);
Adriana Kobylakf477fe22017-01-06 11:56:41 -060028
Deepak Kodihalli72654f12017-06-12 04:33:29 -050029 // Create a directory to persist errors.
Patrick Williams331c4852021-04-16 15:38:59 -050030 std::filesystem::create_directories(ERRLOG_PERSIST_PATH);
Deepak Kodihalli72654f12017-06-12 04:33:29 -050031
32 // Recreate error d-bus objects from persisted errors.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050033 iMgr.restore();
Deepak Kodihalli72654f12017-06-12 04:33:29 -050034
Adriana Kobylakf477fe22017-01-06 11:56:41 -060035 bus.request_name(BUSNAME_LOGGING);
36
Matt Spinler99c2b402019-05-23 14:29:16 -050037 for (auto& startup : phosphor::logging::Extensions::getStartupFunctions())
38 {
39 try
40 {
41 startup(iMgr);
42 }
Patrick Williams66491c62021-10-06 12:23:37 -050043 catch (const std::exception& e)
Matt Spinler99c2b402019-05-23 14:29:16 -050044 {
Patrick Williams5f285c52021-07-27 21:25:38 -050045 error("An extension's startup function threw an exception: {ERROR}",
46 "ERROR", e);
Matt Spinler99c2b402019-05-23 14:29:16 -050047 }
48 }
49
Matt Spinler8ebfd312019-06-03 12:43:59 -050050 return event.loop();
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060051}