Re: shell script error management in busybox ash

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 15/09/2021 21:07, Denys Vlasenko wrote:
On Wed, Sep 15, 2021 at 9:59 PM Harald van Dijk <harald@xxxxxxxxxxx> wrote:
On 15/09/2021 20:47, Denys Vlasenko wrote:
On Wed, Sep 15, 2021 at 7:48 PM Roberto A. Foglietta
<roberto.foglietta@xxxxxxxxx> wrote:
Moreover,
the code that these exceptions trigger (everywhere the setjmp()
returns true) restores some values and frees some memory but the traps
need the information before the restore, not the restored values.

Yes, _this_ is the problem we are having.

E.g. $FUNCNAME in EXIT trap needs to be current function's name.

Important to also mention that although FUNCNAME is not part of POSIX,
and there is no spec to compare to, in bash and ksh it does not behave
that way

In my testing, it does.

so you're talking about implementing FUNCNAME in a way that is
incompatible with existing shells.

Try this in bash:

   trap 'echo trap:$FUNCNAME' EXIT
   f() { exit; }
   f

I'm getting:
   trap:f

For bash, it depends on how the shell is invoked. When bash reads commands from stdin, it prints trap:f. When bash is called with that exact same script passed as -c, it prints trap:. There may be a more specific option that can control this.

$ bash --version
GNU bash, version 5.1.4(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

For ksh, as far as I can tell it always prints trap:.

$ ksh --version
  version         sh (AT&T Research) 93u+ 2012-08-01

Cheers,
Harald van Dijk



[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux