[meta-oe][PATCH] usbmuxd: create the usbmux user the udev rule requires

Eric Chiang <[email protected]>
Newsgroups org.openembedded.lists.openembedded-devel
Message-ID <[email protected]>
usbmuxd ships 39-usbmuxd.rules, which starts the daemon when an Apple
device appears:

  ACTION=="add", ..., OWNER="usbmux", ENV{SYSTEMD_WANTS}="usbmuxd.service"

The recipe never creates that account. Up to systemd v257 udev only
logged a warning and the rest of the line still ran. systemd a1ee55e3c9
("udev-rules: ignore OWNER=/GROUP= with unknown user/group", first
released in v258) makes udev drop the whole rule line instead, so
SYSTEMD_WANTS is never applied and usbmuxd is never started when a
device is plugged in.

Creating the account is what the rule already expects, and it preserves
the intent of the systemd change: that change guards against a rule
naming a nonexistent user silently clearing a valid earlier ownership
assignment, and with the account present there is no nonexistent user.
Removing OWNER= from the rule would evade that check instead of
satisfying it. The daemon still runs as root, so nothing else changes.

Also ship a sysusers.d fragment. Systems that modified a user or
password at runtime carry a copied-up /etc/passwd in a writable /etc,
which masks an account added at image build time even after an update;
systemd-sysusers recreates it there. The uid may then differ, but the
udev rule resolves the account by name and the daemon runs as root, so
only the name matters.

Distros that keep /etc on persistent storage may also need
systemd-sysusers to actually run on boot; that is outside the scope of
this recipe.

Signed-off-by: Eric Chiang <[email protected]>
---
 .../recipes-connectivity/usbmuxd/usbmuxd_git.bb   | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/meta-oe/recipes-connectivity/usbmuxd/usbmuxd_git.bb b/meta-oe/recipes-connectivity/usbmuxd/usbmuxd_git.bb
index c5e0fbee1a..6258bc5134 100644
--- a/meta-oe/recipes-connectivity/usbmuxd/usbmuxd_git.bb
+++ b/meta-oe/recipes-connectivity/usbmuxd/usbmuxd_git.bb
@@ -6,7 +6,7 @@ LIC_FILES_CHKSUM = "file://COPYING.GPLv2;md5=ebb5c50ab7cab4baeffba14977030c07 \
 
 DEPENDS = "udev libusb1 libplist libimobiledevice-glue"
 
-inherit autotools pkgconfig gitpkgv systemd
+inherit autotools pkgconfig gitpkgv systemd useradd
 
 PKGV = "${GITPKGVTAG}"
 PV = "1.1.2+git"
@@ -22,5 +22,18 @@ UPSTREAM_CHECK_COMMITS = "1"
 EXTRA_OECONF += "--without-preflight"
 
 FILES:${PN} += "${base_libdir}/udev/rules.d/"
+FILES:${PN} += "${nonarch_libdir}/sysusers.d"
 
 SYSTEMD_SERVICE:${PN} = "usbmuxd.service"
+
+# 39-usbmuxd.rules carries OWNER="usbmux"; from systemd v258 udev drops the
+# whole rule line when the user does not exist, so the daemon is never
+# started. Create the account, and ship a sysusers.d fragment so it is also
+# recreated on systems whose /etc predates this recipe.
+USERADD_PACKAGES = "${PN}"
+USERADD_PARAM:${PN} = "--system --no-create-home --shell /bin/false --user-group usbmux"
+
+do_install:append() {
+    install -d ${D}${nonarch_libdir}/sysusers.d
+    printf 'u usbmux - "usbmux daemon"\n' > ${D}${nonarch_libdir}/sysusers.d/usbmuxd.conf
+}
-- 
2.53.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.