From: seolheui, kim Date: Tue, 28 Aug 2018 09:00:48 +0000 (+0900) Subject: Add preprocessUnits list to stop user session first X-Git-Tag: submit/tizen_4.0/20180828.100016^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d540f673d2a22418708471b1ca04cae4144fc918;p=platform%2Fcore%2Fsecurity%2Fode.git Add preprocessUnits list to stop user session first Change-Id: I8ab93c13bd416e2bb11d5c09e4ee3b390ab974c6 Signed-off-by: seolheui, kim --- diff --git a/server/internal-encryption.cpp b/server/internal-encryption.cpp index 1947f9d..05f756e 100644 --- a/server/internal-encryption.cpp +++ b/server/internal-encryption.cpp @@ -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 preprocessUnits; std::set 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");