diff mbox

trap: Implement POSIX.1-2008 trap reset behaviour

Message ID 20151207131833.GC735@joyent.com (mailing list archive)
State Superseded
Delegated to: Herbert Xu
Headers show

Commit Message

Jonathan Perkin Dec. 7, 2015, 1:18 p.m. UTC
POSIX.1-2008 for trap adds the following behaviour:

    If the first operand is an unsigned decimal integer, the shell shall
    treat all operands as conditions, and shall reset each condition to
    the default value.

Whilst the standard specifies an "unsigned decimal integer", we take the
pragmatic approach of enabling this behaviour iff the first operand is a
valid signal, otherwise it is interpreted as an action.  This matches
the behaviour of most other shells in this regard.
---
 src/trap.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
diff mbox

Patch

diff --git a/src/trap.c b/src/trap.c
index 82d4263..2d20c3f 100644
--- a/src/trap.c
+++ b/src/trap.c
@@ -112,7 +112,7 @@  trapcmd(int argc, char **argv)
 		}
 		return 0;
 	}
-	if (!ap[1])
+	if ((!ap[1]) || (decode_signal(*ap, 0) >= 0))
 		action = NULL;
 	else
 		action = *ap++;