summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2018-10-07 14:50:11 +0200
committerLennart Poettering <lennart@poettering.net>2018-11-09 17:15:34 +0100
commitb92d0b4c5adef37e9de8f6cc22a0e27b97fcf3ad (patch)
tree767d4e94958f6f530da1b95c349a6d4ed8b26591 /src
parent1d78fea2d6230e0aafa2603abc8f1f51966ef134 (diff)
downloadsystemd-b92d0b4c5adef37e9de8f6cc22a0e27b97fcf3ad.tar.gz
machined: rework referencing of machine scopes from machined, too
When a machine scope is registered by machined, let's add a reference to it, and change the GC mode so that the unit is cleaned up as soon as machined drops the reference, regardless of the fail state. Fixes: #2809
Diffstat (limited to 'src')
-rw-r--r--src/machine/machine.c15
-rw-r--r--src/machine/machined-dbus.c35
-rw-r--r--src/machine/machined.h1
3 files changed, 38 insertions, 13 deletions
diff --git a/src/machine/machine.c b/src/machine/machine.c
index 239228b2d2..d5e0d4953f 100644
--- a/src/machine/machine.c
+++ b/src/machine/machine.c
@@ -403,7 +403,7 @@ int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error) {
static int machine_stop_scope(Machine *m) {
_cleanup_(sd_bus_error_free) sd_bus_error error = SD_BUS_ERROR_NULL;
char *job = NULL;
- int r;
+ int r, q;
assert(m);
assert(m->class != MACHINE_HOST);
@@ -412,10 +412,17 @@ static int machine_stop_scope(Machine *m) {
return 0;
r = manager_stop_unit(m->manager, m->unit, &error, &job);
- if (r < 0)
- return log_error_errno(r, "Failed to stop machine scope: %s", bus_error_message(&error, r));
+ if (r < 0) {
+ log_error_errno(r, "Failed to stop machine scope: %s", bus_error_message(&error, r));
+ sd_bus_error_free(&error);
+ } else
+ free_and_replace(m->scope_job, job);
+
+ q = manager_unref_unit(m->manager, m->unit, &error);
+ if (q < 0)
+ log_warning_errno(q, "Failed to drop reference to machine scope, ignoring: %s", bus_error_message(&error, r));
- return free_and_replace(m->scope_job, job);
+ return r;
}
int machine_stop(Machine *m) {
diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c
index 32c0b04283..87e6298c78 100644
--- a/src/machine/machined-dbus.c
+++ b/src/machine/machined-dbus.c
@@ -1363,18 +1363,15 @@ int manager_start_scope(
return r;
}
- r = sd_bus_message_append(m, "(sv)", "PIDs", "au", 1, pid);
+ r = sd_bus_message_append(m, "(sv)(sv)(sv)(sv)(sv)",
+ "PIDs", "au", 1, pid,
+ "Delegate", "b", 1,
+ "CollectMode", "s", "inactive-or-failed",
+ "AddRef", "b", 1,
+ "TasksMax", "t", UINT64_C(16384));
if (r < 0)
return r;
- r = sd_bus_message_append(m, "(sv)", "Delegate", "b", 1);
- if (r < 0)
- return r;
-
- r = sd_bus_message_append(m, "(sv)", "TasksMax", "t", UINT64_C(16384));
- if (r < 0)
- return bus_log_create_error(r);
-
if (more_properties) {
r = sd_bus_message_copy(m, more_properties, true);
if (r < 0)
@@ -1411,6 +1408,26 @@ int manager_start_scope(
return 1;
}
+int manager_unref_unit(
+ Manager *m,
+ const char *unit,
+ sd_bus_error *error) {
+
+ assert(m);
+ assert(unit);
+
+ return sd_bus_call_method(
+ m->bus,
+ "org.freedesktop.systemd1",
+ "/org/freedesktop/systemd1",
+ "org.freedesktop.systemd1.Manager",
+ "UnrefUnit",
+ error,
+ NULL,
+ "s",
+ unit);
+}
+
int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job) {
_cleanup_(sd_bus_message_unrefp) sd_bus_message *reply = NULL;
int r;
diff --git a/src/machine/machined.h b/src/machine/machined.h
index 3197c1aade..ef63f96e97 100644
--- a/src/machine/machined.h
+++ b/src/machine/machined.h
@@ -50,5 +50,6 @@ int match_job_removed(sd_bus_message *message, void *userdata, sd_bus_error *err
int manager_start_scope(Manager *manager, const char *scope, pid_t pid, const char *slice, const char *description, sd_bus_message *more_properties, sd_bus_error *error, char **job);
int manager_stop_unit(Manager *manager, const char *unit, sd_bus_error *error, char **job);
int manager_kill_unit(Manager *manager, const char *unit, int signo, sd_bus_error *error);
+int manager_unref_unit(Manager *m, const char *unit, sd_bus_error *error);
int manager_unit_is_active(Manager *manager, const char *unit);
int manager_job_is_active(Manager *manager, const char *path);