Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm
Precedence: bulk
X-No-Archive: yes
List-Id: Zsh Workers List <zsh-workers.zsh.org>
List-Post: <mailto:zsh-workers@zsh.org>
List-Help: <mailto:zsh-workers-help@zsh.org>
X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au
X-Spam-Level: 
X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=ham
	autolearn_force=no version=3.4.1
X-Biglobe-Sender: <takimoto-j@kba.biglobe.ne.jp>
Content-Type: text/plain; charset=us-ascii
Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\))
Subject: Re: [BUG] Directory glob picks up running or already-run scripts on OS X
From: "Jun T." <takimoto-j@kba.biglobe.ne.jp>
In-Reply-To: <CAH+w=7Y6GEJxa5LS4AeG5V5hsyUYJkSEEEMRnMSSJpLpRfLPXA@mail.gmail.com>
Date: Mon, 11 Jul 2016 17:51:57 +0900
Content-Transfer-Encoding: 7bit
Message-Id: <9516F748-A5C9-41D7-9739-A87B771551FD@kba.biglobe.ne.jp>
References: <CEE58D57-A237-4451-8882-0AE0CE21DD58@gmail.com> <CAH+w=7Y6GEJxa5LS4AeG5V5hsyUYJkSEEEMRnMSSJpLpRfLPXA@mail.gmail.com>
To: "zsh-workers@zsh.org" <zsh-workers@zsh.org>
X-Mailer: Apple Mail (2.1510)
X-Biglobe-Spnum: 59192
X-Seq: zsh-workers 38823


On 2016/07/11, at 5:12, Bart Schaefer <schaefer@brasslantern.com> wrote:
> I'm not able to reproduce this. 
(snip)
> macadamia% ~-/Src/zsh -f script1
> macadamia% print -l */
> zsh: no matches found: */

Please try running 'script1' and 'print -l */' in the same shell.
For example:
% zsh -f -c './script1; print -l */'

On 2016/07/11, at 13:58, Bart Schaefer <schaefer@brasslantern.com> wrote:
> The problem seems to be that scanner() calls recursively one extra
> time when looking at "notadirectory/".

> In that case statfullpath("") is called and, for reasons I haven't
> figured out, that returns success on MacOS when called in exactly
> the circumstances that Zhiming describes.

Near the end of statfullpath() (line 301 of glob.c), the access(2) system
call is used to check whether the path is actually a directory:
	access(buf, F_OK)
where buf is set to 'script1/.'; but it seems access(2) behaves quite
strangely on OS X.
On OS X 10.8.5 (Mountain Lion, a rather old version) I get the following
(note that no zsh is involved here):

bash$ cat atest.c
#include <unistd.h>
#include <stdio.h>
int main(int argc, char* argv[]) {
    if(argc==2) printf("%d\n",access(argv[1], F_OK));
    return 0;
}
bash$ cc -o atest atest.c
bash$ echo '#!/bogus/command' > foo	# /bogus/command does not exist
bash$ ./atest foo/.
-1                              # as expected
bash$ ./foo
bash: ./foo: Permission denied
bash$ ./atest foo/.
-1                              # still fails
bash$ chmod u+x foo
bash$ ./foo
bash: ./foo: /bogus/command: bad interpreter: No such file or directory
bash$ ./atest foo/.
0                               # now it succeeds
bash$ 

I will test on El Capitan later, but I guess I'll get the same result
since Zhiming is having the problem on El Capitan (or even 10.12 beta).

Jun




