From: Evgeni Dobrev via buildroot <buildroot@buildroot.org>
To: "Yann E. MORIN" <yann.morin.1998@free.fr>
Cc: buildroot@buildroot.org
Subject: Re: [Buildroot] [PATCH 1/1] fs: fix /tmp and /run clean-up in POSIX shells
Date: Thu, 27 Jan 2022 11:34:39 +0100 [thread overview]
Message-ID: <YfJ1ONOCVVlA5JC7@anne> (raw)
In-Reply-To: <20220126221708.GK457876@scaer>
Hi Yann,
indeed the support for [^] vs [!] is more complicated than I thought
initially ( see "Rationale" under https://github.com/koalaman/shellcheck/wiki/SC3026 ).
Would the following be a bad idea:
echo "find $$(TARGET_DIR)/run $$(TARGET_DIR)/tmp -mindepth 1 -delete" >> $$(FAKEROOT_SCRIPT)
- it avoids the glob support complication
- it is shorter
Regards,
Evgeni
On Wed, Jan 26, 2022 at 11:17:08PM +0100, Yann E. MORIN wrote:
> Evgeni, All,
>
> On 2022-01-24 11:41 +0100, Evgeni Dobrev via buildroot spake thusly:
> > In POSIX sh, ^ in place of ! in glob bracket expressions
> > is undefined.
> >
> > Signed-off-by: Evgeni Dobrev <evgeni@studio-punkt.com>
> > ---
> > fs/common.mk | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/fs/common.mk b/fs/common.mk
> > index 45beb5ae7b..64a94d9ad8 100644
> > --- a/fs/common.mk
> > +++ b/fs/common.mk
> > @@ -186,7 +186,7 @@ $$(BINARIES_DIR)/$$(ROOTFS_$(2)_FINAL_IMAGE_NAME): $$(ROOTFS_$(2)_DEPENDENCIES)
> >
> > $$(foreach hook,$$(ROOTFS_$(2)_PRE_GEN_HOOKS),\
> > $$(call PRINTF,$$($$(hook))) >> $$(FAKEROOT_SCRIPT)$$(sep))
> > - echo "rm -rf $$(TARGET_DIR)/run/* $$(TARGET_DIR)/run/.[^.]* $$(TARGET_DIR)/tmp/* $$(TARGET_DIR)/tmp/.[^.]*" >> $$(FAKEROOT_SCRIPT)
> > + echo "rm -rf $$(TARGET_DIR)/run/* $$(TARGET_DIR)/run/.[!.]* $$(TARGET_DIR)/tmp/* $$(TARGET_DIR)/tmp/.[!.]*" >> $$(FAKEROOT_SCRIPT)
>
> TIL that bracket expressions are actually valid and specified by POSIX.
>
> But we do guarantee that we do have bash as a shell when running
> Buildroot, so I think it is fair to also run the fs script with bash:
>
>
> diff --git a/fs/common.mk b/fs/common.mk
> index 45beb5ae7b..f8a6da6bc4 100644
> --- a/fs/common.mk
> +++ b/fs/common.mk
> @@ -172,7 +172,7 @@ $$(BINARIES_DIR)/$$(ROOTFS_$(2)_FINAL_IMAGE_NAME): $$(ROOTFS_$(2)_DEPENDENCIES)
> $$(BASE_TARGET_DIR)/ \
> $$(TARGET_DIR)
>
> - echo '#!/bin/sh' > $$(FAKEROOT_SCRIPT)
> + echo '#!$(SHELL)' > $$(FAKEROOT_SCRIPT)
> echo "set -e" >> $$(FAKEROOT_SCRIPT)
>
> echo "chown -h -R 0:0 $$(TARGET_DIR)" >> $$(FAKEROOT_SCRIPT)
>
> However, $(SHELL) is not always correct, so we'd probably need:
>
> diff --git a/Makefile b/Makefile
> index 5fc7137e5a..bb9955f5b6 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -30,7 +30,7 @@
> # we want bash as shell
> SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
> else if [ -x /bin/bash ]; then echo /bin/bash; \
> - else echo sh; fi; fi)
> + else which sh; fi; fi)
>
> # Set O variable if not already done on the command line;
> # or avoid confusing packages that can use the O=<dir> syntax for out-of-tree
>
> But in the end this is quite more changes than what you propose.
>
> Can we also shorten the command?
>
> echo "rm -rf $$(TARGET_DIR)/{run,tmp}/* $$(TARGET_DIR)/{run,tmp}/.[!.]*" >> $$(FAKEROOT_SCRIPT)
>
> Regards,
> Yann E. MORIN.
>
> > $$(call PRINTF,$$(ROOTFS_REPRODUCIBLE)) >> $$(FAKEROOT_SCRIPT)
> > $$(call PRINTF,$$(ROOTFS_SELINUX)) >> $$(FAKEROOT_SCRIPT)
> > $$(call PRINTF,$$(ROOTFS_$(2)_CMD)) >> $$(FAKEROOT_SCRIPT)
> > --
> > 2.34.1
> >
> > _______________________________________________
> > buildroot mailing list
> > buildroot@buildroot.org
> > https://lists.buildroot.org/mailman/listinfo/buildroot
>
> --
> .-----------------.--------------------.------------------.--------------------.
> | Yann E. MORIN | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
> | +33 662 376 056 | Software Designer | \ / CAMPAIGN | ___ |
> | +33 561 099 427 `------------.-------: X AGAINST | \e/ There is no |
> | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL | v conspiracy. |
> '------------------------------^-------^------------------^--------------------'
> _______________________________________________
> buildroot mailing list
> buildroot@buildroot.org
> https://lists.buildroot.org/mailman/listinfo/buildroot
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot
next prev parent reply other threads:[~2022-01-27 10:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-24 10:41 [Buildroot] [PATCH 0/1] fs: fix /tmp and /run clean-up in POSIX shells Evgeni Dobrev via buildroot
2022-01-24 10:41 ` [Buildroot] [PATCH 1/1] " Evgeni Dobrev via buildroot
2022-01-26 22:17 ` Yann E. MORIN
2022-01-27 10:34 ` Evgeni Dobrev via buildroot [this message]
2022-07-27 15:46 ` Yann E. MORIN
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=YfJ1ONOCVVlA5JC7@anne \
--to=buildroot@buildroot.org \
--cc=evgeni@studio-punkt.com \
--cc=yann.morin.1998@free.fr \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.