From 12c2db7947bf20f683950347e06a36bea1991d37 Mon Sep 17 00:00:00 2001 From: Lei YU Date: Mon, 15 May 2017 11:24:04 +0800 Subject: 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 --- systemintfcmds.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/systemintfcmds.cpp b/systemintfcmds.cpp index 23e81ba..b101016 100644 --- a/systemintfcmds.cpp +++ b/systemintfcmds.cpp @@ -144,11 +144,11 @@ ipmi_ret_t ipmi_app_set_bmc_global_enables(ipmi_netfn_t netfn, ipmi_cmd_t cmd, return rc; } -// Globals to keep the object alive during process life -std::unique_ptr 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 sdbus __attribute__((init_priority(101))); +std::unique_ptr host __attribute__((init_priority(101))); +} #include void register_netfn_app_functions() @@ -185,9 +185,9 @@ void register_netfn_app_functions() // 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(*sdbus, + objPathInst.c_str(), + events); sdbus->request_name(CONTROL_HOST_BUSNAME); -- cgit v1.2.1