[pacman-dev,09/10] makepkg: Clear ERR trap before trying to restore it

Message ID e59f460d62993dc13b9ed03443e6f474b7085c24.1527783895.git.jan.steffens@gmail.com
State Accepted, archived
Headers show
Series [pacman-dev,01/10] libmakepkg/util/option: Refactor checking to reduce code duplication | expand

Commit Message

Jan Alexander Steffens May 31, 2018, 4:24 p.m. UTC
$restoretrap is empty if the trap was not set. This caused the trap
handler to remain and override later exit codes.
---
 scripts/makepkg.sh.in | 1 +
 1 file changed, 1 insertion(+)

Comments

Allan McRae June 4, 2018, 7:59 a.m. UTC | #1
On 01/06/18 02:24, Jan Alexander Steffens (heftig) wrote:
> $restoretrap is empty if the trap was not set. This caused the trap
> handler to remain and override later exit codes.

How is this ever unset? We set the error trap early in makepkg:

trap 'trap_exit USR1 "$(gettext "An unknown error has occurred.
Exiting...")"' ERR


> ---
>  scripts/makepkg.sh.in | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
> index ed0ceaec..3a3f4c30 100644
> --- a/scripts/makepkg.sh.in
> +++ b/scripts/makepkg.sh.in
> @@ -432,6 +432,7 @@ run_function_safe() {
>  
>  	run_function "$1"
>  
> +	trap - ERR
>  	eval "$restoretrap"
>  	eval "$restoreset"
>  	eval "$restoreshopt"
>
Jan Alexander Steffens June 4, 2018, 8:47 a.m. UTC | #2
The ERR trap is not inherited by functions unless the "errtrace" option is
set. So in the current situation, makepkg's internal functions are supposed
to do manual error checking. Bad returns from function calls at the top
level will trigger the trap, though.

On Mon, Jun 4, 2018 at 9:59 AM Allan McRae <allan@archlinux.org> wrote:

> On 01/06/18 02:24, Jan Alexander Steffens (heftig) wrote:
> > $restoretrap is empty if the trap was not set. This caused the trap
> > handler to remain and override later exit codes.
>
> How is this ever unset? We set the error trap early in makepkg:
>
> trap 'trap_exit USR1 "$(gettext "An unknown error has occurred.
> Exiting...")"' ERR
>
>
> > ---
> >  scripts/makepkg.sh.in | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
> > index ed0ceaec..3a3f4c30 100644
> > --- a/scripts/makepkg.sh.in
> > +++ b/scripts/makepkg.sh.in
> > @@ -432,6 +432,7 @@ run_function_safe() {
> >
> >       run_function "$1"
> >
> > +     trap - ERR
> >       eval "$restoretrap"
> >       eval "$restoreset"
> >       eval "$restoreshopt"
> >
>
Allan McRae June 4, 2018, 11:05 a.m. UTC | #3
On 04/06/18 18:47, Jan Alexander Steffens wrote:
> The ERR trap is not inherited by functions unless the "errtrace" option
> is set. So in the current situation, makepkg's internal functions are
> supposed to do manual error checking. Bad returns from function calls at
> the top level will trigger the trap, though.
> 

Is there any point to the restoretrap variable then?

A

> On Mon, Jun 4, 2018 at 9:59 AM Allan McRae <allan@archlinux.org
> <mailto:allan@archlinux.org>> wrote:
> 
>     On 01/06/18 02:24, Jan Alexander Steffens (heftig) wrote:
>     > $restoretrap is empty if the trap was not set. This caused the trap
>     > handler to remain and override later exit codes.
> 
>     How is this ever unset? We set the error trap early in makepkg:
> 
>     trap 'trap_exit USR1 "$(gettext "An unknown error has occurred.
>     Exiting...")"' ERR
> 
> 
>     > ---
>     >  scripts/makepkg.sh.in <http://makepkg.sh.in> | 1 +
>     >  1 file changed, 1 insertion(+)
>     >
>     > diff --git a/scripts/makepkg.sh.in <http://makepkg.sh.in>
>     b/scripts/makepkg.sh.in <http://makepkg.sh.in>
>     > index ed0ceaec..3a3f4c30 100644
>     > --- a/scripts/makepkg.sh.in <http://makepkg.sh.in>
>     > +++ b/scripts/makepkg.sh.in <http://makepkg.sh.in>
>     > @@ -432,6 +432,7 @@ run_function_safe() {
>     > 
>     >       run_function "$1"
>     > 
>     > +     trap - ERR
>     >       eval "$restoretrap"
>     >       eval "$restoreset"
>     >       eval "$restoreshopt"
>     >
>
Jan Alexander Steffens June 4, 2018, 11:15 a.m. UTC | #4
On Mon, Jun 4, 2018 at 1:05 PM Allan McRae <allan@archlinux.org> wrote:

> On 04/06/18 18:47, Jan Alexander Steffens wrote:
> > The ERR trap is not inherited by functions unless the "errtrace" option
> > is set. So in the current situation, makepkg's internal functions are
> > supposed to do manual error checking. Bad returns from function calls at
> > the top level will trigger the trap, though.
> >
>
> Is there any point to the restoretrap variable then?


Probably not. I don't think we nest run_function_safe calls. Then again, it
doesn't hurt, either.

Patch

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index ed0ceaec..3a3f4c30 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -432,6 +432,7 @@  run_function_safe() {
 
 	run_function "$1"
 
+	trap - ERR
 	eval "$restoretrap"
 	eval "$restoreset"
 	eval "$restoreshopt"