From bbe728c374d2583596e628c88c0d8110836f021d Mon Sep 17 00:00:00 2001 From: arun-pm Date: Fri, 10 Jan 2020 15:18:04 +0530 Subject: [user-mgmt]: Rearrange signal handler registration Currently, signal handler are registered after the GetManagedObjects query. This may miss any signals generated in-between this time. Correct flow must be to register for the signal first, followed by GetManagedObjects query. Tested: 1. Verified that user list are properly listed after this change. Note: Also, performed following tests to determine the order didn't cause any problem. Verified with both ipmi_user.json deleted and preserved. 2. Started phosphor-user-manager after host-ipmid. 3. Re-started phosphor-user-manager. 4. Started phosphor-host-ipmid after phosphor-user-manager. 5. Restarted phosphor-host-ipmid. Change-Id: I124b5e96672e0456289bca7a2b889e4b897c0545 Signed-off-by: arun-pm --- user_channel/user_mgmt.cpp | 74 +++++++++++++++++++++++----------------------- user_channel/user_mgmt.hpp | 3 +- 2 files changed, 39 insertions(+), 38 deletions(-) diff --git a/user_channel/user_mgmt.cpp b/user_channel/user_mgmt.cpp index 6b9d1d3..a8d2219 100644 --- a/user_channel/user_mgmt.cpp +++ b/user_channel/user_mgmt.cpp @@ -471,43 +471,8 @@ UserAccess::UserAccess() : bus(ipmid_get_sd_bus_connection()) userMutex = std::make_unique( boost::interprocess::open_or_create, ipmiUserMutex); - initUserDataFile(); + cacheUserDataFile(); getSystemPrivAndGroups(); - sigHndlrLock = boost::interprocess::file_lock(ipmiUserDataFile); - // Register it for single object and single process either netipimd / - // host-ipmid - if (userUpdatedSignal == nullptr && sigHndlrLock.try_lock()) - { - log("Registering signal handler"); - userUpdatedSignal = std::make_unique( - bus, - sdbusplus::bus::match::rules::type::signal() + - sdbusplus::bus::match::rules::interface(dBusObjManager) + - sdbusplus::bus::match::rules::path(userMgrObjBasePath), - [&](sdbusplus::message::message& msg) { - userUpdatedSignalHandler(*this, msg); - }); - userMgrRenamedSignal = std::make_unique( - bus, - sdbusplus::bus::match::rules::type::signal() + - sdbusplus::bus::match::rules::interface(userMgrInterface) + - sdbusplus::bus::match::rules::path(userMgrObjBasePath), - [&](sdbusplus::message::message& msg) { - userUpdatedSignalHandler(*this, msg); - }); - userPropertiesSignal = std::make_unique( - bus, - sdbusplus::bus::match::rules::type::signal() + - sdbusplus::bus::match::rules::path_namespace(userObjBasePath) + - sdbusplus::bus::match::rules::interface( - dBusPropertiesInterface) + - sdbusplus::bus::match::rules::member(propertiesChangedSignal) + - sdbusplus::bus::match::rules::argN(0, usersInterface), - [&](sdbusplus::message::message& msg) { - userUpdatedSignalHandler(*this, msg); - }); - signalHndlrObject = true; - } } UserInfo* UserAccess::getUserInfo(const uint8_t userId) @@ -1569,7 +1534,7 @@ int UserAccess::getUserObjProperties(const DbusUserObjValue& userObjs, return -EIO; } -void UserAccess::initUserDataFile() +void UserAccess::cacheUserDataFile() { boost::interprocess::scoped_lock userLock{*userMutex}; @@ -1596,6 +1561,41 @@ void UserAccess::initUserDataFile() } writeUserData(); } + sigHndlrLock = boost::interprocess::file_lock(ipmiUserDataFile); + // Register it for single object and single process either netipimd / + // host-ipmid + if (userUpdatedSignal == nullptr && sigHndlrLock.try_lock()) + { + log("Registering signal handler"); + userUpdatedSignal = std::make_unique( + bus, + sdbusplus::bus::match::rules::type::signal() + + sdbusplus::bus::match::rules::interface(dBusObjManager) + + sdbusplus::bus::match::rules::path(userMgrObjBasePath), + [&](sdbusplus::message::message& msg) { + userUpdatedSignalHandler(*this, msg); + }); + userMgrRenamedSignal = std::make_unique( + bus, + sdbusplus::bus::match::rules::type::signal() + + sdbusplus::bus::match::rules::interface(userMgrInterface) + + sdbusplus::bus::match::rules::path(userMgrObjBasePath), + [&](sdbusplus::message::message& msg) { + userUpdatedSignalHandler(*this, msg); + }); + userPropertiesSignal = std::make_unique( + bus, + sdbusplus::bus::match::rules::type::signal() + + sdbusplus::bus::match::rules::path_namespace(userObjBasePath) + + sdbusplus::bus::match::rules::interface( + dBusPropertiesInterface) + + sdbusplus::bus::match::rules::member(propertiesChangedSignal) + + sdbusplus::bus::match::rules::argN(0, usersInterface), + [&](sdbusplus::message::message& msg) { + userUpdatedSignalHandler(*this, msg); + }); + signalHndlrObject = true; + } std::map managedObjs; try { diff --git a/user_channel/user_mgmt.hpp b/user_channel/user_mgmt.hpp index 0c38374..054c0e2 100644 --- a/user_channel/user_mgmt.hpp +++ b/user_channel/user_mgmt.hpp @@ -392,8 +392,9 @@ class UserAccess void getSystemPrivAndGroups(); /** @brief function to init user data from configuration & D-Bus objects + * and to register for signals * */ - void initUserDataFile(); + void cacheUserDataFile(); }; } // namespace ipmi -- cgit v1.2.1