From: seolheui kim Date: Wed, 17 Jan 2018 13:00:37 +0000 (+0900) Subject: Add server run method for maintenance mode. X-Git-Tag: accepted/tizen/4.0/unified/20180130.042107~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=21464161fb4baee294cf09aeb41efaf0d0f89685;p=platform%2Fcore%2Fsecurity%2Fdevice-policy-manager.git Add server run method for maintenance mode. Change-Id: Ibb0d5683c13ef04f9e4da9b2184b590fad445b56 Signed-off-by: seolheui kim --- diff --git a/server/main.cpp b/server/main.cpp index 902d92c..70ce62a 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -86,7 +86,7 @@ int main(int argc, char *argv[]) manager.loadPolicyPlugins(); manager.applyPolicies(); - manager.start(ondemand, timeout); + manager.run(ondemand, timeout); } catch (std::exception &e) { ERROR(DPM, e.what()); return EXIT_FAILURE; diff --git a/server/server.cpp b/server/server.cpp index a955c95..8d5d70f 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -43,6 +43,13 @@ const std::string PolicyPluginBase = PLUGIN_INSTALL_DIR; } // namespace +void DevicePolicyManager::modeChangeDispatcher(keynode_t *node, void *data) +{ + DevicePolicyManager *manager = reinterpret_cast(data); + if (!manager->getMaintenanceMode()) + manager->stop(); +} + DevicePolicyManager::DevicePolicyManager() : rmi::Service(PolicyManagerSocket) { @@ -62,6 +69,8 @@ DevicePolicyManager::~DevicePolicyManager() { if (policyApplyThread.joinable()) policyApplyThread.join(); + + ::vconf_ignore_key_changed(VCONFKEY_DPM_MODE_STATE, modeChangeDispatcher); } void DevicePolicyManager::loadPolicyPlugins() @@ -98,10 +107,11 @@ void DevicePolicyManager::initPolicyStorage() PolicyStorage::setBackend(backend); DEBUG(DPM, "Success to init policy-storage."); - bool mode = false; + int mode = 0; if(loadManagedClients() > 0) { - mode = true; + mode = 1; } + if(::vconf_set_bool(VCONFKEY_DPM_MODE_STATE, mode) != 0) { DEBUG(DPM, "VCONFKEY_DPM_MODE_STATE set failed."); } @@ -112,15 +122,31 @@ void DevicePolicyManager::applyPolicies() policyApplyThread = std::thread(PolicyStorage::notify); } +bool DevicePolicyManager::getMaintenanceMode() +{ + return loadManagedClients() > 0 ? true : false; +} + +void DevicePolicyManager::run(int activation, int timeout) +{ + if (getMaintenanceMode()) { + /* Maintenance mode */ + ::vconf_notify_key_changed(VCONFKEY_DPM_MODE_STATE, modeChangeDispatcher, reinterpret_cast(this)); + timeout = -1; + DEBUG(DPM, "Set maintenance mode"); + } + + start(activation, timeout); +} + int DevicePolicyManager::enroll(const std::string& name, uid_t uid) { int ret = PolicyStorage::enroll(name, uid); if(ret == 0) { - if(::vconf_set_bool(VCONFKEY_DPM_MODE_STATE, true) != 0) { + if(::vconf_set_bool(VCONFKEY_DPM_MODE_STATE, 1) != 0) { DEBUG(DPM, "VCONFKEY_DPM_MODE_STATE set failed."); } } - return ret; } @@ -129,12 +155,11 @@ int DevicePolicyManager::disenroll(const std::string& name, uid_t uid) int ret = PolicyStorage::unenroll(name, uid); if(ret == 0) { if(loadManagedClients() == 0) { - if(::vconf_set_bool(VCONFKEY_DPM_MODE_STATE, false) != 0) { + if(::vconf_set_bool(VCONFKEY_DPM_MODE_STATE, 0) != 0) { DEBUG(DPM, "VCONFKEY_DPM_MODE_STATE set failed."); } } } - return ret; } diff --git a/server/server.h b/server/server.h index d28f2a0..c65d770 100644 --- a/server/server.h +++ b/server/server.h @@ -21,6 +21,8 @@ #include #include +#include + #include #include #include @@ -39,6 +41,8 @@ public: void loadPolicyPlugins(); void applyPolicies(); + void run(int activation, int timeout); + private: void initPolicyStorage(); @@ -49,6 +53,9 @@ private: bool checkNewConnection(const rmi::Connection& connection); bool checkCloseConnection(const rmi::Connection& connection); + bool getMaintenanceMode(); + static void modeChangeDispatcher(keynode_t *node, void *data); + private: typedef std::unordered_map ClientRegistry; ClientRegistry clientRegistry;