All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns
@ 2022-03-10 10:18 Mathieu Mirmont via buildroot
  2022-03-10 10:45 ` David Laight
                   ` (4 more replies)
  0 siblings, 5 replies; 13+ messages in thread
From: Mathieu Mirmont via buildroot @ 2022-03-10 10:18 UTC (permalink / raw)
  To: buildroot


[-- Attachment #1.1: Type: text/plain, Size: 1786 bytes --]

Different shells can have different behaviours when it comes to
globbing patterns. The dash shell (/bin/sh) on Debian testing switched
to a different fnmatch/glob implementation that results in this new
behaviour:

Using bash:
$ mkdir /tmp/foo
$ echo /tmp/foo/.[^.]*
/tmp/foo/.[^.]*

Using dash:
$ mkdir /tmp/foo
$ echo /tmp/foo/.[^.]*
/tmp/foo/..

The current FAKEROOT script uses this shell glob pattern which now
fails on recent Debian testing systems:

rm: refusing to remove '.' or '..' directory: skipping '/build/buildroot-fs/cpio/target/run/..'
rm: refusing to remove '.' or '..' directory: skipping '/build/buildroot-fs/cpio/target/tmp/..'

It seems safer to use `find | xargs rm` here instead of relying on
shell globbing patterns.

Signed-off-by: Mathieu Mirmont <mat@parad0x.org>
---
 fs/common.mk | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/common.mk b/fs/common.mk
index 45beb5ae7b..37eafac4f7 100644
--- a/fs/common.mk
+++ b/fs/common.mk
@@ -186,7 +186,8 @@ $$(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 "find $$(TARGET_DIR)/run/ -mindepth 1 -prune -print0 | xargs -0r rm -rf --" >> $$(FAKEROOT_SCRIPT)
+	echo "find $$(TARGET_DIR)/tmp/ -mindepth 1 -prune -print0 | xargs -0r rm -rf --" >> $$(FAKEROOT_SCRIPT)
 	$$(call PRINTF,$$(ROOTFS_REPRODUCIBLE)) >> $$(FAKEROOT_SCRIPT)
 	$$(call PRINTF,$$(ROOTFS_SELINUX)) >> $$(FAKEROOT_SCRIPT)
 	$$(call PRINTF,$$(ROOTFS_$(2)_CMD)) >> $$(FAKEROOT_SCRIPT)
-- 
2.34.1


[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 150 bytes --]

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns
  2022-03-10 10:18 [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns Mathieu Mirmont via buildroot
@ 2022-03-10 10:45 ` David Laight
  2022-03-10 11:33   ` Mat via buildroot
  2022-03-10 11:22 ` Edgar Bonet
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: David Laight @ 2022-03-10 10:45 UTC (permalink / raw)
  To: 'Mathieu Mirmont', buildroot

From: Mathieu Mirmont
> Sent: 10 March 2022 10:18
> 
> Different shells can have different behaviours when it comes to
> globbing patterns. The dash shell (/bin/sh) on Debian testing switched
> to a different fnmatch/glob implementation that results in this new
> behaviour:
> 
> Using bash:
> $ mkdir /tmp/foo
> $ echo /tmp/foo/.[^.]*
> /tmp/foo/.[^.]*
> 
> Using dash:
> $ mkdir /tmp/foo
> $ echo /tmp/foo/.[^.]*
> /tmp/foo/..

That is just broken.
Does the [^x] pattern work at all?

Raise a bug on 'Debian testing' hopefully they'll
fix it before it actually gets released anywhere.

For this script I'd just ignore errors from rm.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns
  2022-03-10 10:18 [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns Mathieu Mirmont via buildroot
  2022-03-10 10:45 ` David Laight
@ 2022-03-10 11:22 ` Edgar Bonet
  2022-03-10 11:31   ` David Laight
  2022-03-10 12:02 ` [Buildroot] [PATCH v2] fs/common.mk: fix the globing pattern Mathieu Mirmont via buildroot
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 13+ messages in thread
From: Edgar Bonet @ 2022-03-10 11:22 UTC (permalink / raw)
  To: Mathieu Mirmont, buildroot

Mathieu Mirmont wrote:
> Using dash:
> $ mkdir /tmp/foo
> $ echo /tmp/foo/.[^.]*
> /tmp/foo/..

There is an error in this glob pattern. Fixing it would be simpler than
invoking find/xargs.

Within a regexp, character classes are complemented with "^": [^.] means
"any character other that a dot". Within a glob pattern, character
classes are complemented with "!", and the same class would be written
[!.]

C.f. glob(7).

Regards,

Edgar.
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns
  2022-03-10 11:22 ` Edgar Bonet
@ 2022-03-10 11:31   ` David Laight
  0 siblings, 0 replies; 13+ messages in thread
From: David Laight @ 2022-03-10 11:31 UTC (permalink / raw)
  To: 'Edgar Bonet', Mathieu Mirmont, buildroot

From: Of Edgar Bonet
> Sent: 10 March 2022 11:22
> 
> Mathieu Mirmont wrote:
> > Using dash:
> > $ mkdir /tmp/foo
> > $ echo /tmp/foo/.[^.]*
> > /tmp/foo/..
> 
> There is an error in this glob pattern. Fixing it would be simpler than
> invoking find/xargs.
> 
> Within a regexp, character classes are complemented with "^": [^.] means
> "any character other that a dot". Within a glob pattern, character
> classes are complemented with "!", and the same class would be written
> [!.]

I should know that :-)

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns
  2022-03-10 10:45 ` David Laight
@ 2022-03-10 11:33   ` Mat via buildroot
  2022-03-10 11:52     ` David Laight
  0 siblings, 1 reply; 13+ messages in thread
From: Mat via buildroot @ 2022-03-10 11:33 UTC (permalink / raw)
  To: David Laight; +Cc: buildroot


[-- Attachment #1.1: Type: text/plain, Size: 899 bytes --]

On Thu, Mar 10, 2022 at 10:45:41AM +0000, David Laight wrote:
> From: Mathieu Mirmont
> > Sent: 10 March 2022 10:18
> > 
> > Different shells can have different behaviours when it comes to
> > globbing patterns. The dash shell (/bin/sh) on Debian testing switched
> > to a different fnmatch/glob implementation that results in this new
> > behaviour:
> > 
> > Using bash:
> > $ mkdir /tmp/foo
> > $ echo /tmp/foo/.[^.]*
> > /tmp/foo/.[^.]*
> > 
> > Using dash:
> > $ mkdir /tmp/foo
> > $ echo /tmp/foo/.[^.]*
> > /tmp/foo/..
> 
> That is just broken.
> Does the [^x] pattern work at all?
>
> Raise a bug on 'Debian testing' hopefully they'll
> fix it before it actually gets released anywhere.

The new behaviour of dash is very strange indeed, but also according
to POSIX the wildcard pattern [^x] is undefined so we should not rely
on it.

-- 
Mat <mat@parad0x.org>

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 150 bytes --]

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns
  2022-03-10 11:33   ` Mat via buildroot
@ 2022-03-10 11:52     ` David Laight
  2022-03-10 12:11       ` Mathieu Mirmont via buildroot
  0 siblings, 1 reply; 13+ messages in thread
From: David Laight @ 2022-03-10 11:52 UTC (permalink / raw)
  To: 'Mat'; +Cc: buildroot

From: Mat
> Sent: 10 March 2022 11:33
> 
> On Thu, Mar 10, 2022 at 10:45:41AM +0000, David Laight wrote:
> > From: Mathieu Mirmont
> > > Sent: 10 March 2022 10:18
> > >
> > > Different shells can have different behaviours when it comes to
> > > globbing patterns. The dash shell (/bin/sh) on Debian testing switched
> > > to a different fnmatch/glob implementation that results in this new
> > > behaviour:
> > >
> > > Using bash:
> > > $ mkdir /tmp/foo
> > > $ echo /tmp/foo/.[^.]*
> > > /tmp/foo/.[^.]*
> > >
> > > Using dash:
> > > $ mkdir /tmp/foo
> > > $ echo /tmp/foo/.[^.]*
> > > /tmp/foo/..
> >
> > That is just broken.
> > Does the [^x] pattern work at all?
> >
> > Raise a bug on 'Debian testing' hopefully they'll
> > fix it before it actually gets released anywhere.
> 
> The new behaviour of dash is very strange indeed, but also according
> to POSIX the wildcard pattern [^x] is undefined so we should not rely
> on it.

Well [^x] originally meant '^' or 'x' (the same as [x^] but then
shells started treating [^x] the same as [!x].
So I guess POSIX has allowed such shells to be conformant by
making [^x] undefined.

I'm not sure how many shells treat [^x] the same as [!x] but
enough do that people (including me) have forgotten the difference.
ash from a recent buildroot treats [^x] as [!x} but a cygwin
ash I've got doesn't.
A quick search failed to find dash.

ISTR dash is badly broken in other places, try:
$ x=aaab234; echo ${x##${x%%b*}}
b234

It is worth checking whether Debian have changed the behaviour of dash
or whether they've just changed the default root shell to dash.

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Buildroot] [PATCH v2] fs/common.mk: fix the globing pattern
  2022-03-10 10:18 [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns Mathieu Mirmont via buildroot
  2022-03-10 10:45 ` David Laight
  2022-03-10 11:22 ` Edgar Bonet
@ 2022-03-10 12:02 ` Mathieu Mirmont via buildroot
  2022-03-12 16:19   ` Yann E. MORIN
  2022-03-12 16:52 ` [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns Yann E. MORIN
  2022-03-19 19:01 ` Peter Korsgaard
  4 siblings, 1 reply; 13+ messages in thread
From: Mathieu Mirmont via buildroot @ 2022-03-10 12:02 UTC (permalink / raw)
  To: buildroot


[-- Attachment #1.1: Type: text/plain, Size: 1679 bytes --]

The FAKEROOT script uses [^x] wildcard patterns which, while supported
by many shells and interpreted like a regex, are undefined according
to POSIX.

The dash shell (/bin/sh) on Debian testing switched to a different
fnmatch/glob implementation that does not support [^x]. Instead it
treats [^x] as either "^" or "x", and as a result buildroot fails to
build on this distro:

rm: refusing to remove '.' or '..' directory: skipping '/build/buildroot-fs/cpio/target/run/..'
rm: refusing to remove '.' or '..' directory: skipping '/build/buildroot-fs/cpio/target/tmp/..'

The correct form should be [!x] rather than [^x].

Signed-off-by: Mathieu Mirmont <mat@parad0x.org>
---
 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)
 	$$(call PRINTF,$$(ROOTFS_REPRODUCIBLE)) >> $$(FAKEROOT_SCRIPT)
 	$$(call PRINTF,$$(ROOTFS_SELINUX)) >> $$(FAKEROOT_SCRIPT)
 	$$(call PRINTF,$$(ROOTFS_$(2)_CMD)) >> $$(FAKEROOT_SCRIPT)
-- 
2.35.1
Changes v1 -> v2:
  - Fix the regex rather than use find|xargs (suggested by Edgar Bonet & David Laight)


[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 150 bytes --]

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply related	[flat|nested] 13+ messages in thread

* Re: [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns
  2022-03-10 11:52     ` David Laight
@ 2022-03-10 12:11       ` Mathieu Mirmont via buildroot
  2022-03-10 13:47         ` David Laight
  0 siblings, 1 reply; 13+ messages in thread
From: Mathieu Mirmont via buildroot @ 2022-03-10 12:11 UTC (permalink / raw)
  To: David Laight; +Cc: buildroot


[-- Attachment #1.1: Type: text/plain, Size: 488 bytes --]

On Thu, Mar 10, 2022 at 11:52:08AM +0000, David Laight wrote:
> It is worth checking whether Debian have changed the behaviour of dash
> or whether they've just changed the default root shell to dash.

They've switched to the internal fnmatch implementation of dash [1] in
this commit [1]. Before that they were using fnmatch(3) from the
glibc.

[1] https://salsa.debian.org/debian/dash/-/commit/d7b1269eeeb5749ccc577f6e01dfccc2916b0130

-- 
Mathieu Mirmont <mat@parad0x.org>

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 150 bytes --]

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns
  2022-03-10 12:11       ` Mathieu Mirmont via buildroot
@ 2022-03-10 13:47         ` David Laight
  2022-03-10 15:42           ` Mathieu Mirmont via buildroot
  0 siblings, 1 reply; 13+ messages in thread
From: David Laight @ 2022-03-10 13:47 UTC (permalink / raw)
  To: 'Mathieu Mirmont'; +Cc: buildroot

From: Mathieu Mirmont
> Sent: 10 March 2022 12:11
> 
> On Thu, Mar 10, 2022 at 11:52:08AM +0000, David Laight wrote:
> > It is worth checking whether Debian have changed the behaviour of dash
> > or whether they've just changed the default root shell to dash.
> 
> They've switched to the internal fnmatch implementation of dash [1] in
> this commit [1]. Before that they were using fnmatch(3) from the
> glibc.
> 
> [1] https://salsa.debian.org/debian/dash/-/commit/d7b1269eeeb5749ccc577f6e01dfccc2916b0130

Hmmm:

    External implementations change in subtle ways, leading to hard to
    diagnose bugs. It’s better to rely on the built-in implementation
    instead.

As does randomly changing the implementation!

Anyone signed up to the debian lists to comment?

	David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns
  2022-03-10 13:47         ` David Laight
@ 2022-03-10 15:42           ` Mathieu Mirmont via buildroot
  0 siblings, 0 replies; 13+ messages in thread
From: Mathieu Mirmont via buildroot @ 2022-03-10 15:42 UTC (permalink / raw)
  To: David Laight; +Cc: buildroot


[-- Attachment #1.1: Type: text/plain, Size: 974 bytes --]

On Thu, Mar 10, 2022 at 01:47:24PM +0000, David Laight wrote:
> From: Mathieu Mirmont
> > Sent: 10 March 2022 12:11
> > 
> > On Thu, Mar 10, 2022 at 11:52:08AM +0000, David Laight wrote:
> > > It is worth checking whether Debian have changed the behaviour of dash
> > > or whether they've just changed the default root shell to dash.
> > 
> > They've switched to the internal fnmatch implementation of dash [1] in
> > this commit [1]. Before that they were using fnmatch(3) from the
> > glibc.
> > 
> > [1] https://salsa.debian.org/debian/dash/-/commit/d7b1269eeeb5749ccc577f6e01dfccc2916b0130
> 
> Hmmm:
> 
>     External implementations change in subtle ways, leading to hard to
>     diagnose bugs. It’s better to rely on the built-in implementation
>     instead.
> 
> As does randomly changing the implementation!

True, however [^x] is not part of POSIX so it can't be expected to
work with /bin/sh.

-- 
Mathieu Mirmont <mat@parad0x.org>

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

[-- Attachment #2: Type: text/plain, Size: 150 bytes --]

_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Buildroot] [PATCH v2] fs/common.mk: fix the globing pattern
  2022-03-10 12:02 ` [Buildroot] [PATCH v2] fs/common.mk: fix the globing pattern Mathieu Mirmont via buildroot
@ 2022-03-12 16:19   ` Yann E. MORIN
  0 siblings, 0 replies; 13+ messages in thread
From: Yann E. MORIN @ 2022-03-12 16:19 UTC (permalink / raw)
  To: Mathieu Mirmont; +Cc: buildroot

Mathieu, All,

On 2022-03-10 13:02 +0100, Mathieu Mirmont via buildroot spake thusly:
> The FAKEROOT script uses [^x] wildcard patterns which, while supported
> by many shells and interpreted like a regex, are undefined according
> to POSIX.
> 
> The dash shell (/bin/sh) on Debian testing switched to a different
> fnmatch/glob implementation that does not support [^x]. Instead it
> treats [^x] as either "^" or "x", and as a result buildroot fails to
> build on this distro:
> 
> rm: refusing to remove '.' or '..' directory: skipping '/build/buildroot-fs/cpio/target/run/..'
> rm: refusing to remove '.' or '..' directory: skipping '/build/buildroot-fs/cpio/target/tmp/..'
> 
> The correct form should be [!x] rather than [^x].
> 
> Signed-off-by: Mathieu Mirmont <mat@parad0x.org>
> ---
>  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)

I think I preferred your find-based solution, because, as far as I
understand, this is still broken, as it won't match files named, for
example "..foo"

The find-based solution, though, should work for everything and does not
risk any issue with badly interpreted blobs in varios shells and various
shell versions.

Regards,
Yann E. MORIN.

>  	$$(call PRINTF,$$(ROOTFS_REPRODUCIBLE)) >> $$(FAKEROOT_SCRIPT)
>  	$$(call PRINTF,$$(ROOTFS_SELINUX)) >> $$(FAKEROOT_SCRIPT)
>  	$$(call PRINTF,$$(ROOTFS_$(2)_CMD)) >> $$(FAKEROOT_SCRIPT)
> -- 
> 2.35.1
> Changes v1 -> v2:
>   - Fix the regex rather than use find|xargs (suggested by Edgar Bonet & David Laight)
> 



> _______________________________________________
> 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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns
  2022-03-10 10:18 [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns Mathieu Mirmont via buildroot
                   ` (2 preceding siblings ...)
  2022-03-10 12:02 ` [Buildroot] [PATCH v2] fs/common.mk: fix the globing pattern Mathieu Mirmont via buildroot
@ 2022-03-12 16:52 ` Yann E. MORIN
  2022-03-19 19:01 ` Peter Korsgaard
  4 siblings, 0 replies; 13+ messages in thread
From: Yann E. MORIN @ 2022-03-12 16:52 UTC (permalink / raw)
  To: Mathieu Mirmont; +Cc: buildroot

Mathieu, All,

On 2022-03-10 11:18 +0100, Mathieu Mirmont via buildroot spake thusly:
> Different shells can have different behaviours when it comes to
> globbing patterns. The dash shell (/bin/sh) on Debian testing switched
> to a different fnmatch/glob implementation that results in this new
> behaviour:
> 
> Using bash:
> $ mkdir /tmp/foo
> $ echo /tmp/foo/.[^.]*
> /tmp/foo/.[^.]*
> 
> Using dash:
> $ mkdir /tmp/foo
> $ echo /tmp/foo/.[^.]*
> /tmp/foo/..
> 
> The current FAKEROOT script uses this shell glob pattern which now
> fails on recent Debian testing systems:
> 
> rm: refusing to remove '.' or '..' directory: skipping '/build/buildroot-fs/cpio/target/run/..'
> rm: refusing to remove '.' or '..' directory: skipping '/build/buildroot-fs/cpio/target/tmp/..'
> 
> It seems safer to use `find | xargs rm` here instead of relying on
> shell globbing patterns.
> 
> Signed-off-by: Mathieu Mirmont <mat@parad0x.org>

I applied to master, after adding a little blurb about the ..foo files
that would be missed with globs.

> ---
>  fs/common.mk | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/fs/common.mk b/fs/common.mk
> index 45beb5ae7b..37eafac4f7 100644
> --- a/fs/common.mk
> +++ b/fs/common.mk
> @@ -186,7 +186,8 @@ $$(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 "find $$(TARGET_DIR)/run/ -mindepth 1 -prune -print0 | xargs -0r rm -rf --" >> $$(FAKEROOT_SCRIPT)
> +	echo "find $$(TARGET_DIR)/tmp/ -mindepth 1 -prune -print0 | xargs -0r rm -rf --" >> $$(FAKEROOT_SCRIPT)

That could have been a single call to find:

    find $$(TARGET_DIR)/run/ $$(TARGET_DIR)/tmp/ -mindepth 1 [...]

but there not much loss calling it twice, and the lines are shorter,
which is nicer too, so I kept it as is.

Applied to master, thanks.

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

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns
  2022-03-10 10:18 [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns Mathieu Mirmont via buildroot
                   ` (3 preceding siblings ...)
  2022-03-12 16:52 ` [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns Yann E. MORIN
@ 2022-03-19 19:01 ` Peter Korsgaard
  4 siblings, 0 replies; 13+ messages in thread
From: Peter Korsgaard @ 2022-03-19 19:01 UTC (permalink / raw)
  To: Mathieu Mirmont via buildroot; +Cc: Mathieu Mirmont

>>>>> "Mathieu" == Mathieu Mirmont via buildroot <buildroot@buildroot.org> writes:

 > Different shells can have different behaviours when it comes to
 > globbing patterns. The dash shell (/bin/sh) on Debian testing switched
 > to a different fnmatch/glob implementation that results in this new
 > behaviour:

 > Using bash:
 > $ mkdir /tmp/foo
 > $ echo /tmp/foo/.[^.]*
 > /tmp/foo/.[^.]*

 > Using dash:
 > $ mkdir /tmp/foo
 > $ echo /tmp/foo/.[^.]*
 > /tmp/foo/..

 > The current FAKEROOT script uses this shell glob pattern which now
 > fails on recent Debian testing systems:

 > rm: refusing to remove '.' or '..' directory: skipping '/build/buildroot-fs/cpio/target/run/..'
 > rm: refusing to remove '.' or '..' directory: skipping '/build/buildroot-fs/cpio/target/tmp/..'

 > It seems safer to use `find | xargs rm` here instead of relying on
 > shell globbing patterns.

 > Signed-off-by: Mathieu Mirmont <mat@parad0x.org>

Committed to 2022.02.x, thanks.

-- 
Bye, Peter Korsgaard
_______________________________________________
buildroot mailing list
buildroot@buildroot.org
https://lists.buildroot.org/mailman/listinfo/buildroot

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-03-19 19:01 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-10 10:18 [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns Mathieu Mirmont via buildroot
2022-03-10 10:45 ` David Laight
2022-03-10 11:33   ` Mat via buildroot
2022-03-10 11:52     ` David Laight
2022-03-10 12:11       ` Mathieu Mirmont via buildroot
2022-03-10 13:47         ` David Laight
2022-03-10 15:42           ` Mathieu Mirmont via buildroot
2022-03-10 11:22 ` Edgar Bonet
2022-03-10 11:31   ` David Laight
2022-03-10 12:02 ` [Buildroot] [PATCH v2] fs/common.mk: fix the globing pattern Mathieu Mirmont via buildroot
2022-03-12 16:19   ` Yann E. MORIN
2022-03-12 16:52 ` [Buildroot] [PATCH 1/1] fs/common.mk: use find instead of shell glob patterns Yann E. MORIN
2022-03-19 19:01 ` Peter Korsgaard

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.