bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: I didn't tell them to look in the current directory


From: Paul Jarc
Subject: Re: I didn't tell them to look in the current directory
Date: Mon, 29 Apr 2002 11:05:41 -0400
User-agent: Gnus/5.090006 (Oort Gnus v0.06) Emacs/21.2 (i686-pc-linux-gnu)

Hans-Bernhard Broeker <address@hidden> wrote:
> Dan Jacobson <address@hidden> wrote:
>> $ cd xxxx
>> $ chmod 0 .
>> $ find ~/oriented/queue/
>> find: cannot open current directory: Permission denied
>
>> Hurmf, why is it trying to open the current directory?
>
> Because find works by chdir()ing into all the directories it visits.
> To make sure it can return you to the original working directory, it
> opens it and keeps that handle open all the time. That way, it can
> fchdir() to it at the end of its job, and also in case of abnormal
> early termination.

There's no need to fchdir at the end, regardless of success or
failure.  There *is* a need to fchdir in the case of multiple
directory arguments specified by relative paths.  (They might be
symlinks, so ".." wouldn't necessarily take us back to the right
place.)  But if there is only one directory argument, or if all
directory arguments are absolute paths, then the descriptor for the
original directory isn't needed.  I'm not sure if it's worth the extra
effort of not opening it for this fairly special case, though.

> This serves as a measure against somebody killing that directory while
> find is working

No, it doesn't.
$ mkdir foo
$ cd foo
$ exec 7< .
$ rmdir ../foo
$ pwd
/home/prj/foo
$ (exec pwd)
pwd: cannot get current directory: No such file or directory


paul



reply via email to

[Prev in Thread] Current Thread [Next in Thread]