Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 15 Jan 2011 21:09:00 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r217461 - in head: bin/sh tools/regression/bin/sh/builtins
Message-ID:  <201101152109.p0FL9055037523@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Sat Jan 15 21:09:00 2011
New Revision: 217461
URL: http://svn.freebsd.org/changeset/base/217461

Log:
  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.

Added:
  head/tools/regression/bin/sh/builtins/trap5.0   (contents, props changed)
Modified:
  head/bin/sh/trap.c

Modified: head/bin/sh/trap.c
==============================================================================
--- head/bin/sh/trap.c	Sat Jan 15 20:37:56 2011	(r217460)
+++ head/bin/sh/trap.c	Sat Jan 15 21:09:00 2011	(r217461)
@@ -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) {

Added: head/tools/regression/bin/sh/builtins/trap5.0
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ head/tools/regression/bin/sh/builtins/trap5.0	Sat Jan 15 21:09:00 2011	(r217461)
@@ -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" ]



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201101152109.p0FL9055037523>