Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tweak the syntax for clearing the DEBUG trap #106

Merged
merged 1 commit into from
Mar 14, 2020
Merged

Tweak the syntax for clearing the DEBUG trap #106

merged 1 commit into from
Mar 14, 2020

Conversation

dimo414
Copy link
Collaborator

@dimo414 dimo414 commented Mar 11, 2020

In a --posix shell (e.g. a shell invoked as sh instead of bash) the ARG parameter is not optional:

  1. The trap builtin doesn’t check the first argument for a possible signal specification and revert the signal handling to the original disposition if it is, unless that argument consists solely of digits and is a valid signal number. If users want to reset the handler for a given signal to the original disposition, they should use ‘-’ as the first argument.

It may not be the intent of bash-preexec to actively support POSIX mode, but the failure behavior here is pretty bad:

$ bash --noprofile --norc --posix || echo BASH CRASHED
bash-5.0$ source bash_preexec.sh
trap: usage: trap [-lp] [[arg] signal_spec ...]
BASH CRASHED

So this small tweak seems worthwhile, even if POSIX mode ends up being incompatible for other reasons.

CC @lguelorget

In a [`--posix` shell](https://www.gnu.org/software/bash/manual/html_node/Bash-POSIX-Mode.html) (e.g. a shell invoked as `sh` instead of `bash`) the ARG parameter is not optional:

> 41. The trap builtin doesn’t check the first argument for a possible signal specification and revert the signal handling to the original disposition if it is, unless that argument consists solely of digits and is a valid signal number. If users want to reset the handler for a given signal to the original disposition, they should use ‘-’ as the first argument.

It may not be the intent of bash-preexec to actively _support_ POSIX mode, but the failure behavior here is pretty bad:

```
$ bash --noprofile --norc --posix || echo BASH CRASHED
bash-5.0$ source bash_preexec.sh
trap: usage: trap [-lp] [[arg] signal_spec ...]
BASH CRASHED
```

So this small tweak seems worthwhile, even if POSIX mode ends up being problematic for other reasons.
@rcaloras rcaloras merged commit e36de17 into rcaloras:master Mar 14, 2020
@rcaloras
Copy link
Owner

Thanks for your contributions @dimo414 👍 🍔 🍟

akinomyoga added a commit to akinomyoga/bash-preexec that referenced this pull request Feb 3, 2024
This is an oversight of chaning `trap DEBUG` to `trap - DEBUG` in

rcaloras#106

The oversight did not cause a test error because the test always
succeeds.  The problem is that even if __bp_install is broken and
fails to remove `trap - DEBUG`, the current test case failed to detect
the failure and produce a false positive.  This patch fixes it.
akinomyoga added a commit to akinomyoga/bash-preexec that referenced this pull request Feb 3, 2024
This is an oversight of chaning `trap DEBUG` to `trap - DEBUG` in

rcaloras#106

The oversight did not cause a test error because the test always
succeeds.  The problem is that even if __bp_install is broken and
fails to remove `trap - DEBUG`, the current test case failed to detect
the failure and produce a false negative.  This patch fixes it.
akinomyoga added a commit to akinomyoga/bash-preexec that referenced this pull request Feb 3, 2024
This is an oversight of changing `trap DEBUG` to `trap - DEBUG` in

rcaloras#106

The oversight did not cause a test error because the test always
succeeds.  The problem is that even if __bp_install is broken and
fails to remove `trap - DEBUG`, the current test case failed to detect
the failure and produce a false negative.  This patch fixes it.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants