return r;
}
-static Job* transaction_add_job(Manager *m, JobType type, Name *name, bool *is_new) {
+static Job* transaction_add_one_job(Manager *m, JobType type, Name *name, bool *is_new) {
Job *j, *f;
int r;
job_dependency_free(j->object_list);
}
-static int real_add_job(Manager *m, JobType type, Name *name, Job *by, bool matters, bool force, Job **_ret) {
+static int transaction_add_job_and_dependencies(Manager *m, JobType type, Name *name, Job *by, bool matters, bool force, Job **_ret) {
Job *ret;
void *state;
Name *dep;
assert(name);
/* First add the job. */
- if (!(ret = transaction_add_job(m, type, name, &is_new)))
+ if (!(ret = transaction_add_one_job(m, type, name, &is_new)))
return -ENOMEM;
/* Then, add a link to the job. */
/* Finally, recursively add in all dependencies. */
if (type == JOB_START || type == JOB_RELOAD_OR_START) {
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_REQUIRES], state)
- if ((r = real_add_job(m, JOB_START, dep, ret, true, force, NULL)) < 0)
+ if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, true, force, NULL)) < 0)
goto fail;
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_SOFT_REQUIRES], state)
- if ((r = real_add_job(m, JOB_START, dep, ret, !force, force, NULL)) < 0)
+ if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, !force, force, NULL)) < 0)
goto fail;
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_WANTS], state)
- if ((r = real_add_job(m, JOB_START, dep, ret, false, force, NULL)) < 0)
+ if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, false, force, NULL)) < 0)
goto fail;
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_REQUISITE], state)
- if ((r = real_add_job(m, JOB_VERIFY_STARTED, dep, ret, true, force, NULL)) < 0)
+ if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_STARTED, dep, ret, true, force, NULL)) < 0)
goto fail;
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_SOFT_REQUISITE], state)
- if ((r = real_add_job(m, JOB_VERIFY_STARTED, dep, ret, !force, force, NULL)) < 0)
+ if ((r = transaction_add_job_and_dependencies(m, JOB_VERIFY_STARTED, dep, ret, !force, force, NULL)) < 0)
goto fail;
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_CONFLICTS], state)
- if ((r = real_add_job(m, JOB_STOP, dep, ret, true, force, NULL)) < 0)
+ if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, dep, ret, true, force, NULL)) < 0)
goto fail;
} else if (type == JOB_STOP || type == JOB_RESTART || type == JOB_TRY_RESTART) {
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_REQUIRED_BY], state)
- if ((r = real_add_job(m, type, dep, ret, true, force, NULL)) < 0)
+ if ((r = transaction_add_job_and_dependencies(m, type, dep, ret, true, force, NULL)) < 0)
goto fail;
}
assert(name);
assert(mode < _JOB_MODE_MAX);
- if ((r = real_add_job(m, type, name, NULL, true, force, &ret))) {
+ if ((r = transaction_add_job_and_dependencies(m, type, name, NULL, true, force, &ret))) {
transaction_abort(m);
return r;
}
assert(f);
HASHMAP_FOREACH(j, s->jobs, state)
- job_dump(j, f);
+ job_dump(j, f, NULL);
}
void manager_dump_names(Manager *s, FILE *f) {
HASHMAP_FOREACH_KEY(n, t, s->names, state)
if (name_id(n) == t)
- name_dump(n, f);
+ name_dump(n, f, NULL);
}
return set_first(n->meta.names);
}
-void name_dump(Name *n, FILE *f) {
+void name_dump(Name *n, FILE *f, const char *prefix) {
static const char* const state_table[_NAME_STATE_MAX] = {
[NAME_STUB] = "stub",
assert(n);
+ if (!prefix)
+ prefix = "";
+
fprintf(f,
- "Name %s\n"
- "\tDescription: %s\n"
- "\tName State: %s\n",
- name_id(n),
- n->meta.description ? n->meta.description : name_id(n),
- state_table[n->meta.state]);
-
- fprintf(f, "\tNames: ");
+ "%sName %s:\n"
+ "%s\tDescription: %s\n"
+ "%s\tName State: %s\n",
+ prefix, name_id(n),
+ prefix, n->meta.description ? n->meta.description : name_id(n),
+ prefix, state_table[n->meta.state]);
+
+ fprintf(f, "%s\tNames: ", prefix);
SET_FOREACH(t, n->meta.names, state)
fprintf(f, "%s ", t);
fprintf(f, "\n");
t = s;
fprintf(f,
- "\tAddress: %s\n"
- "\tSocket State: %s\n",
- t,
- socket_state_table[n->socket.state]);
+ "%s\tAddress: %s\n"
+ "%s\tSocket State: %s\n",
+ prefix, t,
+ prefix, socket_state_table[n->socket.state]);
free(s);
break;
}
if (n->meta.job) {
- fprintf(f, "\t");
- job_dump(n->meta.job, f);
+ char *p;
+
+ if (asprintf(&p, "%s\t", prefix) >= 0)
+ prefix = p;
+ else
+ p = NULL;
+
+ job_dump(n->meta.job, f, prefix);
+ free(p);
}
}