Add getDecodedPath for decoding unit name 96/182696/4
authorseolheui kim <s414.kim@samsung.com>
Wed, 27 Jun 2018 07:01:20 +0000 (16:01 +0900)
committerseolheui kim <s414.kim@samsung.com>
Mon, 9 Jul 2018 08:55:43 +0000 (17:55 +0900)
Change-Id: I7a1d4afe615e4369d33c0f64755d7e80e23891cf
Signed-off-by: seolheui kim <s414.kim@samsung.com>
server/internal-encryption.cpp

index f0df17f04e980a2242836dc0e7b8d883d127dff1..3fc0cd7185b0c2b971b80451d03b2cd5d1052286 100644 (file)
@@ -184,6 +184,28 @@ void stopKnownSystemdUnits()
        }
 }
 
+std::string getDecodedPath(const std::string &path, const std::string &prefix)
+{
+       std::string ret = path;
+       size_t pos = 0;
+
+       pos = ret.find(prefix);
+       if (pos != std::string::npos)
+               ret = ret.substr(prefix.size(), ret.size());
+
+       pos = 0;
+       while ((pos = ret.find("_", pos)) != std::string::npos) {
+               int a = std::stoi(std::string(1, ret.at(pos+1)), nullptr, 16);
+               int b = std::stoi(std::string(1, ret.at(pos+2)), nullptr, 16);
+               if (a < 0 || b < 0)
+                       ret.replace(pos, 3, "_");
+               else
+                       ret.replace(pos, 3, std::string(1, ((a << 4) | b)));
+               pos += 1;
+       }
+       return ret;
+}
+
 void stopDependedSystemdUnits()
 {
        dbus::Connection& systemDBus = dbus::Connection::getSystem();
@@ -192,7 +214,7 @@ void stopDependedSystemdUnits()
 
        for (pid_t pid : runtime::FileUser::getList(INTERNAL_PATH, true)) {
                try {
-                       char *unit;
+                       char *unit = nullptr;
                        systemDBus.methodcall("org.freedesktop.systemd1",
                                                                        "/org/freedesktop/systemd1",
                                                                        "org.freedesktop.systemd1.Manager",
@@ -200,11 +222,11 @@ void stopDependedSystemdUnits()
                                                                        -1, "(o)", "(u)", (unsigned int)pid)
                                                                                .get("(o)", &unit);
 
-                       if (std::string(unit) ==
-                                       "/org/freedesktop/systemd1/unit/samsung_2dlog_2dmgr_2eservice")
+                       auto unescapedName = getDecodedPath(unit, "/org/freedesktop/systemd1/unit/");
+                       if (unescapedName == "samsung-log-mgr.service")
                                p = pid;
                        else
-                               unitsToStop.insert(unit);
+                               unitsToStop.insert(unescapedName);
                } catch (runtime::Exception &e) {
                        INFO(SINK, "Killing process: " + std::to_string(pid));
                        ::kill(pid, SIGKILL);
@@ -217,10 +239,10 @@ void stopDependedSystemdUnits()
                INFO(SINK, "Stopping unit: " + unit);
                const char* job = NULL;
                systemDBus.methodcall("org.freedesktop.systemd1",
-                                                               unit,
-                                                               "org.freedesktop.systemd1.Unit",
-                                                               "Stop",
-                                                               -1, "(o)", "(s)", "flush").get("(o)", &job);
+                                                               "/org/freedesktop/systemd1",
+                                                               "org.freedesktop.systemd1.Manager",
+                                                               "StopUnit",
+                                                               -1, "(o)", "(ss)", unit.c_str(), "flush").get("(o)", &job);
                INFO(SINK, "Waiting for job: " + std::string(job));
                if (!watch.waitForJob(job))
                        throw runtime::Exception("Stopping unit: " + unit + " failed");