Set init_priority attribute for global/static variables

The initialization order of global/static variables and functions
with constructor attribute is unspecified.

Set init_priority attribute to specify the initialization order.

Resolves openbmc/openbmc#1581

Change-Id: Ia85804b3b9e537e0f32b712a3ce92e7d0be554b2
Signed-off-by: Lei YU <mine260309@gmail.com>
diff --git a/systemintfcmds.cpp b/systemintfcmds.cpp
index 23e81ba..b101016 100644
--- a/systemintfcmds.cpp
+++ b/systemintfcmds.cpp
@@ -144,11 +144,11 @@
     return rc;
 }
 
-// Globals to keep the object alive during process life
-std::unique_ptr<sdbusplus::bus::bus> sdbus = nullptr;
-// TODO openbmc/openbmc#1581 - unique_ptr causes seg fault
-phosphor::host::Host* host = nullptr;
-
+namespace {
+// Static storage to keep the object alive during process life
+std::unique_ptr<sdbusplus::bus::bus> sdbus __attribute__((init_priority(101)));
+std::unique_ptr<phosphor::host::Host> host __attribute__((init_priority(101)));
+}
 
 #include <unistd.h>
 void register_netfn_app_functions()
@@ -185,9 +185,9 @@
     // Get the sd_events pointer
     auto events = ipmid_get_sd_event_connection();
 
-    host = new phosphor::host::Host(*sdbus,
-                                    objPathInst.c_str(),
-                                    events);
+    host = std::make_unique<phosphor::host::Host>(*sdbus,
+                                                  objPathInst.c_str(),
+                                                  events);
 
     sdbus->request_name(CONTROL_HOST_BUSNAME);