diff --git a/src/core/job.c b/src/core/job.c index 43a06a365e..24f407ad83 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -292,6 +292,10 @@ int job_install_deserialized(Job *j) { return log_unit_debug_errno(j->unit, SYNTHETIC_ERRNO(EEXIST), "Unit already has a job installed. Not installing deserialized job."); + /* When the job does not have ID, or we failed to deserialize the job ID, then use a new ID. */ + if (j->id <= 0) + j->id = manager_get_new_job_id(j->manager); + r = hashmap_ensure_put(&j->manager->jobs, NULL, UINT32_TO_PTR(j->id), j); if (r == -EEXIST) return log_unit_debug_errno(j->unit, r, "Job ID %" PRIu32 " already used, cannot deserialize job.", j->id);