machine: use free_and_replace() and TAKE_PTR()
This commit is contained in:
parent
fb2367edd9
commit
354f62cf3c
|
@ -328,14 +328,13 @@ int machine_load(Machine *m) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int machine_start_scope(Machine *m, sd_bus_message *properties, sd_bus_error *error) {
|
static int machine_start_scope(Machine *m, sd_bus_message *properties, sd_bus_error *error) {
|
||||||
int r = 0;
|
|
||||||
|
|
||||||
assert(m);
|
assert(m);
|
||||||
assert(m->class != MACHINE_HOST);
|
assert(m->class != MACHINE_HOST);
|
||||||
|
|
||||||
if (!m->unit) {
|
if (!m->unit) {
|
||||||
_cleanup_free_ char *escaped = NULL;
|
_cleanup_free_ char *escaped = NULL, *scope = NULL;
|
||||||
char *scope, *description, *job = NULL;
|
char *description, *job = NULL;
|
||||||
|
int r;
|
||||||
|
|
||||||
escaped = unit_name_escape(m->name);
|
escaped = unit_name_escape(m->name);
|
||||||
if (!escaped)
|
if (!escaped)
|
||||||
|
@ -348,22 +347,17 @@ static int machine_start_scope(Machine *m, sd_bus_message *properties, sd_bus_er
|
||||||
description = strjoina(m->class == MACHINE_VM ? "Virtual Machine " : "Container ", m->name);
|
description = strjoina(m->class == MACHINE_VM ? "Virtual Machine " : "Container ", m->name);
|
||||||
|
|
||||||
r = manager_start_scope(m->manager, scope, m->leader, SPECIAL_MACHINE_SLICE, description, properties, error, &job);
|
r = manager_start_scope(m->manager, scope, m->leader, SPECIAL_MACHINE_SLICE, description, properties, error, &job);
|
||||||
if (r < 0) {
|
if (r < 0)
|
||||||
log_error("Failed to start machine scope: %s", bus_error_message(error, r));
|
return log_error_errno(r, "Failed to start machine scope: %s", bus_error_message(error, r));
|
||||||
free(scope);
|
|
||||||
return r;
|
|
||||||
} else {
|
|
||||||
m->unit = scope;
|
|
||||||
|
|
||||||
free(m->scope_job);
|
m->unit = TAKE_PTR(scope);
|
||||||
m->scope_job = job;
|
free_and_replace(m->scope_job, job);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m->unit)
|
if (m->unit)
|
||||||
hashmap_put(m->manager->machine_units, m->unit, m);
|
hashmap_put(m->manager->machine_units, m->unit, m);
|
||||||
|
|
||||||
return r;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error) {
|
int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error) {
|
||||||
|
@ -417,15 +411,10 @@ static int machine_stop_scope(Machine *m) {
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
r = manager_stop_unit(m->manager, m->unit, &error, &job);
|
r = manager_stop_unit(m->manager, m->unit, &error, &job);
|
||||||
if (r < 0) {
|
if (r < 0)
|
||||||
log_error("Failed to stop machine scope: %s", bus_error_message(&error, r));
|
return log_error_errno(r, "Failed to stop machine scope: %s", bus_error_message(&error, r));
|
||||||
return r;
|
|
||||||
}
|
|
||||||
|
|
||||||
free(m->scope_job);
|
return free_and_replace(m->scope_job, job);
|
||||||
m->scope_job = job;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int machine_stop(Machine *m) {
|
int machine_stop(Machine *m) {
|
||||||
|
|
Loading…
Reference in a new issue