From 89e9df12b3850800780693a1c746716c655d77ef Mon Sep 17 00:00:00 2001 From: Michal Sekletar Date: Tue, 30 May 2023 15:47:16 +0200 Subject: [PATCH] core/transaction: drop job that has unfulfilled required (Requires, BindsTo) dependencies Resolves: #11338 --- src/core/transaction.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/transaction.c b/src/core/transaction.c index 65a00bd9284..39f8f6c96df 100644 --- a/src/core/transaction.c +++ b/src/core/transaction.c @@ -1003,7 +1003,7 @@ int transaction_add_job_and_dependencies( r = transaction_add_job_and_dependencies(tr, JOB_START, dep, ret, true, false, false, ignore_order, e); if (r < 0) { if (r != -EBADR) /* job type not applicable */ - return r; + goto fail; sd_bus_error_free(e); } @@ -1025,7 +1025,7 @@ int transaction_add_job_and_dependencies( r = transaction_add_job_and_dependencies(tr, JOB_VERIFY_ACTIVE, dep, ret, true, false, false, ignore_order, e); if (r < 0) { if (r != -EBADR) /* job type not applicable */ - return r; + goto fail; sd_bus_error_free(e); } @@ -1035,7 +1035,7 @@ int transaction_add_job_and_dependencies( r = transaction_add_job_and_dependencies(tr, JOB_STOP, dep, ret, true, true, false, ignore_order, e); if (r < 0) { if (r != -EBADR) /* job type not applicable */ - return r; + goto fail; sd_bus_error_free(e); } @@ -1102,6 +1102,13 @@ int transaction_add_job_and_dependencies( } return 0; +fail: + /* Recursive call failed to add required jobs so let's drop top level job as well. */ + log_unit_debug_errno(unit, r, "Cannot add dependency job to transaction, deleting job %s/%s again: %s", + unit->id, job_type_to_string(type), bus_error_message(e, r)); + transaction_delete_job(tr, ret, /* delete_dependencies= */ false); + return r; + } static bool shall_stop_on_isolate(Transaction *tr, Unit *u) { -- 2.47.3