This is an automated email from the git hooks/post-receive script. guillem pushed a commit to branch main in repository dpkg.
View the commit online: https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=422e8fc1713c8208f06e567f8d212eae4ab4d8d5 commit 422e8fc1713c8208f06e567f8d212eae4ab4d8d5 Author: Guillem Jover <[email protected]> AuthorDate: Mon Sep 29 23:00:34 2025 +0200 dpkg: Do not run the postinst during cleanup if the previous state was bad During unpack, only call the postinst's abort-upgrade in cleanup if the status was good before-hand. Same goes for postinst's abort-remove when package was about to be removed due to a conflict. If the package was halfconfigured, we do not run the postinst and that way there are no surprises. When we do run the postinst we know that we can without fear set the package to installed (or trig*, as the case may be). We achieve this by not registering the cu_prerm* handlers unless the package was in a state > PKG_STAT_HALFCONFIGURED beforehand. We have no more need to pass the previous state into the cu_prerm* postinst invocations. During remove, only call the postinst's abort-remove in cleanup if the status was good before-hand (same logic than above). We can now remove the static modifier for oldpkgstatus as we are not passing it to the cleanup handler. During cleanup, always mark the package status as installed if abort-remove succeeds as this will only be called if the status was greater than halfconfigured. Thus the oldpkgstatus parameter is now useless and we can drop it. Based-on-patch-by: Ian Jackson <[email protected]> Closes: #432893 --- src/main/cleanup.c | 3 +-- src/main/remove.c | 8 ++++---- src/main/unpack.c | 16 ++++++++++++---- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/src/main/cleanup.c b/src/main/cleanup.c index ca31e70fa..96a4da812 100644 --- a/src/main/cleanup.c +++ b/src/main/cleanup.c @@ -301,14 +301,13 @@ void cu_prermremove(int argc, void **argv) { struct pkginfo *pkg = (struct pkginfo*)argv[0]; - const enum pkgstatus *oldpkgstatus = (enum pkgstatus *)argv[1]; if (cleanup_pkg_failed++) return; maintscript_postinst(pkg, "abort-remove", NULL); pkg_clear_eflags(pkg, PKG_EFLAG_REINSTREQ); - post_postinst_tasks(pkg, *oldpkgstatus); + post_postinst_tasks(pkg, PKG_STAT_INSTALLED); cleanup_pkg_failed--; } diff --git a/src/main/remove.c b/src/main/remove.c index 5f270ea93..c8d95dfdc 100644 --- a/src/main/remove.c +++ b/src/main/remove.c @@ -210,13 +210,13 @@ deferred_remove(struct pkginfo *pkg) trig_activate_packageprocessing(pkg); if (pkg->status >= PKG_STAT_HALFCONFIGURED) { - static enum pkgstatus oldpkgstatus; + enum pkgstatus oldpkgstatus = pkg->status; - oldpkgstatus = pkg->status; pkg_set_status(pkg, PKG_STAT_HALFCONFIGURED); modstatdb_note(pkg); - push_cleanup(cu_prermremove, ~ehflag_normaltidy, 2, - (void *)pkg, (void *)&oldpkgstatus); + if (oldpkgstatus > PKG_STAT_HALFCONFIGURED) + push_cleanup(cu_prermremove, ~ehflag_normaltidy, + 1, (void *)pkg); maintscript_run_old(pkg, PRERMFILE, "remove", NULL); /* Will turn into ‘half-installed’ soon ... */ diff --git a/src/main/unpack.c b/src/main/unpack.c index 106c9d9cd..cbc93f7e7 100644 --- a/src/main/unpack.c +++ b/src/main/unpack.c @@ -315,6 +315,11 @@ pkg_deconfigure_others(struct pkginfo *pkg) versiondescribe(&pkg->available.version, vdew_nonambig)); } + if (deconpil->pkg->status <= PKG_STAT_HALFCONFIGURED) + internerr("deconfiguring package %s is in %s <= half-configured state", + pkg_name(deconpil->pkg, pnaw_always), + pkg_status_name(deconpil->pkg)); + trig_activate_packageprocessing(deconpil->pkg); pkg_set_status(deconpil->pkg, PKG_STAT_HALFCONFIGURED); modstatdb_note(deconpil->pkg); @@ -1449,8 +1454,9 @@ process_archive(const char *filename) pkg_set_eflags(pkg, PKG_EFLAG_REINSTREQ); pkg_set_status(pkg, PKG_STAT_HALFCONFIGURED); modstatdb_note(pkg); - push_cleanup(cu_prermupgrade, ~ehflag_normaltidy, - 1, (void *)pkg); + if (oldversionstatus > PKG_STAT_HALFCONFIGURED) + push_cleanup(cu_prermupgrade, ~ehflag_normaltidy, + 1, (void *)pkg); maintscript_run_old_or_new(pkg, cidir, cidirrest, PRERMFILE, "upgrade", "failed-upgrade"); pkg_set_status(pkg, PKG_STAT_UNPACKED); @@ -1464,6 +1470,7 @@ process_archive(const char *filename) conflictor_iter; conflictor_iter = conflictor_iter->next) { struct pkginfo *conflictor = conflictor_iter->pkg; + enum pkgstatus old_conflictor_status = conflictor->status; if (!(conflictor->status == PKG_STAT_HALFCONFIGURED || conflictor->status == PKG_STAT_TRIGGERSAWAITED || @@ -1474,8 +1481,9 @@ process_archive(const char *filename) trig_activate_packageprocessing(conflictor); pkg_set_status(conflictor, PKG_STAT_HALFCONFIGURED); modstatdb_note(conflictor); - push_cleanup(cu_prerminfavour, ~ehflag_normaltidy, - 2, conflictor, pkg); + if (old_conflictor_status > PKG_STAT_HALFCONFIGURED) + push_cleanup(cu_prerminfavour, ~ehflag_normaltidy, + 2, conflictor, pkg); maintscript_run_old(conflictor, PRERMFILE, "remove", "in-favour", pkgbin_name(pkg, &pkg->available, pnaw_nonambig), -- Dpkg.Org's dpkg

