blob: 173b6e5f7021353ee6fa414ab1dae96861083c09 [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"
Patrick Williamsfa2d9622024-09-30 16:25:43 -04007#include "paths.hpp"
Adriana Kobylak8f7941e2016-11-14 14:46:23 -06008
Patrick Williams5f285c52021-07-27 21:25:38 -05009#include <phosphor-logging/lg2.hpp>
Patrick Venturef18bf832018-10-26 18:14:00 -070010#include <sdbusplus/bus.hpp>
11#include <sdbusplus/server/manager.hpp>
Matt Spinler8ebfd312019-06-03 12:43:59 -050012#include <sdeventplus/event.hpp>
Patrick Venturef18bf832018-10-26 18:14:00 -070013
Patrick Williams2544b412022-10-04 08:41:06 -050014#include <filesystem>
William A. Kennington IIIb6b25572021-05-19 17:09:41 -070015
Patrick Williamsfa2d9622024-09-30 16:25:43 -040016int main(int argc, char* argv[])
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060017{
Patrick Williams5f285c52021-07-27 21:25:38 -050018 PHOSPHOR_LOG2_USING_WITH_FLAGS;
19
Patrick Williams79f206b2024-10-03 09:53:18 -040020 if (argc >= 2)
Patrick Williamsfa2d9622024-09-30 16:25:43 -040021 {
22 PERSIST_PATH_ROOT = strdup(argv[1]);
23 info("Using temporary {PATH} for logs", "PATH", PERSIST_PATH_ROOT);
24 }
25
Adriana Kobylakf477fe22017-01-06 11:56:41 -060026 auto bus = sdbusplus::bus::new_default();
Matt Spinler8ebfd312019-06-03 12:43:59 -050027 auto event = sdeventplus::Event::get_default();
28 bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
Adriana Kobylakf477fe22017-01-06 11:56:41 -060029
Adriana Kobylak70bb6bc2017-02-21 19:51:52 -060030 // Add sdbusplus ObjectManager for the 'root' path of the logging manager.
Patrick Williams45e83522022-07-22 19:26:52 -050031 sdbusplus::server::manager_t objManager(bus, OBJ_LOGGING);
Adriana Kobylakf477fe22017-01-06 11:56:41 -060032
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050033 phosphor::logging::internal::Manager iMgr(bus, OBJ_INTERNAL);
34
35 phosphor::logging::Manager mgr(bus, OBJ_LOGGING, iMgr);
Adriana Kobylakf477fe22017-01-06 11:56:41 -060036
Deepak Kodihalli72654f12017-06-12 04:33:29 -050037 // Create a directory to persist errors.
Patrick Williamsfa2d9622024-09-30 16:25:43 -040038 std::filesystem::create_directories(phosphor::logging::paths::error());
Deepak Kodihalli72654f12017-06-12 04:33:29 -050039
40 // Recreate error d-bus objects from persisted errors.
Nagaraju Goruganti05aae8b2017-08-30 07:56:12 -050041 iMgr.restore();
Deepak Kodihalli72654f12017-06-12 04:33:29 -050042
Matt Spinler99c2b402019-05-23 14:29:16 -050043 for (auto& startup : phosphor::logging::Extensions::getStartupFunctions())
44 {
45 try
46 {
47 startup(iMgr);
48 }
Patrick Williams66491c62021-10-06 12:23:37 -050049 catch (const std::exception& e)
Matt Spinler99c2b402019-05-23 14:29:16 -050050 {
Patrick Williams5f285c52021-07-27 21:25:38 -050051 error("An extension's startup function threw an exception: {ERROR}",
52 "ERROR", e);
Matt Spinler99c2b402019-05-23 14:29:16 -050053 }
54 }
55
Matt Spinler68603192022-01-20 16:35:53 -060056 bus.request_name(BUSNAME_LOGGING);
57
Matt Spinler8ebfd312019-06-03 12:43:59 -050058 return event.loop();
Adriana Kobylak8f7941e2016-11-14 14:46:23 -060059}