1 #include "config.h"
2 
3 #include "config_main.h"
4 
5 #include "extensions.hpp"
6 #include "log_manager.hpp"
7 #include "paths.hpp"
8 
9 #include <phosphor-logging/lg2.hpp>
10 #include <sdbusplus/bus.hpp>
11 #include <sdbusplus/server/manager.hpp>
12 #include <sdeventplus/event.hpp>
13 
14 #include <filesystem>
15 
16 int main(int argc, char* argv[])
17 {
18     PHOSPHOR_LOG2_USING_WITH_FLAGS;
19 
20     if (argc >= 2)
21     {
22         PERSIST_PATH_ROOT = strdup(argv[1]);
23         info("Using temporary {PATH} for logs", "PATH", PERSIST_PATH_ROOT);
24     }
25 
26     auto bus = sdbusplus::bus::new_default();
27     auto event = sdeventplus::Event::get_default();
28     bus.attach_event(event.get(), SD_EVENT_PRIORITY_NORMAL);
29 
30     // Add sdbusplus ObjectManager for the 'root' path of the logging manager.
31     sdbusplus::server::manager_t objManager(bus, OBJ_LOGGING);
32 
33     phosphor::logging::internal::Manager iMgr(bus, OBJ_INTERNAL);
34 
35     phosphor::logging::Manager mgr(bus, OBJ_LOGGING, iMgr);
36 
37     // Create a directory to persist errors.
38     std::filesystem::create_directories(phosphor::logging::paths::error());
39 
40     // Recreate error d-bus objects from persisted errors.
41     iMgr.restore();
42 
43     for (auto& startup : phosphor::logging::Extensions::getStartupFunctions())
44     {
45         try
46         {
47             startup(iMgr);
48         }
49         catch (const std::exception& e)
50         {
51             error("An extension's startup function threw an exception: {ERROR}",
52                   "ERROR", e);
53         }
54     }
55 
56     bus.request_name(BUSNAME_LOGGING);
57 
58     return event.loop();
59 }
60