From 328fd964a91e120c4ea7edde6d1c5c9688123175 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Mon, 27 Apr 2026 13:12:30 +0200 Subject: [PATCH] core: transition job to JOB_FINISHED on uninstall When a job reaches the job_uninstall() stage we used to set the state to JOB_WAITING. However now that we have a JOB_FINISHED state [1] we should use that instead. This is more accurate so when varlink_job_send_removed_signal() is called the job is in the expected state and that is what the user will see. Note that this does not change the D-Bus API because there bus_job_send_removed_signal() doesn't send the state, it only sends the result. [1] https://github.com/systemd/systemd/pull/41811 --- src/core/job.c | 2 +- src/core/varlink-unit.c | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/src/core/job.c b/src/core/job.c index 44652d5f3e2..2388d1de95f 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -168,7 +168,7 @@ void job_uninstall(Job *j) { assert(j); assert(j->installed); - job_set_state(j, JOB_WAITING); + job_set_state(j, JOB_FINISHED); pj = j->type == JOB_NOP ? &j->unit->nop_job : &j->unit->job; assert(*pj == j); diff --git a/src/core/varlink-unit.c b/src/core/varlink-unit.c index 7111baf7391..5b1dc77aae0 100644 --- a/src/core/varlink-unit.c +++ b/src/core/varlink-unit.c @@ -640,18 +640,12 @@ void varlink_unit_send_change_signal(Unit *u) { static int job_build_json(sd_json_variant **ret, const char *name, void *userdata) { Job *j = ASSERT_PTR(userdata); - /* We cannot just "blindly" use the j->state as it will get reset to WAITING in - * core/job.c:job_uninstall() before varlink_job_send_removed_signal(). This happens from - * unit.c:unit_free(). It is probably something that should be fixed but its a subtle part of - * systemd so for now we just deal with it here. */ - JobState state = j->result >= 0 ? JOB_FINISHED : j->state; - /* Note that "Result" is suppressed until the job reaches JOB_FINISHED. */ return sd_json_buildo( ASSERT_PTR(ret), SD_JSON_BUILD_PAIR_INTEGER("Id", j->id), JSON_BUILD_PAIR_ENUM("JobType", job_type_to_string(j->type)), - JSON_BUILD_PAIR_ENUM("State", job_state_to_string(state)), + JSON_BUILD_PAIR_ENUM("State", job_state_to_string(j->state)), JSON_BUILD_PAIR_STRING_NON_EMPTY_UNDERSCORIFY("Result", job_result_to_string(j->result))); } -- 2.47.3