machine: make machine_start_scope() static
Having this function which is called only from one place in a separate file makes the code harder to follow. In preparation for subsequent changes, let's make it static.
This commit is contained in:
parent
f47bd09749
commit
af22794712
|
@ -330,7 +330,99 @@ int machine_load(Machine *m) {
|
|||
return r;
|
||||
}
|
||||
|
||||
static int machine_start_scope(Machine *m, sd_bus_message *properties, sd_bus_error *error) {
|
||||
static int machine_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) {
|
||||
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL;
|
||||
int r;
|
||||
|
||||
assert(manager);
|
||||
assert(scope);
|
||||
assert(pid > 1);
|
||||
|
||||
r = sd_bus_message_new_method_call(
|
||||
manager->bus,
|
||||
&m,
|
||||
"org.freedesktop.systemd1",
|
||||
"/org/freedesktop/systemd1",
|
||||
"org.freedesktop.systemd1.Manager",
|
||||
"StartTransientUnit");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_append(m, "ss", strempty(scope), "fail");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_open_container(m, 'a', "(sv)");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (!isempty(slice)) {
|
||||
r = sd_bus_message_append(m, "(sv)", "Slice", "s", slice);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (!isempty(description)) {
|
||||
r = sd_bus_message_append(m, "(sv)", "Description", "s", description);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (more_properties) {
|
||||
r = sd_bus_message_copy(m, more_properties, true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_bus_message_close_container(m);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_append(m, "a(sa(sv))", 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_call(manager->bus, m, 0, error, &reply);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (job) {
|
||||
const char *j;
|
||||
char *copy;
|
||||
|
||||
r = sd_bus_message_read(reply, "o", &j);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
copy = strdup(j);
|
||||
if (!copy)
|
||||
return -ENOMEM;
|
||||
|
||||
*job = copy;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int machine_ensure_scope(Machine *m, sd_bus_message *properties, sd_bus_error *error) {
|
||||
assert(m);
|
||||
assert(m->class != MACHINE_HOST);
|
||||
|
||||
|
@ -349,7 +441,7 @@ 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);
|
||||
|
||||
r = manager_start_scope(m->manager, scope, m->leader, SPECIAL_MACHINE_SLICE, description, properties, error, &job);
|
||||
r = machine_start_scope(m->manager, scope, m->leader, SPECIAL_MACHINE_SLICE, description, properties, error, &job);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to start machine scope: %s", bus_error_message(error, r));
|
||||
|
||||
|
@ -380,7 +472,7 @@ int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error) {
|
|||
return r;
|
||||
|
||||
/* Create cgroup */
|
||||
r = machine_start_scope(m, properties, error);
|
||||
r = machine_ensure_scope(m, properties, error);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
|
|
|
@ -1294,98 +1294,6 @@ int match_reloading(sd_bus_message *message, void *userdata, sd_bus_error *error
|
|||
return 0;
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
_cleanup_(sd_bus_message_unrefp) sd_bus_message *m = NULL, *reply = NULL;
|
||||
int r;
|
||||
|
||||
assert(manager);
|
||||
assert(scope);
|
||||
assert(pid > 1);
|
||||
|
||||
r = sd_bus_message_new_method_call(
|
||||
manager->bus,
|
||||
&m,
|
||||
"org.freedesktop.systemd1",
|
||||
"/org/freedesktop/systemd1",
|
||||
"org.freedesktop.systemd1.Manager",
|
||||
"StartTransientUnit");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_append(m, "ss", strempty(scope), "fail");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_open_container(m, 'a', "(sv)");
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (!isempty(slice)) {
|
||||
r = sd_bus_message_append(m, "(sv)", "Slice", "s", slice);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
if (!isempty(description)) {
|
||||
r = sd_bus_message_append(m, "(sv)", "Description", "s", description);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
if (more_properties) {
|
||||
r = sd_bus_message_copy(m, more_properties, true);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
||||
r = sd_bus_message_close_container(m);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_message_append(m, "a(sa(sv))", 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = sd_bus_call(manager->bus, m, 0, error, &reply);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
if (job) {
|
||||
const char *j;
|
||||
char *copy;
|
||||
|
||||
r = sd_bus_message_read(reply, "o", &j);
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
copy = strdup(j);
|
||||
if (!copy)
|
||||
return -ENOMEM;
|
||||
|
||||
*job = copy;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int manager_unref_unit(
|
||||
Manager *m,
|
||||
const char *unit,
|
||||
|
|
|
@ -49,7 +49,6 @@ int match_unit_removed(sd_bus_message *message, void *userdata, sd_bus_error *er
|
|||
int match_properties_changed(sd_bus_message *message, void *userdata, sd_bus_error *error);
|
||||
int match_job_removed(sd_bus_message *message, void *userdata, sd_bus_error *error);
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in a new issue