summaryrefslogtreecommitdiff
path: root/libexec/makewhatis
diff options
context:
space:
mode:
authorTheo de Raadt <deraadt@cvs.openbsd.org>1996-09-15 20:40:46 +0000
committerTheo de Raadt <deraadt@cvs.openbsd.org>1996-09-15 20:40:46 +0000
commit8cd83ddd9fcb3ab9645d74a5e9f89363ed3ea344 (patch)
treed68f43a4d67ed9bd99ed28945b627cd94c7bce9e /libexec/makewhatis
parent5137cf233a9a16368ab94fc4defef4846ab76738 (diff)
kill the races; found by bitblt
Diffstat (limited to 'libexec/makewhatis')
-rw-r--r--libexec/makewhatis/makewhatis.sh23
1 files changed, 17 insertions, 6 deletions
diff --git a/libexec/makewhatis/makewhatis.sh b/libexec/makewhatis/makewhatis.sh
index c592f2ce86c..2baef2f12fa 100644
--- a/libexec/makewhatis/makewhatis.sh
+++ b/libexec/makewhatis/makewhatis.sh
@@ -4,7 +4,17 @@
# Public domain.
#
-trap "rm -f /tmp/whatis$$; exit 1" 1 2 15
+TDIR=/tmp/whatis$$
+FILE=$TDIR/whatis
+
+umask 077
+if ! mkdir $TDIR ; then
+ printf "tmp directory %s already exists, looks like:\n" $TDIR
+ ls -alF $TDIR
+ exit 1
+fi
+
+trap "rm -rf $TDIR; exit 1" 1 2 15
MANDIR=${1-/usr/share/man}
if test ! -d "$MANDIR"; then
@@ -15,19 +25,20 @@ fi
find $MANDIR -type f -name '*.0' -print | while read file
do
sed -n -f /usr/share/man/makewhatis.sed $file;
-done > /tmp/whatis$$
+done > $FILE
find $MANDIR -type f -name '*.0.Z' -print | while read file
do
zcat $file | sed -n -f /usr/share/man/makewhatis.sed;
-done >> /tmp/whatis$$
+done >> $FILE
find $MANDIR -type f -name '*.0.gz' -print | while read file
do
gzip -dc $file | sed -n -f /usr/share/man/makewhatis.sed;
-done >> /tmp/whatis$$
+done >> $FILE
-sort -u -o /tmp/whatis$$ /tmp/whatis$$
+sort -u -o $FILE $FILE
-install -o bin -g bin -m 444 /tmp/whatis$$ "$MANDIR/whatis.db"
+install -o bin -g bin -m 444 $FILE "$MANDIR/whatis.db"
+rm -rf $TDIR
exit 0