----- "Garrett Cooper" <[email protected]> wrote:
> 
> Almost there :). Some comments:
> 
> +     trap 'trap EXIT; teardown' EXIT
> 
> Should be:
> 
> +     trap 'trap "" EXIT; teardown' EXIT

Thanks for the tip :-) If I understood correctly, the EXIT 
signal is triggered when the program terminates(like after an
`exit' command). I find that resetting the signal to original
disposition and ignoring the signal have the same effect since
the program is always ready to terminate after finishing the
handler execution. Thus I think using `trap EXIT', `trap - EXIT'
and `trap "" EXIT' all work.

Cheers,
Caspar

> 
> The double quotes tell the shell to ignore all future signals trapped
> for the EXIT event (from bash(1)'s trap section, but the same also
> applies for ash(1), which is the predecessor to dash ):
> 
> ...
> 
>                                                                       If arg 
> is absent (and  there  is  a
>               single  sigspec)  or  -,  each  specified signal is
> reset to its
>               original disposition (the value it  had  upon  entrance 
> to  the
>               shell).   If arg is the null string the signal specified
> by each
>               sigspec is ignored by the shell and by the commands it 
> invokes.
> 
> ...
> 
> The `set' sed could be like this:
> 
>       pattern="[[:space:]]*Defaults[[:space:]]*requiretty.*"
>       sed -E -i "" -e "s/^($pattern)/#\1/" /etc/sudoers
> 
> The restore sed could be like this:
> 
>       sed -E -i "" -e "s/^#($pattern)/\1/" /etc/sudoers
>       # with $pattern being set like before.
> 
> Don't forget the ^ anchors and the quoting's important :).
> 
> >> 
> >>    You may want to execute the handler before the setup call is
> invoked
> >> to ensure that everything done is properly undone in the event of
> a
> >> failure during setup.
> >>    Also, watch out for cases where a user may have done:
> >> 
> >> # requiretty
> >> 
> >> instead of:
> >> 
> >> requiretty
> >> 
> >>    It probably would be wise to preserve all leading and trailing
> >> characters for teardown to avoid inadvertently enabling requiretty
> in
> >> sudo.
> >>    The EXIT trap handler isn't 100% foolproof, but it protects
> against
> >> all but SIGKILL or SIGSTOP from being executed as they're NMIs.
> 
> Cheers,
> -Garrett

-- 
Kernel Associate Quality Engineer
Red Hat Inc. (Beijing R&D Branch)

Red Hat China R&D Branch Unit 907, North Tower C, 
  Raycom Infotech Park, No.2 Kexueyuan Nanlu, 
  Haidian District, Beijing 100190

TEL: +86-10-62608150
Web: http://www.redhat.com/

------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to