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)) {
.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",
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);
}
}
INFO(SINK, "Closing all processes using internal storage.");
try {
- stopDependedSystemdUnits();
+ stopSystemdUnits();
INFO(SINK, "Umounting internal storage.");
unmountInternalStorage("/dev/mapper/userdata");
engine->umount();
if (!mntPaths.empty()) {
INFO(SINK, "Closing all processes using internal storage.");
- stopDependedSystemdUnits();
+ stopSystemdUnits();
INFO(SINK, "Unmounting internal storage.");
unmountInternalStorage(source);
if (engine->isMounted()) {
INFO(SINK, "Closing all processes using internal storage.");
- stopDependedSystemdUnits();
+ stopSystemdUnits();
INFO(SINK, "Umounting internal storage.");
unmountInternalStorage("/dev/mapper/userdata");