Subject: Re: Use of /tmp in /etc/{daily,weekly,monthly,security}
To: None <tech-userlevel@netbsd.org>
From: Christos Zoulas <christos@astron.com>
List: tech-userlevel
Date: 06/05/2007 15:56:42
In article <Pine.NEB.4.64.0706050910580.17699@p130.piuha.net>,
Martti Kuparinen  <martti.kuparinen@iki.fi> wrote:
>Inspired by misc/35544, any objections if I commit this?
>
>Martti
>
>
>
>Index: daily
>===================================================================
>RCS file: /cvsroot/src/etc/daily,v
>retrieving revision 1.69
>diff -u -r1.69 daily
>--- daily	17 Dec 2006 23:24:09 -0000	1.69
>+++ daily	5 Jun 2007 06:09:04 -0000
>@@ -38,8 +38,8 @@
>  #
>  #echo ""
>  #echo "Removing scratch and junk files:"
>-#if [ -d /tmp -a ! -h /tmp ]; then
>-#	cd /tmp && {
>+#if [ -d ${TMPDIR:="/tmp"} -a ! -h ${TMPDIR:="/tmp"} ]; then
>+#	cd ${TMPDIR:="/tmp"} && {
>  #	find . -type f -atime +3 -exec rm -f -- {} \;
>  #	find . ! -name . -type d -mtime +1 -exec rmdir -- {} \; \
>  #	    >/dev/null 2>&1; }
>@@ -66,7 +66,7 @@
>  #	find . ! -name . -mtime +7 -exec rm -f -- {} \; ; }
>  #fi
>
>-DAILYDIR=`mktemp -d /tmp/_daily.XXXXXX` || exit 1
>+DAILYDIR=`mktemp -d ${TMPDIR:="/tmp"}/_daily.XXXXXX` || exit 1
>
>  trap "/bin/rm -rf $DAILYDIR ; exit 0" EXIT INT QUIT
>
>Index: monthly
>===================================================================
>RCS file: /cvsroot/src/etc/monthly,v
>retrieving revision 1.10
>diff -u -r1.10 monthly
>--- monthly	9 Apr 2004 17:35:21 -0000	1.10
>+++ monthly	5 Jun 2007 06:09:04 -0000
>@@ -19,7 +19,7 @@
>  echo "Subject: $host monthly output for $date"
>  echo ""
>
>-MONTHLYDIR=`mktemp -d /tmp/_monthly.XXXXXX` || exit 1
>+MONTHLYDIR=`mktemp -d ${TMPDIR:="/tmp"}/_monthly.XXXXXX` || exit 1
>
>  trap "/bin/rm -rf $MONTHLYDIR ; exit 0" EXIT INT QUIT PIPE
>
>Index: security
>===================================================================
>RCS file: /cvsroot/src/etc/security,v
>retrieving revision 1.101
>diff -u -r1.101 security
>--- security	27 Mar 2007 08:37:58 -0000	1.101
>+++ security	5 Jun 2007 06:09:05 -0000
>@@ -40,7 +40,7 @@
>  	mkdir -p "$work_dir"
>  fi
>
>-SECUREDIR=`mktemp -d /tmp/_securedir.XXXXXX` || exit 1
>+SECUREDIR=`mktemp -d ${TMPDIR:="/tmp"}/_securedir.XXXXXX` || exit 1
>
>  trap "/bin/rm -rf $SECUREDIR ; exit 0" EXIT INT QUIT PIPE
>
>Index: weekly
>===================================================================
>RCS file: /cvsroot/src/etc/weekly,v
>retrieving revision 1.22
>diff -u -r1.22 weekly
>--- weekly	15 Feb 2007 23:04:10 -0000	1.22
>+++ weekly	5 Jun 2007 06:09:05 -0000
>@@ -26,7 +26,7 @@
>  	exit 1;
>  fi
>
>-WEEKLYDIR=`mktemp -d /tmp/_weekly.XXXXXX` || exit 1
>+WEEKLYDIR=`mktemp -d ${TMPDIR:="/tmp"}/_weekly.XXXXXX` || exit 1
>
>  trap "/bin/rm -rf $WEEKLYDIR ; exit 0" EXIT INT QUIT PIPE
>
>@@ -50,7 +50,7 @@
>  #	echo ""
>  #	echo "Looking for checked out files:"
>  #
>-#	TDIR=`mktemp -d /tmp/_checkout.XXXXXX` || exit 1
>+#	TDIR=`mktemp -d ${TMPDIR:="/tmp"}/_checkout.XXXXXX` || exit 1
>  #	trap "/bin/rm -rf $TDIR ; exit 0" EXIT INT QUIT
>  #	for file in `find -f /usr/src ! -fstype local -prune -or \
>  #	    -name 'p.*' -print | egrep 'SCCS/p\.'`; do


Isn't that simpler to write as:


WEEKLYDIR=$(mktemp -d -t _weekly) || exit 1

and:

#	TDIR=$(mktemp -d -t _checkout) || exit 1

christos