bug-gnats
[Top][All Lists]
Advanced

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

GNATS tempfile patch


From: Kris Kennaway
Subject: GNATS tempfile patch
Date: Tue, 24 Apr 2001 03:08:08 -0700
User-agent: Mutt/1.2.5i

I got pissed off with the GNATS port creating all sorts of stupid
tempfiles; here's part 1 of the fix (part 2 is to fix the .c files to
use mkstemp() instead of mktemp()).  Please review.

Kris

--- gnats/gnats-edit-pr.sh.orig Tue Apr 20 14:17:07 1999
+++ gnats/gnats-edit-pr.sh      Tue Apr 24 02:42:11 2001
@@ -247,7 +247,7 @@
 -e '/^X-GNATS-Notify:/,$b' \
 $new.old`"
 
-change_msg=/tmp/ed_pr_ch$$
+change_msg=`mktemp -t ed_pr_ch` || exit 1
 
 # the following could stand to be cleaned up...
 if [ "$old_state" != "$new_state" ]; then
diff -ruN ../work/gnats-3.113/contrib/prmon ./contrib/prmon
--- ../work/gnats-3.113/contrib/prmon   Thu Nov  5 11:54:11 1998
+++ ./contrib/prmon     Tue Apr 24 02:52:09 2001
@@ -103,15 +103,10 @@
 
     hostname=$(hostname)
 
-    tmpdir="/tmp/${progname}$$"
-    while [ -e "${tmpdir}" ]; do
-       tmpdir="/tmp${progname}${RANDOM}"
-    done
+    tmpdir=`mktemp -d -t ${progname}` || exit 1
 
     TRAP_SIGNALS="EXIT SIGHUP SIGINT SIGQUIT SIGTERM"
     trap 'cleanup_and_exit' ${TRAP_SIGNALS}
-
-    mkdir ${tmpdir} || exit 1
 }
 
 function parse_command_args ()
@@ -145,7 +140,7 @@
 
              # Redirect all of stderr to a tmp file which we can mail
              # later. 
-             stderr_file="/tmp/${progname}.stderr$$"
+             stderr_file=`mktemp -t ${progname}.stderr` || exit 1
              exec 2> "${stderr_file}"
             ;;
           z-h* | z--help | z--h* )
diff -ruN ../work/gnats-3.113/gnats/check-db.sh ./gnats/check-db.sh
--- ../work/gnats-3.113/gnats/check-db.sh       Fri Feb 26 09:16:55 1999
+++ ./gnats/check-db.sh Tue Apr 24 02:54:53 2001
@@ -40,8 +40,8 @@
 MAIL_AGENT="xMAIL_AGENTx"
 
 PATH=${LIBEXECDIR}:/usr/local/bin:/bin:/usr/bin; export PATH
-TMPDIR=${TMPDIR-/tmp}
-TMPFILE=$TMPDIR/gnats-check-db-$$
+TMPFILE=`mktemp -t gnats-check-db` || exit 1
+trap "rm -f $TMPFILE; exit 1" 1 2 3 5 10 13 15
 
 # 
 # First, try to lock the database
diff -ruN ../work/gnats-3.113/gnats/delete-pr.sh ./gnats/delete-pr.sh
--- ../work/gnats-3.113/gnats/delete-pr.sh      Fri Feb 26 09:16:55 1999
+++ ./gnats/delete-pr.sh        Tue Apr 24 02:56:33 2001
@@ -68,13 +68,13 @@
 do
 
 
-
-trap 'rm -f /tmp/user$$ $INDEX.$$; exit 0' 0
+userfile=`mktemp -t user` || exit 1
+trap 'rm -f $userfile $INDEX.$$; exit 0' 0
 trap 'if [ "$locked" != "" ]; then \
         $PR_EDIT --unlock $full_id ; \
        locked= ; \
       fi ; \
-      rm -f /tmp/user$$ $INDEX.$$; exit 1' 1 2 3 13 15
+      rm -f $userfile $INDEX.$$; exit 1' 1 2 3 13 15
 
 # check $full_id
 pr=$GNATS_ROOT/$full_id    # pr = full path of editee
@@ -116,16 +116,16 @@
 # now we have a valid $full_id.. use its full path
 
 # lock the pr
-$PR_EDIT --lock $me $full_id 2> /tmp/user$$
+$PR_EDIT --lock $me $full_id 2> $userfile
 locked=t
 
-if [ -s /tmp/user$$ ]; then
-  if [ "`grep exists /tmp/user$$`" = "" ]; then
-    echo "edit-pr: PR $full_id is locked by `sed 's/.*by //g' /tmp/user$$`"
+if [ -s $userfile ]; then
+  if [ "`grep exists $userfile`" = "" ]; then
+    echo "edit-pr: PR $full_id is locked by `sed 's/.*by //g' $userfile`"
   else
     echo "edit-pr: GNATS is presently locked, try again in a moment"
   fi
-  rm -f /tmp/user$$
+  rm -f $userfile
   exit 1
 fi
 
diff -ruN ../work/gnats-3.113/gnats/gnats-edit-pr.sh ./gnats/gnats-edit-pr.sh
--- ../work/gnats-3.113/gnats/gnats-edit-pr.sh  Tue Apr 24 03:01:07 2001
+++ ./gnats/gnats-edit-pr.sh    Tue Apr 24 02:54:08 2001
@@ -174,7 +174,7 @@
 fi
 
 # new = temp file to use for editing
-new="/tmp/ep$$"
+new=`mktemp -t ep` || exit 1
 
 # lock the pr
 $debug_print "Locking $pr_id."
diff -ruN ../work/gnats-3.113/gnats/mail-query.sh ./gnats/mail-query.sh
--- ../work/gnats-3.113/gnats/mail-query.sh     Thu Nov  5 11:54:10 1998
+++ ./gnats/mail-query.sh       Tue Apr 24 02:57:49 2001
@@ -46,7 +46,8 @@
   [ "$header" = "Subject" ] && args="$contents"
 done
 
-mail=/tmp/query$$
+mail=`mktemp -t query` || exit 1
+trap "rm -f $mail; exit 1" 1 2 3 5 10 13 15
 
 exec 3>&1 4>&2 > $mail 2>&1
 
diff -ruN ../work/gnats-3.113/send-pr/install-sid.sh ./send-pr/install-sid.sh
--- ../work/gnats-3.113/send-pr/install-sid.sh  Thu Nov  5 11:54:07 1998
+++ ./send-pr/install-sid.sh    Tue Apr 24 02:58:27 2001
@@ -28,7 +28,8 @@
 BINDIR=xBINDIRx
 
 SUBMITTER=
-TEMP=/tmp/sp$$
+TEMP=`mktemp -t sp` || exit 1
+trap "rm -f $TEMP; exit 1" 1 2 3 5 10 13 15
 
 if [ $# -eq 0 ]; then
   echo "$USAGE"
diff -ruN ../work/gnats-3.113/send-pr/send-pr.sh ./send-pr/send-pr.sh
--- ../work/gnats-3.113/send-pr/send-pr.sh      Tue Apr 20 14:17:06 1999
+++ ./send-pr/send-pr.sh        Tue Apr 24 03:00:19 2001
@@ -75,17 +75,10 @@
 
 #
 
-if [ -z "$TMPDIR" ]; then
-  TMPDIR=/tmp
-else
-  if [ "`echo $TMPDIR | grep '/$'`" != "" ]; then
-    TMPDIR="`echo $TMPDIR | sed -e 's,/$,,'`"
-  fi
-fi
-
-TEMP=$TMPDIR/p$$
-BAD=$TMPDIR/pbad$$
-REF=$TMPDIR/pf$$
+TEMP=`mktemp -t p` || exit 1
+BAD=`mktemp -t pbad` || exit 1
+REF=`mktemp -t pf` || exit 1
+trap "rm -f $TEMP $BAD $REF; exit 1" 1 2 3 5 10 13 15
 
 # find a user name
 if [ "$LOGNAME" = "" ]; then

Attachment: pgpxf60jx3k9S.pgp
Description: PGP signature


reply via email to

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