On Apr 27, 2010, at 10:47 PM, Caspar ZHANG wrote:
>
> ----- "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.
The first item is different from the other two. The first one ignores the
signal (SIG_IGN), whereas the latter two cases reset the handler to the default
one (SIG_DFL). I prefer the former format, because otherwise the signal
handlers become reentrable on accident.
>>
>> 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.
Thanks,
-Garrett
------------------------------------------------------------------------------
_______________________________________________
Ltp-list mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ltp-list