[OE-core] [RFC] opkg: avoid running postinst scripts twice when using systemd

Stefan Agner stefan at agner.ch
Wed Dec 13 18:29:12 UTC 2017


On 2017-12-13 19:06, Stefan Agner wrote:
> From: Stefan Agner <stefan.agner at toradex.com>
> 
> OpenEmbedded has a built-in mechanism to run postinst scripts offline
> at build time or, if necessary, on first boot (delayed execution). If
> the latter is the case and systemd is in use, two services end up
> doing the same thing:
> - opkg-configure.service starts "opkg configure" which in turn parses
>   /var/lib/opkg/status and runs the postinst scripts stored in
>   /var/lib/opkg/info/.
> - run-postinsts.service starts "/usr/sbin/run-postinsts" which runs
>   postinst scripts stored in /etc/ipk-postinsts/. Those scripts get
>   prepared by meta/lib/oe/rootfs.py (see also _save_postinsts of the
>   OpkgRootfs class)
> 
> This can be seen when using a distro using ipk and systemd, then
> installing opkg-keyrings and enable package management. The resulting
> rootfs has both services and will run opkg-keyrings.postinst twice.
> 
> Moreover, because the two services have similar dependency, they
> typically get executed almost at the same time:
>   Dec 13 14:47:25 colibri-imx6 systemd[1]: Starting Opkg first boot configure...
>   ...
>   Dec 13 14:47:25 colibri-imx6 systemd[1]: Starting Run pending postinsts...
> 
> This leads to executions of the same postinst scripts racing with each
> other! In practise update-alternative has been proven to be suspectable
> to such races.
> 
> Get rid of the opkg service to avoid dupplicate postinst execution.

With this applied there is one problem though: opkg status file still
shows the packages as just "unpacked". When running the package manager
(e.g. to install an unrelated package) opkg starts to handle the
postinst nonetheless.

So there is another issue basically. Looking at /usr/sbin/run-postinsts
I see that "opkg configure" is actually triggered if there are no
scripts in /etc/ipk-postinsts. However, meta/lib/oe/rootfs.py calls
_save_postinsts() no matter whether there is package management or no:


...
        if delayed_postinsts:
            self._save_postinsts()
            if image_rorfs:
                bb.warn("There are post install scripts "
                        "in a read-only rootfs")
...


Maybe it needs something like this?


        runtime_pkgmanage = bb.utils.contains("IMAGE_FEATURES",
"package-management",
                                              True, False, self.d)
        if delayed_postinsts and not runtime_pkgmanage:
            self._save_postinsts()
            if image_rorfs:
                bb.warn("There are post install scripts "
                        "in a read-only rootfs")



But then, this is common code for all supported package formats. It
seems that /usr/sbin/run-postinsts only supports package manager
postinst processing for deb and ipk...

Comments appreciated.

--
Stefan

> 
> Signed-off-by: Stefan Agner <stefan.agner at toradex.com>
> ---
>  meta/recipes-devtools/opkg/opkg/opkg-configure.service | 17 -----------------
>  meta/recipes-devtools/opkg/opkg_0.3.5.bb               | 13 -------------
>  2 files changed, 30 deletions(-)
>  delete mode 100644 meta/recipes-devtools/opkg/opkg/opkg-configure.service
> 
> diff --git a/meta/recipes-devtools/opkg/opkg/opkg-configure.service
> b/meta/recipes-devtools/opkg/opkg/opkg-configure.service
> deleted file mode 100644
> index 432c3ddc28..0000000000
> --- a/meta/recipes-devtools/opkg/opkg/opkg-configure.service
> +++ /dev/null
> @@ -1,17 +0,0 @@
> -[Unit]
> -Description=Opkg first boot configure
> -DefaultDependencies=no
> -After=systemd-remount-fs.service systemd-tmpfiles-setup.service tmp.mount
> -Before=sysinit.target
> -
> -[Service]
> -Type=oneshot
> -EnvironmentFile=- at SYSCONFDIR@/default/postinst
> -ExecStart=- at BASE_BINDIR@/sh -c " if [ $POSTINST_LOGGING = '1' ]; then
> @BINDIR@/opkg configure > $LOGFILE 2>&1; else @BINDIR@/opkg configure;
> fi"
> -ExecStartPost=@BASE_BINDIR@/systemctl --no-reload disable
> opkg-configure.service
> -StandardOutput=syslog
> -RemainAfterExit=No
> -
> -[Install]
> -WantedBy=basic.target
> -WantedBy=sysinit.target
> diff --git a/meta/recipes-devtools/opkg/opkg_0.3.5.bb
> b/meta/recipes-devtools/opkg/opkg_0.3.5.bb
> index 3e511b6bb6..fb36e8b866 100644
> --- a/meta/recipes-devtools/opkg/opkg_0.3.5.bb
> +++ b/meta/recipes-devtools/opkg/opkg_0.3.5.bb
> @@ -22,8 +22,6 @@ SRC_URI[sha256sum] =
> "734bc21dea11262113fa86b928d09812618b3966f352350cf916a6ae0d
>  
>  inherit autotools pkgconfig systemd
>  
> -SYSTEMD_SERVICE_${PN} = "opkg-configure.service"
> -
>  target_localstatedir := "${localstatedir}"
>  OPKGLIBDIR = "${target_localstatedir}/lib"
>  
> @@ -46,16 +44,6 @@ do_install_append () {
>  
>  	# We need to create the lock directory
>  	install -d ${D}${OPKGLIBDIR}/opkg
> -
> -	if ${@bb.utils.contains('DISTRO_FEATURES','systemd','true','false',d)};then
> -		install -d ${D}${systemd_unitdir}/system
> -		install -m 0644 ${WORKDIR}/opkg-configure.service
> ${D}${systemd_unitdir}/system/
> -		sed -i -e 's, at BASE_BINDIR@,${base_bindir},g' \
> -			-e 's, at SYSCONFDIR@,${sysconfdir},g' \
> -			-e 's, at BINDIR@,${bindir},g' \
> -			-e 's, at SYSTEMD_UNITDIR@,${systemd_unitdir},g' \
> -			${D}${systemd_unitdir}/system/opkg-configure.service
> -	fi
>  }
>  
>  RDEPENDS_${PN} = "${VIRTUAL-RUNTIME_update-alternatives}
> opkg-arch-config libarchive"
> @@ -68,7 +56,6 @@ RPROVIDES_${PN} = "opkg-collateral"
>  PACKAGES =+ "libopkg"
>  
>  FILES_libopkg = "${libdir}/*.so.* ${OPKGLIBDIR}/opkg/"
> -FILES_${PN} += "${systemd_unitdir}/system/"
>  
>  BBCLASSEXTEND = "native nativesdk"



More information about the Openembedded-core mailing list