* [Qemu-devel] [PATCH] configure: Put tempfiles in subdir so we can clean up libtool files
@ 2014-05-06 13:17 Peter Maydell
2014-05-06 14:36 ` Eric Blake
0 siblings, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2014-05-06 13:17 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, Paolo Bonzini, Don Slutz, patches
When libtool support was added to configure, the new temporary files
were left out of the list of files cleaned up on exit; this results
in a lot of stale .lo files being left around in /tmp. Worse, libtool
creates a /tmp/.libs directory which we can't easily clean up.
Put all our temporary files in a single temporary directory created
via mktemp -d, so we can easily clean it up. This has the bonus
result that we no longer use $RANDOM (which silently expands to the
empty string if your shell is not bash, and so is pretty useless).
Note that because we now use mktemp's tempdir-finding logic rather
than handrolling it, we no longer honour TEMPDIR (only TMPDIR).
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
I don't know why we were looking at TEMPDIR; that code was
in there from the initial commit by Fabrice back in 2003...
configure | 21 ++++++++++-----------
1 file changed, 10 insertions(+), 11 deletions(-)
diff --git a/configure b/configure
index 870c939..84c600f 100755
--- a/configure
+++ b/configure
@@ -2,26 +2,25 @@
#
# qemu configure script (c) 2003 Fabrice Bellard
#
-# set temporary file name
-if test ! -z "$TMPDIR" ; then
- TMPDIR1="${TMPDIR}"
-elif test ! -z "$TEMPDIR" ; then
- TMPDIR1="${TEMPDIR}"
-else
- TMPDIR1="/tmp"
+
+TMPDIR1=$(mktemp -t -d)
+if [ $? -ne 0 ]; then
+ echo "ERROR: failed to create temporary directory"
+ exit 1
fi
-TMPC="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.c"
-TMPB="qemu-conf-${RANDOM}-$$-${RANDOM}"
+TMPB="qemu-conf"
+TMPC="${TMPDIR1}/${TMPB}.c"
TMPO="${TMPDIR1}/${TMPB}.o"
TMPCXX="${TMPDIR1}/${TMPB}.cxx"
TMPL="${TMPDIR1}/${TMPB}.lo"
TMPA="${TMPDIR1}/lib${TMPB}.la"
-TMPE="${TMPDIR1}/qemu-conf-${RANDOM}-$$-${RANDOM}.exe"
+TMPE="${TMPDIR1}/${TMPB}.exe"
# NB: do not call "exit" in the trap handler; this is buggy with some shells;
# see <1285349658-3122-1-git-send-email-loic.minier@linaro.org>
-trap "rm -f $TMPC $TMPO $TMPCXX $TMPE" EXIT INT QUIT TERM
+trap "rm -rf ${TMPDIR1}" EXIT INT QUIT TERM
+
rm -f config.log
# Print a helpful header at the top of config.log
--
1.9.2
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] configure: Put tempfiles in subdir so we can clean up libtool files
2014-05-06 13:17 [Qemu-devel] [PATCH] configure: Put tempfiles in subdir so we can clean up libtool files Peter Maydell
@ 2014-05-06 14:36 ` Eric Blake
2014-05-06 14:53 ` Peter Maydell
0 siblings, 1 reply; 4+ messages in thread
From: Eric Blake @ 2014-05-06 14:36 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: qemu-trivial, Paolo Bonzini, Don Slutz, patches
[-- Attachment #1: Type: text/plain, Size: 1896 bytes --]
On 05/06/2014 07:17 AM, Peter Maydell wrote:
> When libtool support was added to configure, the new temporary files
> were left out of the list of files cleaned up on exit; this results
> in a lot of stale .lo files being left around in /tmp. Worse, libtool
> creates a /tmp/.libs directory which we can't easily clean up.
>
> Put all our temporary files in a single temporary directory created
> via mktemp -d, so we can easily clean it up. This has the bonus
> result that we no longer use $RANDOM (which silently expands to the
> empty string if your shell is not bash, and so is pretty useless).
>
> Note that because we now use mktemp's tempdir-finding logic rather
> than handrolling it, we no longer honour TEMPDIR (only TMPDIR).
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
> I don't know why we were looking at TEMPDIR; that code was
> in there from the initial commit by Fabrice back in 2003...
>
> +
> +TMPDIR1=$(mktemp -t -d)
mktemp is not POSIX. BSD mktemp lacks -t:
http://www.freebsd.org/cgi/man.cgi?query=mktemp&apropos=0&sektion=1&manpath=Red+Hat+Linux%2Fi386+9&format=html
and there are probably systems that lack mktemp(1) altogether. You'll
need to come up with a more portable alternative.
Here's what autoconf recommends (modify to fit...):
# Create a (secure) tmp directory for tmp files.
{
tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
test -d "$tmp"
} ||
{
tmp=./conf$$-$RANDOM
(umask 077 && mkdir "$tmp")
} || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
ac_tmp=$tmp
The use of $$ and $RANDOM is safe (even on shells that lack $RANDOM)
because of the fact that mkdir is atomic and the umask is correctly set
prior to the mkdir.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] configure: Put tempfiles in subdir so we can clean up libtool files
2014-05-06 14:36 ` Eric Blake
@ 2014-05-06 14:53 ` Peter Maydell
2014-05-06 15:43 ` Eric Blake
0 siblings, 1 reply; 4+ messages in thread
From: Peter Maydell @ 2014-05-06 14:53 UTC (permalink / raw)
To: Eric Blake
Cc: QEMU Trivial, Paolo Bonzini, QEMU Developers, Don Slutz,
Patch Tracking
On 6 May 2014 15:36, Eric Blake <eblake@redhat.com> wrote:
> mktemp is not POSIX. BSD mktemp lacks -t:
>
> http://www.freebsd.org/cgi/man.cgi?query=mktemp&apropos=0&sektion=1&manpath=Red+Hat+Linux%2Fi386+9&format=html
Sigh.
> and there are probably systems that lack mktemp(1) altogether. You'll
> need to come up with a more portable alternative.
>
> Here's what autoconf recommends (modify to fit...):
>
> # Create a (secure) tmp directory for tmp files.
>
> {
> tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
> test -d "$tmp"
> } ||
> {
> tmp=./conf$$-$RANDOM
> (umask 077 && mkdir "$tmp")
> } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
> ac_tmp=$tmp
Yuck.
> The use of $$ and $RANDOM is safe (even on shells that lack $RANDOM)
> because of the fact that mkdir is atomic and the umask is correctly set
> prior to the mkdir.
I dislike the use of $RANDOM, because it means we behave
inconsistently. If it's OK for $RANDOM to expand to "" then we
should just not use it at all, because that's OK and the same
everywhere.
Similarly, if it's OK not to use mktemp on some systems,
we should use the same non-mktemp code everywhere.
We could sidestep this rubbish by not trying to put our temp
files in /tmp/, and instead just put them in the build directory
(ie ./conf-temps/ or something similar, which we blow away
and recreate every time).
thanks
-- PMM
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] configure: Put tempfiles in subdir so we can clean up libtool files
2014-05-06 14:53 ` Peter Maydell
@ 2014-05-06 15:43 ` Eric Blake
0 siblings, 0 replies; 4+ messages in thread
From: Eric Blake @ 2014-05-06 15:43 UTC (permalink / raw)
To: Peter Maydell
Cc: QEMU Trivial, Paolo Bonzini, QEMU Developers, Don Slutz,
Patch Tracking
[-- Attachment #1: Type: text/plain, Size: 1836 bytes --]
On 05/06/2014 08:53 AM, Peter Maydell wrote:
>> # Create a (secure) tmp directory for tmp files.
>>
>> {
>> tmp=`(umask 077 && mktemp -d "./confXXXXXX") 2>/dev/null` &&
>> test -d "$tmp"
>> } ||
>> {
>> tmp=./conf$$-$RANDOM
>> (umask 077 && mkdir "$tmp")
>> } || as_fn_error $? "cannot create a temporary directory in ." "$LINENO" 5
>> ac_tmp=$tmp
>
> Yuck.
>
>> The use of $$ and $RANDOM is safe (even on shells that lack $RANDOM)
>> because of the fact that mkdir is atomic and the umask is correctly set
>> prior to the mkdir.
>
> I dislike the use of $RANDOM, because it means we behave
> inconsistently. If it's OK for $RANDOM to expand to "" then we
> should just not use it at all, because that's OK and the same
> everywhere.
It's okay for $RANDOM to expand to "" in the fallback code, for the
platforms that lack mktemp(1); most developers are on a platform that
have mktemp. The use of $RANDOM makes it harder for an attacker to
pre-create a competing file by the same name, but does not add any
security; so omitting $RANDOM for the fallback path doesn't hurt if you
are that bothered by seeing it present in a dash script.
>
> Similarly, if it's OK not to use mktemp on some systems,
> we should use the same non-mktemp code everywhere.
The fallback is not ideal, but tolerable. It's still better to try and
use mktemp where it exists.
>
> We could sidestep this rubbish by not trying to put our temp
> files in /tmp/, and instead just put them in the build directory
> (ie ./conf-temps/ or something similar, which we blow away
> and recreate every time).
Yes, using a different location for temporary files and avoiding /tmp
might also work.
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 604 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2014-05-06 15:44 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-06 13:17 [Qemu-devel] [PATCH] configure: Put tempfiles in subdir so we can clean up libtool files Peter Maydell
2014-05-06 14:36 ` Eric Blake
2014-05-06 14:53 ` Peter Maydell
2014-05-06 15:43 ` Eric Blake
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).