summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
authorYu Watanabe <watanabe.yu+github@gmail.com>2023-04-26 14:39:56 +0900
committerYu Watanabe <watanabe.yu+github@gmail.com>2023-04-27 00:36:41 +0900
commitaafb96d5146c70ac30f2b5c677cd22fd43abd62c (patch)
tree1169f18b30b4ccbc8530aebd85aa5d4e137c2dd2 /src/core
parent3e1aec303646c37e7a7c74b45ef8cc90e3bf3531 (diff)
downloadsystemd-aafb96d5146c70ac30f2b5c677cd22fd43abd62c.tar.gz
core/job: use new job ID when we failed to deserialize job ID
This is for the case when we fail to deserialize job ID. In job_install_deserialized(), we also check the job type, and that is for the case when we failed to deserialize the job. Let's gracefully handle the failure in deserializing the job ID. This is paranoia, and just for safety. Should not change any behavior.
Diffstat (limited to 'src/core')
-rw-r--r--src/core/job.c4
1 files changed, 4 insertions, 0 deletions
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);