mirror of
https://github.com/systemd/systemd.git
synced 2025-03-19 22:50:17 +03:00
core: update setings on the unit and job as the result of ExecCondition=
Update ExecCondition= to set Unit->condition_result and return JOB_DONE in the Job results if the check fails so as to match the current behavior of ConditionXYZ= w.r.t units/jobs dependency checks. Fixes: #18207
This commit is contained in:
parent
f190ac486e
commit
42e6f54979
@ -878,8 +878,7 @@ static void job_log_done_status_message(Unit *u, uint32_t job_id, JobType t, Job
|
||||
return;
|
||||
|
||||
/* Show condition check message if the job did not actually do anything due to failed condition. */
|
||||
if ((t == JOB_START && result == JOB_DONE && !u->condition_result) ||
|
||||
(t == JOB_START && result == JOB_SKIPPED)) {
|
||||
if (t == JOB_START && result == JOB_DONE && !u->condition_result) {
|
||||
log_struct(LOG_INFO,
|
||||
"MESSAGE=Condition check resulted in %s being skipped.", unit_status_string(u),
|
||||
"JOB_ID=%" PRIu32, job_id,
|
||||
|
@ -1105,8 +1105,7 @@ static void service_set_state(Service *s, ServiceState state) {
|
||||
|
||||
unit_notify(UNIT(s), table[old_state], table[state],
|
||||
(s->reload_result == SERVICE_SUCCESS ? 0 : UNIT_NOTIFY_RELOAD_FAILURE) |
|
||||
(s->will_auto_restart ? UNIT_NOTIFY_WILL_AUTO_RESTART : 0) |
|
||||
(s->result == SERVICE_SKIP_CONDITION ? UNIT_NOTIFY_SKIP_CONDITION : 0));
|
||||
(s->will_auto_restart ? UNIT_NOTIFY_WILL_AUTO_RESTART : 0));
|
||||
}
|
||||
|
||||
static usec_t service_coldplug_timeout(Service *s) {
|
||||
@ -3524,10 +3523,6 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
||||
} else if (s->control_pid == pid) {
|
||||
s->control_pid = 0;
|
||||
|
||||
/* ExecCondition= calls that exit with (0, 254] should invoke skip-like behavior instead of failing */
|
||||
if (f == SERVICE_FAILURE_EXIT_CODE && s->state == SERVICE_CONDITION && status < 255)
|
||||
f = SERVICE_SKIP_CONDITION;
|
||||
|
||||
if (s->control_command) {
|
||||
exec_status_exit(&s->control_command->exec_status, &s->exec_context, pid, code, status);
|
||||
|
||||
@ -3535,6 +3530,15 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
|
||||
f = SERVICE_SUCCESS;
|
||||
}
|
||||
|
||||
/* ExecCondition= calls that exit with (0, 254] should invoke skip-like behavior instead of failing */
|
||||
if (s->state == SERVICE_CONDITION) {
|
||||
if (f == SERVICE_FAILURE_EXIT_CODE && status < 255) {
|
||||
UNIT(s)->condition_result = false;
|
||||
f = SERVICE_SKIP_CONDITION;
|
||||
} else if (f == SERVICE_SUCCESS)
|
||||
UNIT(s)->condition_result = true;
|
||||
}
|
||||
|
||||
unit_log_process_exit(
|
||||
u,
|
||||
"Control process",
|
||||
@ -4579,7 +4583,6 @@ const UnitVTable service_vtable = {
|
||||
},
|
||||
.finished_start_job = {
|
||||
[JOB_FAILED] = "Failed to start %s.",
|
||||
[JOB_SKIPPED] = "Skipped %s.",
|
||||
},
|
||||
.finished_stop_job = {
|
||||
[JOB_DONE] = "Stopped %s.",
|
||||
|
@ -2559,8 +2559,6 @@ static bool unit_process_job(Job *j, UnitActiveState ns, UnitNotifyFlags flags)
|
||||
if (UNIT_IS_INACTIVE_OR_FAILED(ns)) {
|
||||
if (ns == UNIT_FAILED)
|
||||
result = JOB_FAILED;
|
||||
else if (FLAGS_SET(flags, UNIT_NOTIFY_SKIP_CONDITION))
|
||||
result = JOB_SKIPPED;
|
||||
else
|
||||
result = JOB_DONE;
|
||||
|
||||
|
@ -738,7 +738,6 @@ int unit_kill_common(Unit *u, KillWho who, int signo, pid_t main_pid, pid_t cont
|
||||
typedef enum UnitNotifyFlags {
|
||||
UNIT_NOTIFY_RELOAD_FAILURE = 1 << 0,
|
||||
UNIT_NOTIFY_WILL_AUTO_RESTART = 1 << 1,
|
||||
UNIT_NOTIFY_SKIP_CONDITION = 1 << 2,
|
||||
} UnitNotifyFlags;
|
||||
|
||||
void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, UnitNotifyFlags flags);
|
||||
|
Loading…
x
Reference in New Issue
Block a user