mirror of
https://github.com/systemd/systemd-stable.git
synced 2025-01-12 09:17:44 +03:00
improve dump output
This commit is contained in:
parent
e5b5ae50f0
commit
ceed357001
16
job.c
16
job.c
@ -52,7 +52,7 @@ JobDependency* job_dependency_new(Job *subject, Job *object, bool matters) {
|
|||||||
* this means the 'anchor' job (i.e. the one the user
|
* this means the 'anchor' job (i.e. the one the user
|
||||||
* explcitily asked for) is the requester. */
|
* explcitily asked for) is the requester. */
|
||||||
|
|
||||||
if (!(l = new(JobDependency, 1)))
|
if (!(l = new0(JobDependency, 1)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
l->subject = subject;
|
l->subject = subject;
|
||||||
@ -127,7 +127,7 @@ void job_dependency_delete(Job *subject, Job *object, bool *matters) {
|
|||||||
job_dependency_free(l);
|
job_dependency_free(l);
|
||||||
}
|
}
|
||||||
|
|
||||||
void job_dump(Job *j, FILE*f) {
|
void job_dump(Job *j, FILE*f, const char *prefix) {
|
||||||
|
|
||||||
static const char* const job_type_table[_JOB_TYPE_MAX] = {
|
static const char* const job_type_table[_JOB_TYPE_MAX] = {
|
||||||
[JOB_START] = "start",
|
[JOB_START] = "start",
|
||||||
@ -148,11 +148,13 @@ void job_dump(Job *j, FILE*f) {
|
|||||||
assert(j);
|
assert(j);
|
||||||
assert(f);
|
assert(f);
|
||||||
|
|
||||||
fprintf(f, "Job %u (%s) → %s in state %s\n",
|
fprintf(f,
|
||||||
j->id,
|
"%sJob %u:\n"
|
||||||
name_id(j->name),
|
"%s\tAction: %s → %s\n"
|
||||||
job_type_table[j->type],
|
"%s\tState: %s\n",
|
||||||
job_state_table[j->state]);
|
prefix, j->id,
|
||||||
|
prefix, name_id(j->name), job_type_table[j->type],
|
||||||
|
prefix, job_state_table[j->state]);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool job_is_anchor(Job *j) {
|
bool job_is_anchor(Job *j) {
|
||||||
|
2
job.h
2
job.h
@ -80,7 +80,7 @@ struct Job {
|
|||||||
|
|
||||||
Job* job_new(Manager *m, JobType type, Name *name);
|
Job* job_new(Manager *m, JobType type, Name *name);
|
||||||
void job_free(Job *job);
|
void job_free(Job *job);
|
||||||
void job_dump(Job *j, FILE*f);
|
void job_dump(Job *j, FILE*f, const char *prefix);
|
||||||
|
|
||||||
JobDependency* job_dependency_new(Job *subject, Job *object, bool matters);
|
JobDependency* job_dependency_new(Job *subject, Job *object, bool matters);
|
||||||
void job_dependency_free(JobDependency *l);
|
void job_dependency_free(JobDependency *l);
|
||||||
|
26
manager.c
26
manager.c
@ -421,7 +421,7 @@ rollback:
|
|||||||
return r;
|
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;
|
Job *j, *f;
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
@ -491,7 +491,7 @@ void manager_transaction_delete_job(Manager *m, Job *j) {
|
|||||||
job_dependency_free(j->object_list);
|
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;
|
Job *ret;
|
||||||
void *state;
|
void *state;
|
||||||
Name *dep;
|
Name *dep;
|
||||||
@ -503,7 +503,7 @@ static int real_add_job(Manager *m, JobType type, Name *name, Job *by, bool matt
|
|||||||
assert(name);
|
assert(name);
|
||||||
|
|
||||||
/* First add the job. */
|
/* 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;
|
return -ENOMEM;
|
||||||
|
|
||||||
/* Then, add a link to the job. */
|
/* Then, add a link to the job. */
|
||||||
@ -514,28 +514,28 @@ static int real_add_job(Manager *m, JobType type, Name *name, Job *by, bool matt
|
|||||||
/* Finally, recursively add in all dependencies. */
|
/* Finally, recursively add in all dependencies. */
|
||||||
if (type == JOB_START || type == JOB_RELOAD_OR_START) {
|
if (type == JOB_START || type == JOB_RELOAD_OR_START) {
|
||||||
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_REQUIRES], state)
|
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;
|
goto fail;
|
||||||
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_SOFT_REQUIRES], state)
|
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;
|
goto fail;
|
||||||
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_WANTS], state)
|
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;
|
goto fail;
|
||||||
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_REQUISITE], state)
|
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;
|
goto fail;
|
||||||
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_SOFT_REQUISITE], state)
|
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;
|
goto fail;
|
||||||
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_CONFLICTS], state)
|
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;
|
goto fail;
|
||||||
|
|
||||||
} else if (type == JOB_STOP || type == JOB_RESTART || type == JOB_TRY_RESTART) {
|
} else if (type == JOB_STOP || type == JOB_RESTART || type == JOB_TRY_RESTART) {
|
||||||
|
|
||||||
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_REQUIRED_BY], state)
|
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;
|
goto fail;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -557,7 +557,7 @@ int manager_add_job(Manager *m, JobType type, Name *name, JobMode mode, bool for
|
|||||||
assert(name);
|
assert(name);
|
||||||
assert(mode < _JOB_MODE_MAX);
|
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);
|
transaction_abort(m);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
@ -786,7 +786,7 @@ void manager_dump_jobs(Manager *s, FILE *f) {
|
|||||||
assert(f);
|
assert(f);
|
||||||
|
|
||||||
HASHMAP_FOREACH(j, s->jobs, state)
|
HASHMAP_FOREACH(j, s->jobs, state)
|
||||||
job_dump(j, f);
|
job_dump(j, f, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void manager_dump_names(Manager *s, FILE *f) {
|
void manager_dump_names(Manager *s, FILE *f) {
|
||||||
@ -799,5 +799,5 @@ void manager_dump_names(Manager *s, FILE *f) {
|
|||||||
|
|
||||||
HASHMAP_FOREACH_KEY(n, t, s->names, state)
|
HASHMAP_FOREACH_KEY(n, t, s->names, state)
|
||||||
if (name_id(n) == t)
|
if (name_id(n) == t)
|
||||||
name_dump(n, f);
|
name_dump(n, f, NULL);
|
||||||
}
|
}
|
||||||
|
40
name.c
40
name.c
@ -405,7 +405,7 @@ const char* name_id(Name *n) {
|
|||||||
return set_first(n->meta.names);
|
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] = {
|
static const char* const state_table[_NAME_STATE_MAX] = {
|
||||||
[NAME_STUB] = "stub",
|
[NAME_STUB] = "stub",
|
||||||
@ -432,15 +432,18 @@ void name_dump(Name *n, FILE *f) {
|
|||||||
|
|
||||||
assert(n);
|
assert(n);
|
||||||
|
|
||||||
fprintf(f,
|
if (!prefix)
|
||||||
"Name %s\n"
|
prefix = "";
|
||||||
"\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: ");
|
fprintf(f,
|
||||||
|
"%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)
|
SET_FOREACH(t, n->meta.names, state)
|
||||||
fprintf(f, "%s ", t);
|
fprintf(f, "%s ", t);
|
||||||
fprintf(f, "\n");
|
fprintf(f, "\n");
|
||||||
@ -457,10 +460,10 @@ void name_dump(Name *n, FILE *f) {
|
|||||||
t = s;
|
t = s;
|
||||||
|
|
||||||
fprintf(f,
|
fprintf(f,
|
||||||
"\tAddress: %s\n"
|
"%s\tAddress: %s\n"
|
||||||
"\tSocket State: %s\n",
|
"%s\tSocket State: %s\n",
|
||||||
t,
|
prefix, t,
|
||||||
socket_state_table[n->socket.state]);
|
prefix, socket_state_table[n->socket.state]);
|
||||||
|
|
||||||
free(s);
|
free(s);
|
||||||
break;
|
break;
|
||||||
@ -471,7 +474,14 @@ void name_dump(Name *n, FILE *f) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (n->meta.job) {
|
if (n->meta.job) {
|
||||||
fprintf(f, "\t");
|
char *p;
|
||||||
job_dump(n->meta.job, f);
|
|
||||||
|
if (asprintf(&p, "%s\t", prefix) >= 0)
|
||||||
|
prefix = p;
|
||||||
|
else
|
||||||
|
p = NULL;
|
||||||
|
|
||||||
|
job_dump(n->meta.job, f, prefix);
|
||||||
|
free(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user