summaryrefslogtreecommitdiff
path: root/src/core/transaction.c
diff options
context:
space:
mode:
authorLuca Boccassi <luca.boccassi@microsoft.com>2020-07-03 18:45:19 +0100
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-07-07 10:09:24 +0200
commitcda667722c2218cf1a0185284d2a87f8a25f1b2d (patch)
tree0e97f4ea9ed8373ddaef00c7cd4fa866e1ceb8c2 /src/core/transaction.c
parent77ecc1aaa54947d4babd57110e0dee0457f7ba4e (diff)
downloadsystemd-cda667722c2218cf1a0185284d2a87f8a25f1b2d.tar.gz
core: refresh unit cache when building a transaction if UNIT_NOT_FOUND
When a command asks to load a unit directly and it is in state UNIT_NOT_FOUND, and the cache is outdated, we refresh it and attempto to load again. Use the same logic when building up a transaction and a dependency in UNIT_NOT_FOUND state is encountered. Update the unit test to exercise this code path.
Diffstat (limited to 'src/core/transaction.c')
-rw-r--r--src/core/transaction.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/core/transaction.c b/src/core/transaction.c
index ef6470656c..4a57b8e3f9 100644
--- a/src/core/transaction.c
+++ b/src/core/transaction.c
@@ -954,6 +954,24 @@ int transaction_add_job_and_dependencies(
if (type != JOB_STOP) {
r = bus_unit_validate_load_state(unit, e);
+ /* The time-based cache allows to start new units without daemon-reload,
+ * but if they are already referenced (because of dependencies or ordering)
+ * then we have to force a load of the fragment. As an optimization, check
+ * first if anything in the usual paths was modified since the last time
+ * the cache was loaded. Also check if the last time an attempt to load the
+ * unit was made was before the most recent cache refresh, so that we know
+ * we need to try again - even if the cache is current, it might have been
+ * updated in a different context before we had a chance to retry loading
+ * this particular unit.
+ * Given building up the transaction is a synchronous operation, attempt
+ * to load the unit immediately. */
+ if (r < 0 && manager_unit_file_maybe_loadable_from_cache(unit)) {
+ unit->load_state = UNIT_STUB;
+ r = unit_load(unit);
+ if (r < 0 || unit->load_state == UNIT_STUB)
+ unit->load_state = UNIT_NOT_FOUND;
+ r = bus_unit_validate_load_state(unit, e);
+ }
if (r < 0)
return r;
}