Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!uakari.primate.wisc.edu!aplcen!haven!adm!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.unix.programmer Subject: Re: Why use pwd(1) for getpwd(3C)? (Re: Why use find?) Message-ID: <9838:Oct1212:02:5090@kramden.acf.nyu.edu> Date: 12 Oct 90 12:02:50 GMT References: <1990Oct10.231857.11668@virtech.uucp> <14976@hydra.gatech.EDU> <1990Oct11.140654.22117@virtech.uucp> Organization: IR Lines: 19 In article <1990Oct11.140654.22117@virtech.uucp> cpcahil@virtech.UUCP (Conor P. Cahill) writes: > The shells that have pwd built-in usually don't run getpwd()/getcwd() to > get the directory each time. They run it once at start up time and then > keep track of where they go. This causes problems if you run pwd (the > shell built-in) from a directory that you got to via a symbolic link > and it gives you the incorrect information (whereas /bin/pwd will give > you the right stuff). But the shell can read the symbolic link and figure out where it's going. It can detect race conditions as follows: lstat() to tell it's a symbolic link, readlink(), figure out the pathname of the target directory, stat() the target directory, chdir() to the symbolic link, stat(".") to make sure everything's okay, and getwd() in the exceptional situation that the link or target has moved. The real problem is that the directory could be moved, or even removed, without the shell finding out. ---Dan