Skip to contentSkip to conversation

trap: Implement POSIX.1-2008 trap reset behaviour

PATCH New Jonathan Perkin 1 participant 1 message Dec 7, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trap: Implement POSIX.1-2008 trap reset behaviour

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(-)
src/trap.c +1 -1
index 82d4263..2d20c3f 100644
@@ -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++;
Signature · 4 lines
2.4.9 (Apple Git-60)

-- 
Jonathan Perkin  -  Joyent, Inc.  -  www.joyent.com