[comp.sys.sun] .getwd and .getwdCNNNNN

hoey@aic.nrl.navy.mil (Dan Hoey) (12/21/89)

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.  These are apparently related to /tmp/.getwd, which
``man 3 getwd'' says ``exists for the sole purpose of the getwd() library
routine; no other software should depend on its existence or contents.''
It seems like these files tend to get created when two or more users of a
machine are calling system(3) lots of times.

Is there a good way to cut down on the creation of these files?  I am
really getting tired of having to fix people's Suns when their filesystem
becomes full.  Could someone at least explain to me the purpose and use of
these files?  Under what circumstances are they created and deleted?

Dan Hoey
HOEY@AIC.NRL.NAVY.MIL

hoey@aic.nrl.navy.mil (Dan Hoey) (02/02/90)

In article <3998@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@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@AIC.NRL.NAVY.MIL