From: Yann E. MORIN <yann.morin.1998@free.fr>
To: buildroot@busybox.net
Subject: [Buildroot] [PATCH 18/20] fs: add pre- and post-command hooks
Date: Sun, 23 Jul 2017 16:17:44 +0200 [thread overview]
Message-ID: <20170723141744.GI26998@scaer> (raw)
In-Reply-To: <1a767f33-47a3-5ab6-ed40-00e2bfa31da8@mind.be>
Arnout, All,
On 2017-07-23 15:42 +0200, Arnout Vandecappelle spake thusly:
> On 18-07-17 19:25, Yann E. MORIN wrote:
> > In some cases, the directory structure we want in the filesystem is not
> > exactly what we have in target/
> >
> > For example, when systemd is used on a read-only rootfs, /var must be a
> > tmpfs. However, we may have packages that install stuff in there, and
> > set important rights (via the permission-table). So, at build time, we
> > need /var to be a symlink to the remanent location (/usr/share/factory)
> > while at runtime we need /var to be a directory.
> >
> > One option would have seen to have /var as a real directory even during
> > build time, and in a target-finalize hook, move everything out of there
> > and into the "factory" location. However, that's not possible because
> > it's too early: some packages may want to set ownership and/or acces
> > rights on directories or files in /var, and this is only done in the
> > fakeroot script, which is called only later during the assembling of the
> > filesystem images.
> >
> > Also, there would have been no way to undo the tweak (i.e. we need to
> > restore the /var symlink so that subsequent builds continue to work) if
> > it were done as a target-finalize hook.
> >
> > The only solution is to allow packages to register pre- and post-hooks
> > that are called right before and right after the rootfs commands are
> > executed, and inside in the fakeroot script.
> >
> > We can however not re-use the BR2_ROOTFS_POST_FAKEROOT_SCRIPT feature
> > either because it is done before the filesystem command, but there is
> > nothing that is done after. Also, we don't want to add to, and modify a
> > user-supplied variable.
>
> I completely agree with this approach.
>
> >
> > So, we introduce two new variables that packages can set to add the
> > commands they need to run to tweak the filesystem right at the last
> > moment.
>
> But not with this.
>
> > Those hooks are not documented on-purpose; they are probably going to
> > only ever be used by systemd.
>
> If systemd is the only one ever to use it, then the approach with a list of
> hooks is just too much over the top. Why not hardcode it? Like so:
>
> > Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
> > Reviewed-by: Romain Naour <romain.naour@gmail.com>
> >
> > ---
> > Changes v2 -> v3:
> > - add space between >> and $$ (Romain)
> > ---
> > fs/common.mk | 4 ++++
> > package/pkg-generic.mk | 4 ++++
> > 2 files changed, 8 insertions(+)
> >
> > diff --git a/fs/common.mk b/fs/common.mk
> > index 14e0a6b868..9a7758ff49 100644
> > --- a/fs/common.mk
> > +++ b/fs/common.mk
> > @@ -95,10 +95,14 @@ endif
> > $$(foreach s,$$(call qstrip,$$(BR2_ROOTFS_POST_FAKEROOT_SCRIPT)),\
> > echo "echo '$$(TERM_BOLD)>>> Executing fakeroot script $$(s)$$(TERM_RESET)'" >> $$(FAKEROOT_SCRIPT); \
> > echo $$(s) $$(TARGET_DIR) $$(BR2_ROOTFS_POST_SCRIPT_ARGS) >> $$(FAKEROOT_SCRIPT)$$(sep))
> > + $$(foreach hook,$$(ROOTFS_PRE_CMD_HOOKS),\
> > + $$(call PRINTF,$$($$(hook))) >> $$(FAKEROOT_SCRIPT))
>
> $$(call PRINTF,$$(ROOTFS_SKELETON_PRE_CMD_HOOK)) >> $$(FAKEROOT_SCRIPT)
>
> You may want to change the variable name, obviously.
And it also means that the declaration of ROOTFS_SKELETON_PRE_CMD_HOOK
be conditional in the skeleton-systemd package, like:
ifeq ($(BR2_PACKAGE_SKELETON_SYSTEMD),y)
define ROOTFS_SKELETON_PRE_CMD_HOOK
blabla
endef
endif
But I do not like these kind of constructs in the packages themselves,
because they are too easy to miss...
Alternatively, I would rather move that logic into the filesystem code
itself, because after all that is its responsibility, and guard its use
with something like (with a proper variable name, of course):
ifeq ($(ROOTFS_VAR_FACTORY_BLABLA),YES)
blabla...
endif
And then have the packages that need it just set:
ROOTFS_VAR_FACTORY_BLABLA = YES
All that, because Thomas already suggested (last year in Toulouse) that
we could re-use the same factory mechanism for the other init systems as
well (on read-only rootfs). In this case, the code would then be guarded
by an test against an empty $(BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW),
because then there would be no relation to an init system at all.
But the tmpfiles format is very specific to systemd; we'd have to write
our own parser for that (not too difficult, I think, but it'd run on
the target so it'd have to be really dead-simple).
So in the end, I'd remove the hooks and move the code to the fs
handling, protected by a conditional that so far only systemd would set.
OK with this new approach?
Still, there is yet ine thing that I dislike in this solution, whether
it be with hooks or the variable, and that noone has seen so far: it is
not atomic and the target/ directory will be broken if the filesystem
command fails right in the middle, before the var symlink was restored.
I have seen no solution to this issue, except doing a copy of target
first, right before assembling the image(s), becasue in that case, we
wouldn't care about restoring the previous status, so we would no longer
need atomicity.
Regards,
Yann E. MORIN.
> Regards,
> Arnout
>
>
> [snip]
>
> --
> Arnout Vandecappelle arnout at mind be
> Senior Embedded Software Architect +32-16-286500
> Essensium/Mind http://www.mind.be
> G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven
> LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
> GPG fingerprint: 7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
--
.-----------------.--------------------.------------------.--------------------.
| Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ |
| +33 223 225 172 `------------.-------: X AGAINST | \e/ There is no |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |
'------------------------------^-------^------------------^--------------------'
next prev parent reply other threads:[~2017-07-23 14:17 UTC|newest]
Thread overview: 108+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-18 17:25 [Buildroot] [PATCH 00/20] system: properly handle systemd as init system Yann E. MORIN
2017-07-18 17:25 ` [Buildroot] [PATCH 01/20] support/tests: allow properly indented config fragment Yann E. MORIN
2017-07-18 20:45 ` Yann E. MORIN
2017-07-18 17:25 ` [Buildroot] [PATCH 02/20] core/pkg-generic: add variable to skip skeleton dependency Yann E. MORIN
2017-07-22 12:27 ` Arnout Vandecappelle
2017-07-23 9:12 ` Peter Korsgaard
2017-07-23 9:21 ` Yann E. MORIN
2017-07-23 13:01 ` Peter Korsgaard
2017-07-22 13:41 ` Thomas Petazzoni
2017-07-18 17:25 ` [Buildroot] [PATCH 03/20] package/skeleton: add macro to rsync skeleton directory Yann E. MORIN
2017-07-22 12:34 ` Arnout Vandecappelle
2017-07-22 13:02 ` Arnout Vandecappelle
2017-07-22 14:33 ` Yann E. MORIN
2017-07-22 13:42 ` Thomas Petazzoni
2017-07-18 17:25 ` [Buildroot] [PATCH 04/20] package/skeleton: make SKELETON_LIB_SYMLINK a macro Yann E. MORIN
2017-07-22 12:56 ` Arnout Vandecappelle
2017-07-22 19:47 ` Thomas Petazzoni
2017-07-22 21:02 ` [Buildroot] Is MIPS_NABI32 a 64-bit architecture? [was: [PATCH 04/20] package/skeleton: make SKELETON_LIB_SYMLINK a macro] Arnout Vandecappelle
2017-07-22 13:50 ` [Buildroot] [PATCH 04/20] package/skeleton: make SKELETON_LIB_SYMLINK a macro Thomas Petazzoni
2017-07-22 14:23 ` Yann E. MORIN
2017-07-22 19:45 ` Thomas Petazzoni
2017-07-18 17:25 ` [Buildroot] [PATCH 05/20] system: provide package-wide system variables and macros Yann E. MORIN
2017-07-22 13:00 ` Arnout Vandecappelle
2017-07-18 17:25 ` [Buildroot] [PATCH 06/20] system: move setting getty to the corresponding init systems Yann E. MORIN
2017-07-22 13:11 ` Arnout Vandecappelle
2017-07-22 19:57 ` Thomas Petazzoni
2017-07-22 21:13 ` Arnout Vandecappelle
2017-07-22 20:34 ` Thomas Petazzoni
2017-07-18 17:25 ` [Buildroot] [PATCH 07/20] system: move remounting / " Yann E. MORIN
2017-07-22 13:16 ` Arnout Vandecappelle
2017-07-22 20:36 ` Thomas Petazzoni
2017-07-18 17:25 ` [Buildroot] [PATCH 08/20] system: with no init system, only allow custom skeleton Yann E. MORIN
2017-07-22 13:28 ` Arnout Vandecappelle
2017-07-22 13:53 ` Yann E. MORIN
2017-07-22 21:18 ` Arnout Vandecappelle
2017-07-22 22:12 ` Yann E. MORIN
2017-07-18 17:25 ` [Buildroot] [PATCH 09/20] package/skeleton: drop dependency on host-mkpasswd Yann E. MORIN
2017-07-22 21:24 ` Arnout Vandecappelle
2017-07-22 22:32 ` Yann E. MORIN
2017-07-18 17:25 ` [Buildroot] [PATCH 10/20] package/skeleton: select it rather than default to y Yann E. MORIN
2017-07-22 21:47 ` Arnout Vandecappelle
2017-07-18 17:25 ` [Buildroot] [PATCH 11/20] package/skeleton: split out into skeleton-custom Yann E. MORIN
2017-07-22 22:31 ` Arnout Vandecappelle
2017-07-22 22:38 ` Arnout Vandecappelle
2017-07-23 9:45 ` Yann E. MORIN
2017-07-18 17:25 ` [Buildroot] [PATCH 12/20] package/skeleton: split out into skeleton-common Yann E. MORIN
2017-07-22 23:06 ` Arnout Vandecappelle
2017-07-23 9:48 ` Yann E. MORIN
2017-07-23 20:32 ` Arnout Vandecappelle
2017-07-24 7:19 ` Thomas Petazzoni
2017-07-24 15:19 ` Yann E. MORIN
2017-07-18 17:25 ` [Buildroot] [PATCH 13/20] package/skeleton: make it a virtual package Yann E. MORIN
2017-07-22 23:36 ` Arnout Vandecappelle
2017-07-23 10:13 ` Yann E. MORIN
2017-07-23 20:48 ` Arnout Vandecappelle
2017-07-18 17:25 ` [Buildroot] [PATCH 14/20] package/skeleton-common: simplify staging install Yann E. MORIN
2017-07-22 23:38 ` Arnout Vandecappelle
2017-07-18 17:25 ` [Buildroot] [PATCH 15/20] package/skeleton: introduce sysv- and systemd-specific skeletons Yann E. MORIN
2017-07-22 23:49 ` Arnout Vandecappelle
2017-07-23 10:15 ` Yann E. MORIN
2017-07-18 17:25 ` [Buildroot] [PATCH 16/20] system: separate sysv and systemd parts of the skeleton Yann E. MORIN
2017-07-23 0:08 ` Arnout Vandecappelle
2017-07-23 0:13 ` Arnout Vandecappelle
2017-07-23 10:31 ` Yann E. MORIN
2017-07-23 10:24 ` Yann E. MORIN
2017-07-23 13:32 ` Arnout Vandecappelle
2017-07-23 13:39 ` Arnout Vandecappelle
2017-07-23 13:41 ` Yann E. MORIN
2017-07-18 17:25 ` [Buildroot] [PATCH 17/20] sytem: no-init systems may use our default, common skeleton Yann E. MORIN
2017-07-23 0:18 ` Arnout Vandecappelle
2017-07-23 10:37 ` Yann E. MORIN
2017-07-18 17:25 ` [Buildroot] [PATCH 18/20] fs: add pre- and post-command hooks Yann E. MORIN
2017-07-23 13:42 ` Arnout Vandecappelle
2017-07-23 14:17 ` Yann E. MORIN [this message]
2017-07-23 21:51 ` Arnout Vandecappelle
2017-07-24 16:01 ` Yann E. MORIN
2017-07-24 22:23 ` Arnout Vandecappelle
2017-07-18 17:25 ` [Buildroot] [PATCH 19/20] system: make systemd work on a read-only rootfs Yann E. MORIN
2017-07-23 22:18 ` Arnout Vandecappelle
2017-07-24 15:45 ` Yann E. MORIN
2017-07-24 22:44 ` Arnout Vandecappelle
2017-07-25 16:07 ` Yann E. MORIN
2017-07-25 22:24 ` Arnout Vandecappelle
2017-07-18 17:25 ` [Buildroot] [PATCH 20/20] support/testing: add runtime testing for init systems Yann E. MORIN
2017-07-22 14:32 ` Arnout Vandecappelle
2017-07-22 14:45 ` Yann E. MORIN
2017-07-22 19:30 ` Thomas Petazzoni
2017-07-22 19:53 ` Arnout Vandecappelle
2017-07-22 20:10 ` Thomas Petazzoni
2017-07-22 22:50 ` Yann E. MORIN
2017-07-23 7:58 ` Thomas Petazzoni
2017-07-23 9:26 ` Yann E. MORIN
2017-07-23 18:13 ` [Buildroot] TestIso9660GrubExternal and TestIso9660GrubInternal failing Ricardo Martincoski
2017-07-23 20:02 ` Yann E. MORIN
2017-07-23 20:28 ` Yann E. MORIN
2017-07-23 20:39 ` Yann E. MORIN
2017-07-24 7:13 ` Thomas Petazzoni
2017-07-24 11:07 ` Ricardo Martincoski
2017-07-24 15:18 ` Yann E. MORIN
2017-07-24 15:20 ` [Buildroot] [PATCH 20/20] support/testing: add runtime testing for init systems Andrey Smirnov
2017-07-24 15:50 ` Yann E. MORIN
2017-07-19 20:14 ` [Buildroot] [PATCH 00/20] system: properly handle systemd as init system Andrey Yurovsky
2017-07-19 20:53 ` Thomas Petazzoni
2017-07-19 22:17 ` Andrey Yurovsky
2017-07-20 7:32 ` Thomas Petazzoni
2017-07-21 22:15 ` Marcus Hoffmann
2017-07-28 20:41 ` Marcus Hoffmann
2017-07-28 20:54 ` Thomas Petazzoni
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=20170723141744.GI26998@scaer \
--to=yann.morin.1998@free.fr \
--cc=buildroot@busybox.net \
/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