All of lore.kernel.org
 help / color / mirror / Atom feed
* [Buildroot] [PATCH] purge-locales: Handle empty locale directories better
@ 2016-03-04  1:50 Trent Piepho
  2016-03-06 19:37 ` Arnout Vandecappelle
  0 siblings, 1 reply; 4+ messages in thread
From: Trent Piepho @ 2016-03-04  1:50 UTC (permalink / raw)
  To: buildroot

If a locale directory is empty, shell code like "for langdir in
$$dir/*;" will loop once with langdir set to "path/to/dir/*", rather
than not looping at all, which would obviously be the desired
behavior.

Then "grep -qx $${langdir##*/}" ungoes two shell expansions (how?)
that transform the expression from "${langdir##*/}" to "*" to "list
of all files in buildroot root dir".  Which is most certainly not what
this command was supposed to do.

If one of those files happens to be an 8GB flash image, grep consumes
all available memory and crashes trying to search it.

Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
---
 Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index f2822a2..0df5a35 100644
--- a/Makefile
+++ b/Makefile
@@ -581,7 +581,8 @@ define PURGE_LOCALES
 	do \
 		for langdir in $$dir/*; \
 		do \
-			grep -qx $${langdir##*/} $(LOCALE_WHITELIST) || rm -rf $$langdir; \
+			[ -e "$${langdir}" ] || continue; \
+			grep -qx "$${langdir##*/}" $(LOCALE_WHITELIST) || rm -rf $$langdir; \
 		done; \
 	done
 	if [ -d $(TARGET_DIR)/usr/share/X11/locale ]; \
-- 
2.7.0.25.gfc10eb5.dirty

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

* [Buildroot] [PATCH] purge-locales: Handle empty locale directories better
  2016-03-04  1:50 [Buildroot] [PATCH] purge-locales: Handle empty locale directories better Trent Piepho
@ 2016-03-06 19:37 ` Arnout Vandecappelle
  2016-03-08 21:02   ` [Buildroot] [PATCH v2] " Trent Piepho
  0 siblings, 1 reply; 4+ messages in thread
From: Arnout Vandecappelle @ 2016-03-06 19:37 UTC (permalink / raw)
  To: buildroot

On 03/04/16 02:50, Trent Piepho wrote:
> If a locale directory is empty, shell code like "for langdir in
> $$dir/*;" will loop once with langdir set to "path/to/dir/*", rather
> than not looping at all, which would obviously be the desired
> behavior.
> 
> Then "grep -qx $${langdir##*/}" ungoes two shell expansions (how?)
> that transform the expression from "${langdir##*/}" to "*" to "list
> of all files in buildroot root dir".  Which is most certainly not what
> this command was supposed to do.
> 
> If one of those files happens to be an 8GB flash image, grep consumes
> all available memory and crashes trying to search it.

 Good catch!

> 
> Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
> ---
>  Makefile | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/Makefile b/Makefile
> index f2822a2..0df5a35 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -581,7 +581,8 @@ define PURGE_LOCALES
>  	do \
>  		for langdir in $$dir/*; \
>  		do \
> -			grep -qx $${langdir##*/} $(LOCALE_WHITELIST) || rm -rf $$langdir; \
> +			[ -e "$${langdir}" ] || continue; \

 I would prefer a more explicit if, the continue is a bit more difficult to grok.

 Regards,
 Arnout

> +			grep -qx "$${langdir##*/}" $(LOCALE_WHITELIST) || rm -rf $$langdir; \
>  		done; \
>  	done
>  	if [ -d $(TARGET_DIR)/usr/share/X11/locale ]; \
> 


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

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

* [Buildroot] [PATCH v2] purge-locales: Handle empty locale directories better
  2016-03-06 19:37 ` Arnout Vandecappelle
@ 2016-03-08 21:02   ` Trent Piepho
  2016-04-28 21:48     ` Peter Korsgaard
  0 siblings, 1 reply; 4+ messages in thread
From: Trent Piepho @ 2016-03-08 21:02 UTC (permalink / raw)
  To: buildroot

If a locale directory is empty, shell code like "for langdir in
$$dir/*;" will loop once with langdir set to "path/to/dir/*", rather
than not looping at all, which would obviously be the desired
behavior.

Then "grep -qx $${langdir##*/}" ungoes two shell expansions (how?)
that transform the expression from "${langdir##*/}" to "*" to "list of
all files in buildroot root dir".  Which is most certainly not what
this command was supposed to do.

If one of those files happens to be an 8GB flash image, grep consumes
all available memory and crashes trying to search it.

Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>
---
 Makefile | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/Makefile b/Makefile
index f2822a2..44ded9d 100644
--- a/Makefile
+++ b/Makefile
@@ -581,7 +581,10 @@ define PURGE_LOCALES
 	do \
 		for langdir in $$dir/*; \
 		do \
-			grep -qx $${langdir##*/} $(LOCALE_WHITELIST) || rm -rf $$langdir; \
+			if [ -e "$${langdir}" ]; \
+			then \
+				grep -qx "$${langdir##*/}" $(LOCALE_WHITELIST) || rm -rf $$langdir; \
+			fi \
 		done; \
 	done
 	if [ -d $(TARGET_DIR)/usr/share/X11/locale ]; \
-- 
2.7.0.25.gfc10eb5.dirty

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

* [Buildroot] [PATCH v2] purge-locales: Handle empty locale directories better
  2016-03-08 21:02   ` [Buildroot] [PATCH v2] " Trent Piepho
@ 2016-04-28 21:48     ` Peter Korsgaard
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Korsgaard @ 2016-04-28 21:48 UTC (permalink / raw)
  To: buildroot

>>>>> "Trent" == Trent Piepho <tpiepho@kymetacorp.com> writes:

 > If a locale directory is empty, shell code like "for langdir in
 > $$dir/*;" will loop once with langdir set to "path/to/dir/*", rather
 > than not looping at all, which would obviously be the desired
 > behavior.

 > Then "grep -qx $${langdir##*/}" ungoes two shell expansions (how?)
 > that transform the expression from "${langdir##*/}" to "*" to "list of
 > all files in buildroot root dir".  Which is most certainly not what
 > this command was supposed to do.

 > If one of those files happens to be an 8GB flash image, grep consumes
 > all available memory and crashes trying to search it.

 > Signed-off-by: Trent Piepho <tpiepho@kymetacorp.com>

Committed, thanks.

-- 
Bye, Peter Korsgaard

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

end of thread, other threads:[~2016-04-28 21:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-03-04  1:50 [Buildroot] [PATCH] purge-locales: Handle empty locale directories better Trent Piepho
2016-03-06 19:37 ` Arnout Vandecappelle
2016-03-08 21:02   ` [Buildroot] [PATCH v2] " Trent Piepho
2016-04-28 21:48     ` 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.