diff mbox

posix: Add SIGSEGV on the trap list for globtest.sh

Message ID 1491934157-30940-1-git-send-email-adhemerval.zanella@linaro.org
State New
Headers show

Commit Message

Adhemerval Zanella April 11, 2017, 6:09 p.m. UTC
This patch prevents lingering files for SIGSEGV failutes.  Checked
on x86_64.

	* posix/globtest.sh: Add SIGSEGV for the signal to act on a trap.
---
 ChangeLog         | 4 ++++
 posix/globtest.sh | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

-- 
2.7.4

Comments

Florian Weimer April 11, 2017, 6:22 p.m. UTC | #1
On 04/11/2017 08:09 PM, Adhemerval Zanella wrote:
> -trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15

> +trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' HUP INT QUIT SEGV TERM


Does the shell really receive the signal?  Why not use “0”?

Thanks,
Florian
Adhemerval Zanella April 11, 2017, 7:59 p.m. UTC | #2
On 11/04/2017 15:22, Florian Weimer wrote:
> On 04/11/2017 08:09 PM, Adhemerval Zanella wrote:

>> -trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15

>> +trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' HUP INT QUIT SEGV TERM

> 

> Does the shell really receive the signal?  Why not use “0”?


It does not off course since it is not the shell that is actually generating
the segfault. I will rewrite the patch.

> 

> Thanks,

> Florian
Florian Weimer April 11, 2017, 9:12 p.m. UTC | #3
On 04/11/2017 09:59 PM, Adhemerval Zanella wrote:
>

>

> On 11/04/2017 15:22, Florian Weimer wrote:

>> On 04/11/2017 08:09 PM, Adhemerval Zanella wrote:

>>> -trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15

>>> +trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' HUP INT QUIT SEGV TERM

>>

>> Does the shell really receive the signal?  Why not use “0”?

>

> It does not off course since it is not the shell that is actually generating

> the segfault.


Well, the shell uses globbing, too, so who knows. :)

> I will rewrite the patch.


Thanks.  Using 0 is probably the correct choice, then.

Florian
Adhemerval Zanella April 12, 2017, 12:35 p.m. UTC | #4
On 11/04/2017 18:12, Florian Weimer wrote:
> On 04/11/2017 09:59 PM, Adhemerval Zanella wrote:

>>

>>

>> On 11/04/2017 15:22, Florian Weimer wrote:

>>> On 04/11/2017 08:09 PM, Adhemerval Zanella wrote:

>>>> -trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15

>>>> +trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' HUP INT QUIT SEGV TERM

>>>

>>> Does the shell really receive the signal?  Why not use “0”?

>>

>> It does not off course since it is not the shell that is actually generating

>> the segfault.

> 

> Well, the shell uses globbing, too, so who knows. :)

> 

>> I will rewrite the patch.

> 

> Thanks.  Using 0 is probably the correct choice, then.

> 

> Florian


Ok, here is a version 2.

--

This patch prevents lingering files for SIGSEGV failures by adding
a cleanup handler on trap handler.  Checked on x86_64-linux-gnu.

	* posix/globtest.sh: Add cleanup for the signal to act on a trap.

---
 ChangeLog         |  4 ++++
 posix/globtest.sh | 10 +++++++---
 2 files changed, 11 insertions(+), 3 deletions(-)

index f9cc80b..a764aef 100755--- a/posix/globtest.sh
+++ b/posix/globtest.sh
@@ -47,7 +47,13 @@ testout=${common_objpfx}posix/globtest-out
 rm -rf $testdir $testout
 mkdir $testdir
 
-trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15
+cleanup()
+{
+  chmod 777 $testdir/noread
+  rm -fr $testdir $testout
+}
+
+trap cleanup 0 HUP INT QUIT TERM
 
 echo 1 > $testdir/file1
 echo 2 > $testdir/file2
@@ -811,8 +817,6 @@ if test $failed -ne 0; then
 fi
 
 if test $result -eq 0; then
-    chmod 777 $testdir/noread
-    rm -fr $testdir $testout
     echo "All OK." > $logfile
 fi


Florian Weimer April 12, 2017, 1:19 p.m. UTC | #5
On 04/12/2017 02:35 PM, Adhemerval Zanella wrote:
> Ok, here is a version 2.

> 

> --

> 

> This patch prevents lingering files for SIGSEGV failures by adding

> a cleanup handler on trap handler.  Checked on x86_64-linux-gnu.

> 

> 	* posix/globtest.sh: Add cleanup for the signal to act on a trap.


Looks reasonable.

> +cleanup()


Not sure what the preferred style is here, “cleanup () {” or yours.

GNU style for shell scripts seems to be 4 space indentation.

Thanks,
Florian
Adhemerval Zanella April 12, 2017, 1:49 p.m. UTC | #6
On 12/04/2017 10:19, Florian Weimer wrote:
> On 04/12/2017 02:35 PM, Adhemerval Zanella wrote:

>> Ok, here is a version 2.

>>

>> -- 

>>

>> This patch prevents lingering files for SIGSEGV failures by adding

>> a cleanup handler on trap handler.  Checked on x86_64-linux-gnu.

>>

>>     * posix/globtest.sh: Add cleanup for the signal to act on a trap.

> 

> Looks reasonable.

> 

>> +cleanup()

> 

> Not sure what the preferred style is here, “cleanup () {” or yours.

> 

> GNU style for shell scripts seems to be 4 space indentation.

> 

> Thanks,

> Florian


GLIBC usage seems to tend for 'function () {', although there both usage
across the scripts.  I will change it and use 4 space indentation.
Florian Weimer April 12, 2017, 2:09 p.m. UTC | #7
On 04/12/2017 03:19 PM, Florian Weimer wrote:

> GNU style for shell scripts seems to be 4 space indentation.


I may have been wrong about that.  It is what Emacs uses, but GNU is 
inconsistent.  Two spaces are common as well.

Thanks,
Florian
diff mbox

Patch

diff --git a/posix/globtest.sh b/posix/globtest.sh
index f9cc80b..cb7d748 100755
--- a/posix/globtest.sh
+++ b/posix/globtest.sh
@@ -47,7 +47,7 @@  testout=${common_objpfx}posix/globtest-out
 rm -rf $testdir $testout
 mkdir $testdir
 
-trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' 1 2 3 15
+trap 'chmod 777 $testdir/noread; rm -fr $testdir $testout' HUP INT QUIT SEGV TERM
 
 echo 1 > $testdir/file1
 echo 2 > $testdir/file2