Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Bug/misfeature with autoloaded TRAPxxx functions



Bart Schaefer wrote:
> I worry that there's a race condition between setting sigtrapped[signum]
> and actually adding the function node.

Well, I would guess there are various possible races, many of which were
already in the TRAP function handling.

I suppose this fixes the one you are worried about.

> And what happens if the fucntion
> fails to load?  Does sigtrapped[signum] get cleared somewhere else?

No, but it's consistent with other failed functions.

% autoload spooble
% spooble
zsh: spooble: function definition file not found
% spooble
zsh: spooble: function definition file not found
% autoload TRAPZERR
% false
zsh: TRAPZERR: function definition file not found
% false
zsh: TRAPZERR: function definition file not found

With the current behaviour of retrying, clearing the trap doesn't look
like the right thing to do.

However, there seems to be a bug somewhere anyway.

% autoload TRAPZERR
% echo <TAB>
...
% false
zsh: segmentation fault (core dumped)  ./zsh

Happens whether or not the autoload was successful, interestingly.
Doesn't happen if you successfully autoload the trap before completion
(or define TRAPZERR inline).  Symptom is an empty state->prog->shf in
execautofn.

Also, $functions don't show TRAP functions.

Index: builtin.c
===================================================================
RCS file: /cvsroot/zsh/zsh/Src/builtin.c,v
retrieving revision 1.117
diff -u -r1.117 builtin.c
--- builtin.c	20 Apr 2004 12:57:35 -0000	1.117
+++ builtin.c	21 Apr 2004 17:23:27 -0000
@@ -2515,12 +2515,13 @@
 	    shf = (Shfunc) zshcalloc(sizeof *shf);
 	    shf->flags = on;
 	    shf->funcdef = mkautofn(shf);
+	    shfunctab->addnode(shfunctab, ztrdup(*argv), shf);
 
 	    if (!strncmp(*argv, "TRAP", 4) &&
 		(signum = getsignum(*argv + 4)) != -1) {
 		if (settrap(signum, shf->funcdef)) {
-		    freeeprog(shf->funcdef);
-		    zfree(shf, sizeof(*shf));
+		    shfunctab->removenode(shfunctab, *argv);
+		    shfunctab->freenode((HashNode)shf);
 		    returnval = 1;
 		    ok = 0;
 		}
@@ -2528,12 +2529,9 @@
 		    sigtrapped[signum] |= ZSIG_FUNC;
 	    }
 
-	    if (ok) {
-		shfunctab->addnode(shfunctab, ztrdup(*argv), shf);
-		if (OPT_ISSET(ops,'X') &&
-		    eval_autoload(shf, shf->nam, ops, func))
-		    returnval = 1;
-	    }
+	    if (ok && OPT_ISSET(ops,'X') &&
+		eval_autoload(shf, shf->nam, ops, func))
+		returnval = 1;
 	} else
 	    returnval = 1;
     }
-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR Ltd., Science Park, Milton Road,
Cambridge, CB4 0WH, UK                          Tel: +44 (0)1223 692070


**********************************************************************
This email and any files transmitted with it are confidential and
intended solely for the use of the individual or entity to whom they
are addressed. If you have received this email in error please notify
the system manager.

This footnote also confirms that this email message has been swept by
MIMEsweeper for the presence of computer viruses.

www.mimesweeper.com
**********************************************************************



Messages sorted by: Reverse Date, Date, Thread, Author