kumquat-buildroot/package/skeleton-init-systemd/fakeroot_tmpfiles.sh
Yann E. MORIN d18176396a package/skeleton-systemd: host the tmpfiles preparation script
Commit 0d9b84b7a8 (package/systemd: invoke systemd-tmpfilesd on final
image) forcefully introduced a call to systemd-tmpfiles as a per-rootfs
hook, on the premise that would help with read-only rootfs.

However, that did not account for the then-pre-existing handling of /var
as a factory when the user opted not to remount / read-write (by not
setting BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW).

This means that, for users who want to use a factory for /var, the
generated filesystem contains the factory files twice: once as stored in
the factory, and once as populated by systemd-tmpfilesd.

In the hope to reconcile the two solutions, we move the handling of
calling systemd-tmpfilesd to the skeleton-init-systemd package, where we
already handle the /var factory. Having the two in the same package will
make it easier, in the future, to provide the user with a choice whether
to use one of the other.

Note that it is very important to keep the order of the hooks as they
are.

Indeed, skeleton-init-systemd sorts before systemd, so its hooks were
registered before systemd's hooks; now that we move the CREATE_TMPFILES
hook, we must ensure it is called after the PRE_ROOTFS_VAR one, so that
the behaviour of acting on the var factory remains.

As a final note: we chose the move this way, rather than move the var
factory into the systemd package, because it is more related to the
system integration on the Buildroot side, rather than the integration
of the systemd package in Buildroot.

Similarly, the other four rootfs hooks, SYSTEMD_LOCALE_PURGE_CATALOGS,
SYSTEMD_UPDATE_CATALOGS, SYSTEMD_RM_CATALOG_UPDATE_SERVICE, and
specially SYSTEMD_PRESET_ALL, should also be moved out of the systemd
package, because they too are more related to the Buildroot system,
rather than to the systemd package itself; but the frontier is very
porous in either way, for such a package as special as systemd.

Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
Cc: Norbert Lange <nolange79@gmail.com>
Cc: Arnout Vandecappelle (Essensium/Mind) <arnout@mind.be>
Cc: Romain Naour <romain.naour@smile.fr>
Cc: Jérémy Rosen <jeremy.rosen@smile.fr>
Cc: Yann E. MORIN <yann.morin@orange.com>
Acked-by: Norbert Lange <nolange79@gmail.com>
Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
2022-12-21 22:14:27 +01:00

60 lines
2.3 KiB
Bash
Executable File

#!/bin/sh
#
# The systemd-tmpfiles has the ability to grab information
# from the filesystem (instead from the running system).
#
# tmpfs directories (/tmp, /proc, ...) are skipped since they're not
# relevant for the rootfs image.
#
# However there are a few specifiers that *always* will grab
# information from the running system examples are %a, %b, %m, %H
# (Architecture, Boot UUID, Machine UUID, Hostname).
#
# See [1] for historic information.
#
# This script will (conservatively) skip tmpfiles lines that have
# such an specifier to prevent leaking host information.
#
# shell expansion is critical to be POSIX compliant,
# this script wont work with zsh in its default mode for example.
#
# The script takes several measures to handle more complex stuff
# like passing this correctly:
# f+ "/var/example" - - - - %B\n%o\n%w\n%W%%\n
#
# [1] - https://github.com/systemd/systemd/pull/16187
[ -n "${HOST_SYSTEMD_TMPFILES-}" ] ||
HOST_SYSTEMD_TMPFILES=systemd-tmpfiles
[ -n "${1-}" -a -d "${1-}"/usr/lib/tmpfiles.d ] ||
{ echo 1>&2 "$0: need ROOTFS argument"; exit 1; }
${HOST_SYSTEMD_TMPFILES} --no-pager --cat-config --root="$1" |
sed -e '/^[[:space:]]*#/d' -e 's,^[[:space:]]*,,' -e '/^$/d' |
while read -r line; do
# it is allowed to use quotes around arguments,
# so let the shell pack the arguments
eval "set -- $line"
# dont output warnings for directories we dont process
[ "${2#/dev}" = "${2}" ] && [ "${2#/proc}" = "${2}" ] &&
[ "${2#/run}" = "${2}" ] && [ "${2#/sys}" = "${2}" ] &&
[ "${2#/tmp}" = "${2}" ] && [ "${2#/mnt}" = "${2}" ] ||
continue
# blank out all specs that are ok to use,
# test if some remain. (Specs up to date with v250)
if echo "$2 ${7-}" | sed -e 's,%[%BCEgGhLMosStTuUVwW],,g' | grep -v -q '%'; then
# no "bad" specifiers, pass the line unmodified
eval "printf '%s\n' '$line'"
else
# warn
eval "printf 'ignored spec: %s\n' '$line' 1>&2"
fi
done |
TMPDIR= TEMP= TMP= ${HOST_SYSTEMD_TMPFILES} --create --boot --root="$1" \
--exclude-prefix=/dev --exclude-prefix=/proc --exclude-prefix=/run \
--exclude-prefix=/sys --exclude-prefix=/tmp --exclude-prefix=/mnt \
-