/*
- * Copyright (c) 2015-2017 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2015-2019 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#include <klay/filesystem.h>
#include <klay/dbus/connection.h>
#include <klay/error.h>
+#include <systemd/sd-bus.h>
#include "misc.h"
#include "logger.h"
jobsCv.notify_one();
}
-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 stopSystemdUnits()
{
dbus::Connection& systemDBus = dbus::Connection::getSystem();
-1, "(o)", "(u)", (unsigned int)pid)
.get("(o)", &unit);
- auto unescapedName = getDecodedPath(unit, "/org/freedesktop/systemd1/unit/");
+ char* tmp = NULL;
+ int err = sd_bus_path_decode(unit, "/org/freedesktop/systemd1/unit", &tmp);
+ if (err <= 0 || tmp == NULL) {
+ ERROR(SINK, "Failed to decode unit name: " + std::string(unit) + " error: " +
+ std::to_string(err));
+ continue;
+ }
+ std::string unescapedName(tmp);
+ free(tmp);
+
if (unescapedName.find("dbus", 0, 4) == std::string::npos)
unitsToStop.insert(unescapedName);
} catch (runtime::Exception &e) {