Add preprocessUnits list to stop user session first 80/187780/2 accepted/tizen/4.0/unified/20180829.004848 submit/tizen_4.0/20180828.100016
authorseolheui, kim <s414.kim@samsung.com>
Tue, 28 Aug 2018 09:00:48 +0000 (18:00 +0900)
committerseolheui, kim <s414.kim@samsung.com>
Tue, 28 Aug 2018 09:19:36 +0000 (18:19 +0900)
Change-Id: I8ab93c13bd416e2bb11d5c09e4ee3b390ab974c6
Signed-off-by: seolheui, kim <s414.kim@samsung.com>
server/internal-encryption.cpp

index 1947f9d..05f756e 100644 (file)
@@ -155,9 +155,10 @@ std::string getDecodedPath(const std::string &path, const std::string &prefix)
        return ret;
 }
 
-void stopDependedSystemdUnits()
+void stopSystemdUnits()
 {
        dbus::Connection& systemDBus = dbus::Connection::getSystem();
+       std::set<std::string> preprocessUnits;
        std::set<std::string> unitsToStop;
 
        for (pid_t pid : runtime::FileUser::getList(INTERNAL_PATH, true)) {
@@ -171,20 +172,23 @@ void stopDependedSystemdUnits()
                                                                                .get("(o)", &unit);
 
                        auto unescapedName = getDecodedPath(unit, "/org/freedesktop/systemd1/unit/");
-                       unitsToStop.insert(unescapedName);
+                       if (unescapedName.compare(0, 5, "user@") == 0)
+                               preprocessUnits.insert(unescapedName);
+                       else
+                               unitsToStop.insert(unescapedName);
                } catch (runtime::Exception &e) {
                        INFO(SINK, "Killing process: " + std::to_string(pid));
                        ::kill(pid, SIGKILL);
                }
        }
 
-       JobWatch watch(systemDBus);
        for (auto unit : blackListSystemdUnits) {
                unitsToStop.erase(unitsToStop.find(unit));
        }
 
-       for (const std::string& unit : unitsToStop) {
+       auto stopUnit = [&systemDBus](const std::string &unit) {
                INFO(SINK, "Stopping unit: " + unit);
+               JobWatch watch(systemDBus);
                const char* job = NULL;
                systemDBus.methodcall("org.freedesktop.systemd1",
                                                                "/org/freedesktop/systemd1",
@@ -194,6 +198,14 @@ void stopDependedSystemdUnits()
                INFO(SINK, "Waiting for job: " + std::string(job));
                if (!watch.waitForJob(job))
                        throw runtime::Exception("Stopping unit: " + unit + " failed");
+       };
+
+       for (const std::string &unit : preprocessUnits) {
+               stopUnit(unit);
+       }
+
+       for (const std::string &unit : unitsToStop) {
+               stopUnit(unit);
        }
 }
 
@@ -423,7 +435,7 @@ int InternalEncryptionServer::umount()
 
        INFO(SINK, "Closing all processes using internal storage.");
        try {
-               stopDependedSystemdUnits();
+               stopSystemdUnits();
                INFO(SINK, "Umounting internal storage.");
                unmountInternalStorage("/dev/mapper/userdata");
                engine->umount();
@@ -460,7 +472,7 @@ int InternalEncryptionServer::encrypt(const std::string& password, unsigned int
 
                        if (!mntPaths.empty()) {
                                INFO(SINK, "Closing all processes using internal storage.");
-                               stopDependedSystemdUnits();
+                               stopSystemdUnits();
 
                                INFO(SINK, "Unmounting internal storage.");
                                unmountInternalStorage(source);
@@ -513,7 +525,7 @@ int InternalEncryptionServer::decrypt(const std::string& password)
 
                        if (engine->isMounted()) {
                                INFO(SINK, "Closing all processes using internal storage.");
-                               stopDependedSystemdUnits();
+                               stopSystemdUnits();
 
                                INFO(SINK, "Umounting internal storage.");
                                unmountInternalStorage("/dev/mapper/userdata");