From: Wouter Verhelst Date: Fri, 27 May 2011 15:53:52 +0000 (+0200) Subject: use mktemp -d X-Git-Url: http://git.alex.org.uk use mktemp -d appending a suffix to a safely-created temporary file to do other stuff is not necessarily a good idea. Create a directory safely instead. --- diff --git a/simple_test b/simple_test index a05a6a5..44191eb 100755 --- a/simple_test +++ b/simple_test @@ -1,9 +1,10 @@ #!/bin/sh # Yes, that's POSIX sh, not bash! -tmpnam=`mktemp` -conffile=${tmpnam}.conf -pidfile=${tmpnam}.pid +tmpdir=`mktemp -d` +conffile=${tmpdir}/nbd.conf +pidfile=${tmpdir}/nbd.pid +tmpnam=${tmpdir}/nbd.dd ulimit -c unlimited @@ -75,13 +76,12 @@ EOF if [ -f ${pidfile} ] then kill `cat ${pidfile}` - rm -f ${pidfile} else kill $PID fi if [ -z "$2" ] then - rm -f $tmpnam ${conffile} + rm -rf $tmpdir fi exit $retval fi @@ -156,13 +156,12 @@ esac if [ -f ${pidfile} ] then kill `cat ${pidfile}` - rm -f ${pidfile} else kill $PID fi if [ -z "$2" ] then - rm -f $tmpnam ${conffile} + rm -rf $tmpdir fi if [ $retval -ne 0 ] then