blob: 207c93c2be6a9f8f2fe8a69477d7a420e336c2e9 [file] [log] [blame]
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06001#include "config.h"
Patrick Venturef18bf832018-10-26 18:14:00 -07002
Patrick Williams2544b412022-10-04 08:41:06 -05003#include "config_main.h"
4
Matt Spinler99c2b402019-05-23 14:29:16 -05005#include "extensions.hpp"
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06006#include "log_manager.hpp"
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06007
Patrick Williams5f285c52021-07-27 21:25:38 -05008#include <phosphor-logging/lg2.hpp>
Patrick Venturef18bf832018-10-26 18:14:00 -07009#include <sdbusplus/bus.hpp>
10#include <sdbusplus/server/manager.hpp>
Matt Spinler8ebfd312019-06-03 12:43:59 -050011#include <sdeventplus/event.hpp>
Patrick Venturef18bf832018-10-26 18:14:00 -070012
Patrick Williams2544b412022-10-04 08:41:06 -050013#include <filesystem>
William A. Kennington IIIb6b25572021-05-19 17:09:41 -070014
Patrick Williamsf40323d2021-04-16 15:35:17 -050015int main(int /*argc*/, char* /*argv*/[])
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060016{
Patrick Williams5f285c52021-07-27 21:25:38 -050017 PHOSPHOR_LOG2_USING_WITH_FLAGS;
18
Adriana Kobylakf477fe22017-01-06 11:56:41 -060019 auto bus = sdbusplus::bus::new_default();
Matt Spinler8ebfd312019-06-03 12:43:59 -050020 auto event = sdeventplus::Event::get_default();
21 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
Adriana Kobylakf477fe22017-01-06 11:56:41 -060022
Adriana Kobylak70bb6bc2017-02-21 19:51:52 -060023 // Add sdbusplus ObjectManager for the 'root' path of the logging manager.
Patrick Williams45e83522022-07-22 19:26:52 -050024 sdbusplus::server::manager_t objManager(bus, OBJ_LOGGING);
Adriana Kobylakf477fe22017-01-06 11:56:41 -060025
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050026 phosphor::logging::internal::Manager iMgr(bus, OBJ_INTERNAL);
27
28 phosphor::logging::Manager mgr(bus, OBJ_LOGGING, iMgr);
Adriana Kobylakf477fe22017-01-06 11:56:41 -060029
Deepak Kodihalli72654f12017-06-12 04:33:29 -050030 // Create a directory to persist errors.
Patrick Williams331c4852021-04-16 15:38:59 -050031 std::filesystem::create_directories(ERRLOG_PERSIST_PATH);
Deepak Kodihalli72654f12017-06-12 04:33:29 -050032
33 // Recreate error d-bus objects from persisted errors.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050034 iMgr.restore();
Deepak Kodihalli72654f12017-06-12 04:33:29 -050035
Matt Spinler99c2b402019-05-23 14:29:16 -050036 for (auto& startup : phosphor::logging::Extensions::getStartupFunctions())
37 {
38 try
39 {
40 startup(iMgr);
41 }
Patrick Williams66491c62021-10-06 12:23:37 -050042 catch (const std::exception& e)
Matt Spinler99c2b402019-05-23 14:29:16 -050043 {
Patrick Williams5f285c52021-07-27 21:25:38 -050044 error("An extension's startup function threw an exception: {ERROR}",
45 "ERROR", e);
Matt Spinler99c2b402019-05-23 14:29:16 -050046 }
47 }
48
Matt Spinler68603192022-01-20 16:35:53 -060049 bus.request_name(BUSNAME_LOGGING);
50
Matt Spinler8ebfd312019-06-03 12:43:59 -050051 return event.loop();
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060052}