Fix to improve failing umount before internal encryption/decryption 94/116194/1
authorSungbae Yoo <sungbae.yoo@samsung.com>
Thu, 23 Feb 2017 09:08:41 +0000 (18:08 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Thu, 23 Feb 2017 09:12:51 +0000 (18:12 +0900)
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Change-Id: I717054c0e9edc0a79665b12db0b1732d7bbb46ba

server/internal-encryption.cpp

index c90b4c7..a5059ca 100644 (file)
@@ -87,19 +87,21 @@ void stopSystemdUserSessions() {
                }
 
                std::string service(dataStr[0]);
-                       if (service.compare(0, 5, "user@") == 0) {
-                               userSessionServices.push_back(service);
-                       }
+               if (service.compare(0, 5, "user@") == 0) {
+                       userSessionServices.push_back(service);
                }
+       }
 
-               for (const std::string& service : userSessionServices) {
-                       INFO("Stop service - " + service);
-                       systemDBus.methodcall("org.freedesktop.systemd1",
-                                                                       "/org/freedesktop/systemd1",
-                                                                       "org.freedesktop.systemd1.Manager",
-                                                                       "StopUnit",
-                                                                       -1, "", "(ss)", service.c_str(), "flush");
-               }
+       for (const std::string& service : userSessionServices) {
+               INFO("Stop service - " + service);
+               systemDBus.methodcall("org.freedesktop.systemd1",
+                                                               "/org/freedesktop/systemd1",
+                                                               "org.freedesktop.systemd1.Manager",
+                                                               "StopUnit",
+                                                               -1, "", "(ss)", service.c_str(), "flush");
+       }
+
+       sleep(1);
 }
 
 void stopDependedSystemdServices()
@@ -138,15 +140,19 @@ void showProgressUI(const std::string type) {
        std::string defaultUserHome(::tzplatform_getenv(TZ_USER_HOME));
        ::tzplatform_reset_user();
 
-       runtime::File shareDirectory("/opt/home/root/share");
-       if (!shareDirectory.exists()) {
-               shareDirectory.makeDirectory(true);
-       }
+       try {
+               runtime::File shareDirectory("/opt/home/root/share");
+               if (!shareDirectory.exists()) {
+                       shareDirectory.makeDirectory(true);
+               }
 
-       runtime::File elmConfigDir(shareDirectory.getPath() + "/.elementary");
-       if (!elmConfigDir.exists()) {
-               runtime::File defaultElmConfigDir(defaultUserHome + "/share/.elementary");
-               defaultElmConfigDir.copyTo(shareDirectory.getPath());
+               runtime::File elmConfigDir(shareDirectory.getPath() + "/.elementary");
+               if (!elmConfigDir.exists()) {
+                       runtime::File defaultElmConfigDir(defaultUserHome + "/share/.elementary");
+                       defaultElmConfigDir.copyTo(shareDirectory.getPath());
+               }
+       } catch (runtime::Exception &e) {
+               ERROR("Failed to set up elm configuration");
        }
 
        std::vector<std::string> args = {
@@ -260,8 +266,6 @@ int InternalEncryption::encrypt(const std::string& password, unsigned int option
        KeyManager::data MasterKey = keyManager.getMasterKey(pwData);
        auto encryptWorker = [MasterKey, options, this]() {
                try {
-                       showProgressUI("Encrypting");
-
                        INFO("Close all user sessions...");
                        stopSystemdUserSessions();
                        INFO("Close all processes using internal storage...");
@@ -274,6 +278,8 @@ int InternalEncryption::encrypt(const std::string& password, unsigned int option
                                stopDependedSystemdServices();
                        }
 
+                       showProgressUI("Encrypting");
+
                        INFO("Encryption started...");
                        engine->encrypt(MasterKey, options);
                        setOptions(options & getSupportedOptions());
@@ -311,8 +317,8 @@ int InternalEncryption::decrypt(const std::string& password)
        KeyManager::data MasterKey = keyManager.getMasterKey(pwData);
        auto decryptWorker = [MasterKey, this]() {
                try {
-                       showProgressUI("Decrypting");
-
+                       INFO("Close all user sessions...");
+                       stopSystemdUserSessions();
                        INFO("Close all processes using internal storage...");
                        stopDependedSystemdServices();
                        INFO("Umount internal storage...");
@@ -325,6 +331,8 @@ int InternalEncryption::decrypt(const std::string& password)
                                }
                        }
 
+                       showProgressUI("Decrypting");
+
                        INFO("Decryption started...");
                        engine->decrypt(MasterKey, getOptions());
                        INFO("Sync disk...");