aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@FreeBSD.org>2011-01-15 21:09:00 +0000
committerJilles Tjoelker <jilles@FreeBSD.org>2011-01-15 21:09:00 +0000
commita043cc4c68b0e8b0ed716275ac3df27621d1b3f0 (patch)
tree86ec116a5ba2f93c9f0fca869422376bb05458fa
parent951f1334b64f9b2f90b785a8d01c96c5893bcb3d (diff)
downloadsrc-a043cc4c68b0e8b0ed716275ac3df27621d1b3f0.tar.gz
src-a043cc4c68b0e8b0ed716275ac3df27621d1b3f0.zip
sh: Fix some things about -- in trap:
* Make 'trap --' do the same as 'trap' instead of nothing. * Make '--' stop option processing (note that '-' action is not an option). Side effect: The error message for an unknown option is different.
Notes
Notes: svn path=/head/; revision=217461
-rw-r--r--bin/sh/trap.c25
-rw-r--r--tools/regression/bin/sh/builtins/trap5.019
2 files changed, 33 insertions, 11 deletions
diff --git a/bin/sh/trap.c b/bin/sh/trap.c
index 2b3a4d358e08..d2e53086b102 100644
--- a/bin/sh/trap.c
+++ b/bin/sh/trap.c
@@ -153,8 +153,18 @@ trapcmd(int argc, char **argv)
char *action;
int signo;
int errors = 0;
+ int i;
+
+ while ((i = nextopt("l")) != '\0') {
+ switch (i) {
+ case 'l':
+ printsignals();
+ return (0);
+ }
+ }
+ argv = argptr;
- if (argc <= 1) {
+ if (*argv == NULL) {
for (signo = 0 ; signo < sys_nsig ; signo++) {
if (signo < NSIG && trap[signo] != NULL) {
out1str("trap -- ");
@@ -171,19 +181,12 @@ trapcmd(int argc, char **argv)
return 0;
}
action = NULL;
- if (*++argv && strcmp(*argv, "--") == 0)
- argv++;
if (*argv && sigstring_to_signum(*argv) == -1) {
- if ((*argv)[0] != '-') {
- action = *argv;
+ if (strcmp(*argv, "-") == 0)
argv++;
- } else if ((*argv)[1] == '\0') {
+ else {
+ action = *argv;
argv++;
- } else if ((*argv)[1] == 'l' && (*argv)[2] == '\0') {
- printsignals();
- return 0;
- } else {
- error("bad option %s", *argv);
}
}
while (*argv) {
diff --git a/tools/regression/bin/sh/builtins/trap5.0 b/tools/regression/bin/sh/builtins/trap5.0
new file mode 100644
index 000000000000..56e0fb1b89fe
--- /dev/null
+++ b/tools/regression/bin/sh/builtins/trap5.0
@@ -0,0 +1,19 @@
+# $FreeBSD$
+
+set -e
+trap - USR1
+initial=$(trap)
+trap -- -l USR1
+added=$(trap)
+[ -n "$added" ]
+trap - USR1
+second=$(trap)
+[ "$initial" = "$second" ]
+eval "$added"
+added2=$(trap)
+added3=$(trap --)
+[ "$added" = "$added2" ]
+[ "$added2" = "$added3" ]
+trap -- - USR1
+third=$(trap)
+[ "$initial" = "$third" ]