Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Stefan Agner <stefan@agner.ch>
To: openembedded-core@lists.openembedded.org
Cc: Stefan Agner <stefan.agner@toradex.com>, muhammad_shakeel@mentor.com
Subject: [RFC] opkg: avoid running postinst scripts twice when using systemd
Date: Wed, 13 Dec 2017 19:06:24 +0100	[thread overview]
Message-ID: <20171213180624.30839-1-stefan@agner.ch> (raw)

From: Stefan Agner <stefan.agner@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.

Signed-off-by: Stefan Agner <stefan.agner@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=-@SYSCONFDIR@/default/postinst
-ExecStart=-@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,@BASE_BINDIR@,${base_bindir},g' \
-			-e 's,@SYSCONFDIR@,${sysconfdir},g' \
-			-e 's,@BINDIR@,${bindir},g' \
-			-e 's,@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"
 
-- 
2.13.6



             reply	other threads:[~2017-12-13 18:06 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-13 18:06 Stefan Agner [this message]
2017-12-13 18:29 ` [RFC] opkg: avoid running postinst scripts twice when using systemd Stefan Agner
2017-12-14 13:10   ` Alexander Kanavin
2017-12-14 13:11     ` Stefan Agner
2017-12-14 13:52       ` Alexander Kanavin
2017-12-14 13:59         ` Stefan Agner
2017-12-14 14:24           ` Alexander Kanavin
2017-12-14 14:41             ` Stefan Agner
2017-12-14 14:55               ` Alexander Kanavin
2017-12-14 14:57                 ` Stefan Agner
2017-12-14 15:14                   ` Alexander Kanavin
2017-12-14 16:46                     ` Stefan Agner
2017-12-14 16:59                       ` Alexander Kanavin
2017-12-14 17:16                         ` Stefan Agner
2017-12-14 17:28                           ` Alexander Kanavin
2017-12-14 17:40                             ` Stefan Agner
2017-12-14 17:49                               ` Alexander Kanavin
2017-12-14 18:04                                 ` Alexander Kanavin
2017-12-16 12:02                                   ` Stefan Agner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171213180624.30839-1-stefan@agner.ch \
    --to=stefan@agner.ch \
    --cc=muhammad_shakeel@mentor.com \
    --cc=openembedded-core@lists.openembedded.org \
    --cc=stefan.agner@toradex.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox