1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

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
This commit is contained in:
Lennart Poettering 2018-10-07 14:50:11 +02:00
parent 1d78fea2d6
commit b92d0b4c5a
3 changed files with 38 additions and 13 deletions

View File

@ -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);
return 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 r;
}
int machine_stop(Machine *m) {

View File

@ -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;

View File

@ -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);