.getwd and .getwdCNNNNN (summ

Dan Hoey hoey at aic.nrl.navy.mil
Fri Feb 2 09:12:51 AEST 1990


In article <3998 at brazos.Rice.edu> I wrote:

>X-Sun-Spots-Digest: Volume 8, Issue 228, message 10 of 18
>We at last have a way to prevent users from stepping on each other's
>temporary files in 4.3BSD (and therefore SunOS 4.0.3).  I do a ``chmod +t
>/tmp'' so that /tmp/* can only be deleted by owner or superuser.
>
>But we have been seeing problems with /tmp filling up with thousands of
>files named .getwdCNNNNN, where C is a letter, either ``a'' or ``b'', and
>NNNNN is a process ID.

Several people explained that whenever /etc/mtab is newer than
/tmp/.getwd, the getwd routine will create /tmp/.getwdCNNNNN and attempt
to rename it to /tmp/.getwd.  The rename fails when .getwd exists and is
owned by another user.

The bug is known (1011843) and is supposed to be fixed in 4.1.  Until
then, the general solution is to chmod -t /tmp.  If you really have to
have the t-bit set, a fairly ingenious solution came from Rob McMahon
<cudcv%cu.warwick.ac.uk at NSFnet-Relay.AC.UK>:

> The cure is to put a `pwd' command in /etc/rc.local after
> mounting all the NFS filesystems, to remember to use pwd as root after
> mounting or unmounting any filesystems, and to put a `pwd' in root's crontab
> for good measure.

The rationale is that we force /tmp/.getwd to be newer than /etc/mtab.
The reason for doing this as root is that root is always able to rename
.getwdCNNNNN to .getwd, so once root calls getwd, .getwd will be owned by
root and so root will be the only account able to change it.

I should note that Rob's solution will work only marginally if you run the
automounter, because the automounter will mount and unmount filesystems
without giving you a chance to use pwd.  If you have source, I guess you
can get the automounter to call getwd.  Of course, if root's crontab runs
getwd often enough, only a few .getwdCNNNNN files can get created, and you
can delete them with another crontab entry.

Thanks to Guy Harris, Rob McMahon, Ken Smith, and Steve Rumsby for
explaining the operation of .getwd and the status of the bug.

Dan
Hoey at AIC.NRL.NAVY.MIL



More information about the Comp.sys.sun mailing list