From 5d0179bd88a83c5f4d9a3b8393a28f0c6a30d1c1 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Fri, 10 Feb 2017 11:05:44 +0100 Subject: [PATCH] libopkg: run prerm scripts for the old version also on upgrade To make sure we properly restart services on upgrade we need to call the prerm script of the old package, in case the init script changes (or vanishes). Signed-off-by: Jonas Gorski Acked-by: Jo-Philipp Wich --- libopkg/opkg_install.c | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/libopkg/opkg_install.c b/libopkg/opkg_install.c index acb7530..ad1169f 100644 --- a/libopkg/opkg_install.c +++ b/libopkg/opkg_install.c @@ -528,7 +528,25 @@ prerm_upgrade_old_pkg(pkg_t *pkg, pkg_t *old_pkg) Error unwind, for both the above cases: old-postinst abort-upgrade new-version */ - return 0; + int err; + char *script_args; + char *new_version; + + if (!old_pkg || !pkg) + return 0; + + new_version = pkg_version_str_alloc(pkg); + + sprintf_alloc(&script_args, "upgrade %s", new_version); + free(new_version); + err = pkg_run_script(old_pkg, "prerm", script_args); + free(script_args); + if (err != 0) { + opkg_msg(ERROR, "prerm script for package \"%s\" failed\n", + old_pkg->name); + return -1; + } + return 0; } static int @@ -925,7 +943,25 @@ postrm_upgrade_old_pkg(pkg_t *pkg, pkg_t *old_pkg) new-postrm failed-upgrade old-version Error unwind, for both cases: old-preinst abort-upgrade new-version */ - return 0; + int err; + char *script_args; + char *new_version; + + if (!old_pkg || !pkg) + return 0; + + new_version = pkg_version_str_alloc(pkg); + + sprintf_alloc(&script_args, "upgrade %s", new_version); + free(new_version); + err = pkg_run_script(old_pkg, "postrm", script_args); + free(script_args); + if (err != 0) { + opkg_msg(ERROR, "postrm script for package \"%s\" failed\n", + old_pkg->name); + return -1; + } + return 0; } static int -- 2.25.1