Re: trap commands in auxiliary scripts

Jacob Bachmeyer <[email protected]> Fri, 29 May 2026 19:58:47 -0500
Newsgroups gmane.comp.sysutils.automake.general
Message-ID <[email protected]>
On 5/29/26 17:29, Bruno Haible via Discussion list for automake wrote:
> 'trap' commands in shell scripts present a dilemma:
>
>    - If we use double-quotes to delimit the command
>        trap "rmdir '$lockdir'; exit 1" 1 2 15
>      we get undefined behaviour if $lockdir contains a single-quote,
>      and also some backslashes might be needed here and there, for
>      quoting.

Can we simply ensure that $lockdir will never contain a single-quote?

> [...]
>
> Here's a proposed patch.

I agree with Jan Engelhardt that evaluating $lockdir when the trap is 
set is preferable to evaluating it when the trap is hit, but this means 
that there is no way around expanding $lockdir in the argument to trap.

I posit that a better solution would be to add a test that our 
assumptions hold to configure and bail out early on in a weird 
environment that would do things like putting a single quote into 
$lockdir. Maybe packages using automake should refuse to build in 
directories with absolute full names containing quote marks?

Something like:  (in the generated configure)

    case `pwd` in
       *[\'\"]*)
         echo "ERROR: cannot build reliably in a location named with quote marks"
         exit 1
         ;;
    esac

A similar check for the source tree location could also be appropriate.


-- Jacob