From: Chris Lamb <[email protected]>

dash used to print the following output when running this test script

 $ dash -c 'trap "echo EXIT trap executed" EXIT; kill -HUP $$'
 Hangup
 $

With this commit, it properly executes the EXIT trap defined

 $ dash -c 'trap "echo EXIT trap executed" EXIT; kill -HUP $$'
 EXIT trap executed
 $

The missing trap handling was reported by Martin Dickopp through
 http://bugs.debian.org/390433

Patch is from Chris Lamb.

Signed-off-by: Gerrit Pape <[email protected]>
---
 src/trap.c |   28 +++++++++++++++++++++++-----
 1 files changed, 23 insertions(+), 5 deletions(-)

diff --git a/src/trap.c b/src/trap.c
index 58cd0cc..732fd41 100644
--- a/src/trap.c
+++ b/src/trap.c
@@ -67,6 +67,8 @@
 #define S_HARD_IGN 4           /* signal is ignored permenantly */
 #define S_RESET 5              /* temporary - to reset a hard ignored sig */
 
+#define SIGEXIT 0
+#define DUMMY_ACTION savestr(":")
 
 /* trap handler commands */
 char *trap[NSIG];
@@ -97,7 +99,7 @@ trapcmd(int argc, char **argv)
 {
        char *action;
        char **ap;
-       int signo;
+       int signo, dummysig;
 
        nextopt(nullstr);
        ap = argptr;
@@ -122,16 +124,32 @@ trapcmd(int argc, char **argv)
                        sh_error("%s: bad trap", *ap);
                INTOFF;
                if (action) {
-                       if (action[0] == '-' && action[1] == '\0')
-                               action = NULL;
-                       else
+                       if (action[0] == '-' && action[1] == '\0') {
+                               if (signo != SIGEXIT && trap[0] != NULL)
+                                       /* Reset dummy handler */
+                                       action = DUMMY_ACTION;
+                               else
+                                       action = NULL;
+                       } else {
                                action = savestr(action);
+                       }
+               } else {
+                       action = DUMMY_ACTION;
                }
                if (trap[signo])
                        ckfree(trap[signo]);
                trap[signo] = action;
-               if (signo != 0)
+               if (signo == SIGEXIT) {
+                       /* Set dummy handlers */
+                       for (dummysig = 1 ; dummysig < NSIG ; dummysig++) {
+                               if (trap[dummysig] == NULL) {
+                                       trap[dummysig] = DUMMY_ACTION;
+                                       setsignal(dummysig);
+                               }
+                       }
+               } else {
                        setsignal(signo);
+               }
                INTON;
                ap++;
        }
-- 
1.6.1.2.346.g8600b3.dirty

--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to