From: Jo-Philipp Wich Date: Fri, 10 Feb 2017 10:05:44 +0000 (+0100) Subject: libopkg: run prerm scripts for the old version also on upgrade X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=5d0179bd88a83c5f4d9a3b8393a28f0c6a30d1c1;p=oweals%2Fopkg-lede.git 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 --- 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