mirror of
https://github.com/systemd/systemd.git
synced 2024-11-27 20:23:36 +08:00
only accept valid job types for specific names
This commit is contained in:
parent
e094e853a0
commit
cd2dbd7df9
27
job.c
27
job.c
@ -266,10 +266,33 @@ bool job_type_is_superset(JobType a, JobType b) {
|
||||
}
|
||||
|
||||
bool job_type_is_conflicting(JobType a, JobType b) {
|
||||
|
||||
/* Checks whether two types are "conflicting" */
|
||||
assert(a >= 0 && a < _JOB_TYPE_MAX);
|
||||
assert(b >= 0 && b < _JOB_TYPE_MAX);
|
||||
|
||||
return
|
||||
(a == JOB_STOP && b != JOB_STOP) ||
|
||||
(b == JOB_STOP && a != JOB_STOP);
|
||||
}
|
||||
|
||||
bool job_type_applicable(JobType j, NameType n) {
|
||||
assert(j >= 0 && j < _JOB_TYPE_MAX);
|
||||
assert(n >= 0 && n < _NAME_TYPE_MAX);
|
||||
|
||||
switch (j) {
|
||||
case JOB_START:
|
||||
case JOB_STOP:
|
||||
case JOB_VERIFY_STARTED:
|
||||
return true;
|
||||
|
||||
case JOB_RELOAD:
|
||||
case JOB_RELOAD_OR_START:
|
||||
return n == NAME_SERVICE || n == NAME_TIMER || n == NAME_MOUNT;
|
||||
|
||||
case JOB_RESTART:
|
||||
case JOB_TRY_RESTART:
|
||||
return n == NAME_SERVICE || n == NAME_TIMER || n == NAME_SOCKET || NAME_MOUNT || NAME_SNAPSHOT;
|
||||
|
||||
default:
|
||||
assert_not_reached("Invalid job type");
|
||||
}
|
||||
}
|
||||
|
17
manager.c
17
manager.c
@ -680,6 +680,9 @@ static int transaction_add_job_and_dependencies(Manager *m, JobType type, Name *
|
||||
if (name->meta.state != NAME_LOADED)
|
||||
return -EINVAL;
|
||||
|
||||
if (!job_type_applicable(type, name->meta.type))
|
||||
return -EBADR;
|
||||
|
||||
/* First add the job. */
|
||||
if (!(ret = transaction_add_one_job(m, type, name, &is_new)))
|
||||
return -ENOMEM;
|
||||
@ -692,28 +695,28 @@ static int transaction_add_job_and_dependencies(Manager *m, JobType type, Name *
|
||||
/* 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 = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, true, force, NULL)) < 0)
|
||||
if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, true, force, NULL)) != -EBADR)
|
||||
goto fail;
|
||||
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_SOFT_REQUIRES], state)
|
||||
if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, !force, force, NULL)) < 0)
|
||||
if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, !force, force, NULL)) != -EBADR)
|
||||
goto fail;
|
||||
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_WANTS], state)
|
||||
if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, false, force, NULL)) < 0)
|
||||
if ((r = transaction_add_job_and_dependencies(m, JOB_START, dep, ret, false, force, NULL)) != -EBADR)
|
||||
goto fail;
|
||||
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_REQUISITE], state)
|
||||
if ((r = transaction_add_job_and_dependencies(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)) != -EBADR)
|
||||
goto fail;
|
||||
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_SOFT_REQUISITE], state)
|
||||
if ((r = transaction_add_job_and_dependencies(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)) != -EBADR)
|
||||
goto fail;
|
||||
SET_FOREACH(dep, ret->name->meta.dependencies[NAME_CONFLICTS], state)
|
||||
if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, dep, ret, true, force, NULL)) < 0)
|
||||
if ((r = transaction_add_job_and_dependencies(m, JOB_STOP, dep, ret, true, force, NULL)) != -EBADR)
|
||||
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 = transaction_add_job_and_dependencies(m, type, dep, ret, true, force, NULL)) < 0)
|
||||
if ((r = transaction_add_job_and_dependencies(m, type, dep, ret, true, force, NULL)) != -EBADR)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user