]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: transition job to JOB_FINISHED on uninstall 41583/head
authorMichael Vogt <michael@amutable.com>
Mon, 27 Apr 2026 11:12:30 +0000 (13:12 +0200)
committerMichael Vogt <michael@amutable.com>
Tue, 28 Apr 2026 07:01:54 +0000 (09:01 +0200)
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
src/core/varlink-unit.c

index 44652d5f3e2024dadc557e7b6442d16e847116c4..2388d1de95f64c7ac883b5f2462f3f9dd6f9fae2 100644 (file)
@@ -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);
index 7111baf7391e613e31b415d5495621697c0f6299..5b1dc77aae0b42f55cf91530f86ca6623b8334ea 100644 (file)
@@ -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)));
 }