}
}
+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();
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",
-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);
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");