zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <pws@ibmth.df.unipi.it>
To: zsh-workers@math.gatech.edu (Zsh hackers list)
Subject: PATCH: 3.1.4: autocd to directory in $PATH (2)
Date: Mon, 12 Oct 1998 14:18:37 +0200	[thread overview]
Message-ID: <9810121218.AA21544@ibmth.df.unipi.it> (raw)
In-Reply-To: ""Bart Schaefer""'s message of "Fri, 09 Oct 1998 10:16:01 DFT." <981009101601.ZM25272@candle.brasslantern.com>

"Bart Schaefer" wrote:
> I haven't actually walked through this with a debugger, but it looks to
> me as though hn = NULL at that point is going to trigger the call to
> hashcmd(cmdarg, pathchecked), which in turn is going to call iscom() a
> second time; so you end up stat()ing the directory twice.

It does call hashcmd() again, but that's right... consider what can
happen otherwise:

% ./zsh -f
% mkdir ~/foo1 ~/foo2
% path=(~/foo1 ~/foo2 $path)
% cdpath=(~/foo1 .)      
% mkdir ~/foo1/file1
% echo "#\!/bin/sh\necho This is \$0" >~/foo2/file1
% chmod +x ~/foo2/file1
% setopt autocd
% file1                         # problem here:  cd's to ~/foo1/file1
~/foo1/file1
% pwd
/home/user2/pws/foo1/file1
% which file1
/home/user2/pws/foo2/file1
% file1                         # correct this time:  call ~/foo2/file1
This is /home/user2/pws/foo2/file1


The directory does get stat'ed twice, but it's hard to avoid without
more fiddling around with special cases.  The next fix does at least
mean it's restricted to twice altogether.

> Also, what about removing the improperly hashed directory from cmdnamtab
> once you've discovered that it isn't a command?  That would (I think) get
> any real command with the same name put into the table the next time that
> name was used, so that you'll never needlessly stat() again.

I meant to do that, there were only vague historical reasons why I
didn't.  Here's another replacement patch, this time for 4404.  I've
expunged an uncessary statbuf declaration, too.

*** Src/exec.c.hc	Mon Sep 28 10:37:43 1998
--- Src/exec.c	Mon Oct 12 14:10:37 1998
***************
*** 524,529 ****
--- 524,541 ----
  
  /**/
  int
+ isreallycom(Cmdnam cn)
+ {
+     char fullnam[MAXCMDLEN];
+ 
+     strcpy(fullnam, cn->u.name ? *(cn->u.name) : "");
+     strcat(fullnam, "/");
+     strcat(fullnam, cn->nam);
+     return iscom(fullnam);
+ }
+ 
+ /**/
+ int
  isrelative(char *s)
  {
      if (*s != '/')
***************
*** 1489,1494 ****
--- 1501,1511 ----
  	    char *cmdarg = (char *) peekfirst(args);
  
  	    hn = cmdnamtab->getnode(cmdnamtab, cmdarg);
+ 	    if (hn && !isreallycom((Cmdnam)hn)) {
+ 		cmdnamtab->removenode(cmdnamtab, cmdarg);
+ 		cmdnamtab->freenode(hn);
+ 		hn = NULL;
+ 	    }
  	    if (!hn && isset(HASHCMDS) && strcmp(cmdarg, "..")) {
  		for (s = cmdarg; *s && *s != '/'; s++);
  		if (!*s)

-- 
Peter Stephenson <pws@ibmth.df.unipi.it>       Tel: +39 050 844536
WWW:  http://www.ifh.de/~pws/
Dipartimento di Fisica, Via Buonarotti 2, 56100 Pisa, Italy


  reply	other threads:[~1998-10-12 12:36 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1998-10-03 15:30 PATCH: 3.1.4: autocd to directory in $PATH Peter Stephenson
1998-10-09 17:16 ` Bart Schaefer
1998-10-12 12:18   ` Peter Stephenson [this message]
1998-10-14 19:07     ` PATCH: Re: PATCH: 3.1.4: autocd to directory in $PATH (2) Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=9810121218.AA21544@ibmth.df.unipi.it \
    --to=pws@ibmth.df.unipi.it \
    --cc=zsh-workers@math.gatech.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).