WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: [PATCH] adding trap ERR to ash  (Read 2978 times)

Offline Roberto A. Foglietta

  • Full Member
  • ***
  • Posts: 212
    • personal home page
[PATCH] adding trap ERR to ash
« on: August 13, 2021, 06:14:21 AM »
Hi all,

 this patch add the trap ERR to busybox ash. I tested it against various cases.
 
Code: [Select]
roberto@vm-ubuntu18:~/tinycore-editor/busybox/src$ ./busybox ash -x
ash: using fallback suid method

~/tinycore-editor/busybox/src $ trap "echo myerror; false" ERR; trap; false
+ trap 'echo myerror; false' ERR
+ trap
trap -- 'echo myerror; false' ERR
+ false
+ echo myerror
myerror
+ false

~/tinycore-editor/busybox/src $ trap -- ERR; false
+ trap -- ERR
+ false

~/tinycore-editor/busybox/src $ trap "echo myexit; false" EXIT; trap "echo myerror; false" ERR; exit 1
+ trap 'echo myexit; false' EXIT
+ trap 'echo myerror; false' ERR
+ exit 1
+ echo myexit
myexit
+ false
+ echo myerror
myerror
+ false

Offline Roberto A. Foglietta

  • Full Member
  • ***
  • Posts: 212
    • personal home page
Re: [PATCH] adding trap ERR to ash
« Reply #1 on: August 13, 2021, 11:22:53 AM »
This second patch goes after the first one:

 - add a bugfix to the first patch
 - enable global $LINENO

At the moment when $LINENO is printed by a function the number displayed is the lines from the start of the function.
Unfortunately, this information is useless because we do not have $FUNCNAME.
Even if we have $FUNCNAME having always an absolute $LINENO will be more easier.
In fact this will be the quickest way to reach the break point

- vi script.sh :$n

The two patches goes together because having the $LINENO without the ability to use in an error trap is not very useful.

I will add in attachment a script for testing in the next post.

Please let me know what you think,
-R

Offline Roberto A. Foglietta

  • Full Member
  • ***
  • Posts: 212
    • personal home page
Re: [PATCH] adding trap ERR to ash
« Reply #2 on: August 13, 2021, 11:23:42 AM »
I will add in attachment a script for testing in the next post.

Offline Roberto A. Foglietta

  • Full Member
  • ***
  • Posts: 212
    • personal home page
Re: [PATCH] adding trap ERR to ash
« Reply #3 on: August 14, 2021, 01:24:40 AM »
This third patch add the support for set -E (error trace)

Please, rename the others 1of3 and 2of3. Thank you

In attachment the scripts for testing, in a tarball.

Offline Roberto A. Foglietta

  • Full Member
  • ***
  • Posts: 212
    • personal home page
Re: [PATCH] adding trap ERR to ash
« Reply #4 on: August 14, 2021, 03:03:51 AM »
This 4th patch add the support for $FUNCNAME

Please, rename the others Nof4. Thank you

In attachment the scripts for testing, in a tarball.

Offline Roberto A. Foglietta

  • Full Member
  • ***
  • Posts: 212
    • personal home page
Re: [PATCH] adding trap ERR to ash
« Reply #5 on: August 14, 2021, 07:44:19 AM »
This 5th patch fixes a corner-case LINENO bug

Please, rename the others Nof5. Thank you

In attachment the scripts for testing, in a tarball.

Offline Roberto A. Foglietta

  • Full Member
  • ***
  • Posts: 212
    • personal home page
Re: [PATCH] adding trap ERR to ash
« Reply #6 on: August 14, 2021, 09:24:41 AM »
This 6th patch fixes FUNCNAME when no function is defined

Please, rename the others Nof6. Thank you

In attachment the scripts for testing, in a tarball.

Offline Roberto A. Foglietta

  • Full Member
  • ***
  • Posts: 212
    • personal home page
Re: [PATCH] adding trap ERR to ash
« Reply #7 on: August 16, 2021, 07:44:18 AM »
This 7th patch fixes three main issues

Please, rename the others Nof7. Thank you

In attachment the scripts for testing, in a tarball.

Offline Roberto A. Foglietta

  • Full Member
  • ***
  • Posts: 212
    • personal home page
Re: [PATCH] adding trap ERR to ash
« Reply #8 on: August 20, 2021, 05:50:54 AM »
This 8th patch cover another case of string evaluation

Please, rename the others Nof8. Thank you

In attachment the scripts for testing, in a tarball.

Offline Roberto A. Foglietta

  • Full Member
  • ***
  • Posts: 212
    • personal home page
Re: [PATCH] adding trap ERR to ash
« Reply #9 on: August 20, 2021, 11:59:12 AM »
This 9th patch fixes some corner case related to command line execution

Please, rename the others Nof9. Thank you

Offline Roberto A. Foglietta

  • Full Member
  • ***
  • Posts: 212
    • personal home page
Re: [PATCH] adding trap ERR to ash
« Reply #10 on: August 21, 2021, 07:52:12 AM »
This 10th patch is very important: rework the trap ERR because the previous was misimplemented.

Now the behaviour of trap ERR in busybox ash is compliant with the one shown by bash.

Updated test suite attached also. Please rename 0N of 10, thank you.

Offline Roberto A. Foglietta

  • Full Member
  • ***
  • Posts: 212
    • personal home page
Re: [PATCH] adding trap ERR to ash
« Reply #11 on: August 29, 2021, 11:59:25 PM »
The patchset has been united in a single patch with its testsuite.
This patch add to busybox ash the following features:

 - trap ERR and set -E added
 - global FUNCNAME added
 - LINENO became global

 Future improvement could be downloaded from here

 https://github.com/robang74/tinycore-editor/tree/main/busybox

 Enjoy it, -R