Skip to contentSkip to conversation

support/scripts/apply-patches.sh: handle tar and mkdir failures

PATCH New Sébastien Szymanski 3 participants 5 messages May 25, 2016 – Jul 5, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 support/scripts/apply-patches.sh: handle tar and mkdir failures

With several archives in a space-separated list of patches, if one archive cannot be untar (i.e because it is not readable), Buildroot keeps going instead of aborting. Fix this by checking the tar return code.
While at it, check if the unpack archive directory creation is successful.

---
 support/scripts/apply-patches.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
support/scripts/apply-patches.sh +5 -1
index 201278d..b0a8ad4 100755
@@ -132,7 +132,11 @@ function scan_patchdir {
                 unpackedarchivedir="$builddir/.patches-$(basename $i)-unpacked"
                 rm -rf "$unpackedarchivedir" 2> /dev/null
                 mkdir "$unpackedarchivedir"
-                tar -C "$unpackedarchivedir" -xaf "${path}/$i"
+                if [ $? != 0 ] ; then
+                    echo "Error: cannot create $unpackedarchivedir directory."
+                    exit 1
+                fi
+                tar -C "$unpackedarchivedir" -xaf "${path}/$i" || exit 1
                 scan_patchdir "$unpackedarchivedir"
             else
                 apply_patch "$path" "$i"
Signature · 1 line
2.3.6
#1 lore raw

PATCH 1/1 support/scripts/apply-patches.sh: handle tar and mkdir failures

Hello,

Quoted 9 lines · S?bastien Szymanski

With several archives in a space-separated list of patches, if one archive cannot be untar (i.e because it is not readable), Buildroot keeps going instead of aborting. Fix this by checking the tar return code.
While at it, check if the unpack archive directory creation is successful.

---
 support/scripts/apply-patches.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Thanks for the patch. One question though: are you actually using the capability of Buildroot to take a tarball, and apply the patches that it contains? If so, for what use case?

Thanks,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#2 lore raw

PATCH 1/1 support/scripts/apply-patches.sh: handle tar and mkdir failures

Hi,

Quoted 8 lines · Thomas Petazzoni

Hello,

Quoted 5 lines · S?bastien Szymanski

With several archives in a space-separated list of patches, if one archive cannot be untar (i.e because it is not readable), Buildroot keeps going instead of aborting. Fix this by checking the tar return code.
While at it, check if the unpack archive directory creation is successful.

Quoted 9 lines
Quoted 4 lines
---
 support/scripts/apply-patches.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

Thanks for the patch. One question though: are you actually using the capability of Buildroot to take a tarball, and apply the patches that it contains? If so, for what use case?

Yes, we use this Buildroot feature. We have an old kernel with several tarballs of patches for our i.MX28-based SoM. They was provided that way by Freescale I guess.

Regards,

Quoted 4 lines

Thanks,

Thomas

Signature · 6 lines
S?bastien Szymanski
Software Engineer
Armadeus Systems - A new vision of the embedded world
sebastien.szymanski at armadeus.com
Tel: +33 (0)9 72 29 41 44
Fax: +33 (0)9 72 28 79 26
#3 lore raw

PATCH 1/1 support/scripts/apply-patches.sh: handle tar and mkdir failures

In reply to Sébastien Szymanski

Hi S?bastien,

Le 25/05/2016 ? 14:13, S?bastien Szymanski a ?crit :

Quoted 15 lines

With several archives in a space-separated list of patches, if one archive cannot be untar (i.e because it is not readable), Buildroot keeps going instead of aborting. Fix this by checking the tar return code.
While at it, check if the unpack archive directory creation is successful.

---
 support/scripts/apply-patches.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
support/scripts/apply-patches.sh +0 -0
index 201278d..b0a8ad4 100755

support/scripts/apply-patches.sh function scan_patchdir { · line 138

Quoted 8 lines
support/scripts/apply-patches.sh +4 -1
@@ -132,7 +132,11 @@ function scan_patchdir {
                 unpackedarchivedir="$builddir/.patches-$(basename $i)-unpacked"
                 rm -rf "$unpackedarchivedir" 2> /dev/null
                 mkdir "$unpackedarchivedir"
-                tar -C "$unpackedarchivedir" -xaf "${path}/$i"
+                if [ $? != 0 ] ; then
+                    echo "Error: cannot create $unpackedarchivedir directory."
+                    exit 1
+                fi

I don't see why mkdir can fail here.

support/scripts/apply-patches.sh function scan_patchdir { · line 139

Quoted 1 line
support/scripts/apply-patches.sh +1 -0
+                tar -C "$unpackedarchivedir" -xaf "${path}/$i" || exit 1

Ok with the check.

Best regards,
Romain

Quoted 4 lines
support/scripts/apply-patches.sh +0 -0
                 scan_patchdir "$unpackedarchivedir"
             else
                 apply_patch "$path" "$i"
#4 lore raw

PATCH 1/1 support/scripts/apply-patches.sh: handle tar and mkdir failures

In reply to Sébastien Szymanski

Hi S?bastien,

Le 25/05/2016 ? 14:13, S?bastien Szymanski a ?crit :

Quoted 4 lines

With several archives in a space-separated list of patches, if one archive cannot be untar (i.e because it is not readable), Buildroot keeps going instead of aborting. Fix this by checking the tar return code.
While at it, check if the unpack archive directory creation is successful.

As discussed with other Buildroot developers, we prefer to use "set -e" in apply-patches.sh

See:
http://patchwork.ozlabs.org/patch/644705

I'll mark you patch rejected in patchwork.

Thanks!

Best regards,
Romain

Quoted 24 lines
---
 support/scripts/apply-patches.sh | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
support/scripts/apply-patches.sh +5 -1
index 201278d..b0a8ad4 100755
@@ -132,7 +132,11 @@ function scan_patchdir {
                 unpackedarchivedir="$builddir/.patches-$(basename $i)-unpacked"
                 rm -rf "$unpackedarchivedir" 2> /dev/null
                 mkdir "$unpackedarchivedir"
-                tar -C "$unpackedarchivedir" -xaf "${path}/$i"
+                if [ $? != 0 ] ; then
+                    echo "Error: cannot create $unpackedarchivedir directory."
+                    exit 1
+                fi
+                tar -C "$unpackedarchivedir" -xaf "${path}/$i" || exit 1
                 scan_patchdir "$unpackedarchivedir"
             else
                 apply_patch "$path" "$i"