From: Philip Withnall Date: Mon, 17 Nov 2025 15:14:19 +0000 (+0000) Subject: sysupdate: Split context_apply() into acquire and install steps X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ec10efa1a1af1881adb89d71eaf3916d61c73b96;p=thirdparty%2Fsystemd.git sysupdate: Split context_apply() into acquire and install steps This introduces no functional changes at the moment, but will be used in upcoming commits. Signed-off-by: Philip Withnall Helps: https://github.com/systemd/systemd/issues/34814 --- diff --git a/src/sysupdate/sysupdate.c b/src/sysupdate/sysupdate.c index 05163754af7..e1143ad4ce4 100644 --- a/src/sysupdate/sysupdate.c +++ b/src/sysupdate/sysupdate.c @@ -982,10 +982,9 @@ static int context_on_acquire_progress(const Transfer *t, const Instance *inst, overall, n - i, i, inst->metadata.version, overall); } -static int context_apply( +static int context_acquire( Context *c, - const char *version, - UpdateSet **ret_applied) { + const char *version) { UpdateSet *us = NULL; int r; @@ -1000,9 +999,6 @@ static int context_apply( if (!c->candidate) { log_info("No update needed."); - if (ret_applied) - *ret_applied = NULL; - return 0; } @@ -1014,9 +1010,6 @@ static int context_apply( else if (FLAGS_SET(us->flags, UPDATE_INSTALLED)) { log_info("Selected update '%s' is already installed. Skipping update.", us->version); - if (ret_applied) - *ret_applied = NULL; - return 0; } @@ -1075,7 +1068,34 @@ static int context_apply( if (arg_sync) sync(); - (void) sd_notifyf(/* unset_environment= */ false, + return 1; +} + +static int context_install( + Context *c, + const char *version, + UpdateSet **ret_applied) { + + UpdateSet *us = NULL; + int r; + + assert(c); + + if (version) { + us = context_update_set_by_version(c, version); + if (!us) + return log_error_errno(SYNTHETIC_ERRNO(ENOENT), "Update '%s' not found.", version); + } else { + if (!c->candidate) { + log_info("No update needed."); + + return 0; + } + + us = c->candidate; + } + + (void) sd_notifyf(/* unset_environment=*/ false, "STATUS=Installing '%s'.", us->version); for (size_t i = 0; i < c->n_transfers; i++) { @@ -1443,7 +1463,12 @@ static int verb_update(int argc, char **argv, void *userdata) { if (r < 0) return r; - r = context_apply(context, version, &applied); + r = context_acquire(context, version); + if (r < 0) + return r; /* error */ + + if (r > 0) /* update needed */ + r = context_install(context, version, &applied); if (r < 0) return r;