* [Qemu-trivial] [PATCH] configure: Put tempfiles in a subdir of the build directory
@ 2014-05-19 17:19 ` Peter Maydell
0 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2014-05-19 17:19 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, Paolo Bonzini, Eric Blake, 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
as a subdirectory of the build directory, so we can easily clean it up,
and don't need fragile or complicated code for creation to avoid it
clashing with temporary directories from other instances of QEMU
configure or being subject to attack from adversaries who can write
to /tmp.
Since the temporaries now live in the build tree, we have no
need to jump through hoops with a trap handler to try to remove
them when configure exits; this fixes some weird bugs where hitting
^C during a configure run wouldn't actually make it stop, because
we would run the trap handler but then not stop. (It is possible
to get the trap handler semantics right but it is convoluted largely
because of bugs in dash, so it is simpler to just avoid it.)
Note that "temporary files go in the build directory, not /tmp" is
the way autoconf behaves.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
If we really wanted to run a cleanup handler then to cope
with dash bugs I think this has to be:
trap 'exit $?' INT QUIT TERM
trap 'ret=$?; cleanup here; exit $?' EXIT
(and even then this doesn't work if you run with -ex...)
.gitignore | 1 +
configure | 28 +++++++++++++++-------------
2 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/.gitignore b/.gitignore
index 8a52709..c658613 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@
/config-host.*
/config-target.*
/config.status
+/config-temp
/trace/generated-tracers.h
/trace/generated-tracers.c
/trace/generated-tracers-dtrace.h
diff --git a/configure b/configure
index 605a0ec..e06386a 100755
--- a/configure
+++ b/configure
@@ -2,26 +2,28 @@
#
# 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"
+
+# Temporary directory used for files created while
+# configure runs. Since it is in the build directory
+# we can safely blow away any previous version of it
+# (and we need not jump through hoops to try to delete
+# it when configure exits.)
+TMPDIR1="config-temp"
+rm -rf "${TMPDIR1}"
+mkdir -p "${TMPDIR1}"
+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
rm -f config.log
# Print a helpful header at the top of config.log
--
1.9.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [Qemu-devel] [PATCH] configure: Put tempfiles in a subdir of the build directory
@ 2014-05-19 17:19 ` Peter Maydell
0 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2014-05-19 17:19 UTC (permalink / raw)
To: qemu-devel; +Cc: qemu-trivial, Paolo Bonzini, 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
as a subdirectory of the build directory, so we can easily clean it up,
and don't need fragile or complicated code for creation to avoid it
clashing with temporary directories from other instances of QEMU
configure or being subject to attack from adversaries who can write
to /tmp.
Since the temporaries now live in the build tree, we have no
need to jump through hoops with a trap handler to try to remove
them when configure exits; this fixes some weird bugs where hitting
^C during a configure run wouldn't actually make it stop, because
we would run the trap handler but then not stop. (It is possible
to get the trap handler semantics right but it is convoluted largely
because of bugs in dash, so it is simpler to just avoid it.)
Note that "temporary files go in the build directory, not /tmp" is
the way autoconf behaves.
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
If we really wanted to run a cleanup handler then to cope
with dash bugs I think this has to be:
trap 'exit $?' INT QUIT TERM
trap 'ret=$?; cleanup here; exit $?' EXIT
(and even then this doesn't work if you run with -ex...)
.gitignore | 1 +
configure | 28 +++++++++++++++-------------
2 files changed, 16 insertions(+), 13 deletions(-)
diff --git a/.gitignore b/.gitignore
index 8a52709..c658613 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,6 +4,7 @@
/config-host.*
/config-target.*
/config.status
+/config-temp
/trace/generated-tracers.h
/trace/generated-tracers.c
/trace/generated-tracers-dtrace.h
diff --git a/configure b/configure
index 605a0ec..e06386a 100755
--- a/configure
+++ b/configure
@@ -2,26 +2,28 @@
#
# 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"
+
+# Temporary directory used for files created while
+# configure runs. Since it is in the build directory
+# we can safely blow away any previous version of it
+# (and we need not jump through hoops to try to delete
+# it when configure exits.)
+TMPDIR1="config-temp"
+rm -rf "${TMPDIR1}"
+mkdir -p "${TMPDIR1}"
+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
rm -f config.log
# Print a helpful header at the top of config.log
--
1.9.2
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [Qemu-trivial] [PATCH] configure: Put tempfiles in a subdir of the build directory
2014-05-19 17:19 ` [Qemu-devel] " Peter Maydell
@ 2014-05-19 17:46 ` Eric Blake
-1 siblings, 0 replies; 6+ messages in thread
From: Eric Blake @ 2014-05-19 17:46 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: qemu-trivial, Paolo Bonzini, patches
[-- Attachment #1: Type: text/plain, Size: 2011 bytes --]
On 05/19/2014 11:19 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
> as a subdirectory of the build directory, so we can easily clean it up,
> and don't need fragile or complicated code for creation to avoid it
> clashing with temporary directories from other instances of QEMU
> configure or being subject to attack from adversaries who can write
> to /tmp.
>
> Since the temporaries now live in the build tree, we have no
> need to jump through hoops with a trap handler to try to remove
> them when configure exits; this fixes some weird bugs where hitting
> ^C during a configure run wouldn't actually make it stop, because
> we would run the trap handler but then not stop. (It is possible
> to get the trap handler semantics right but it is convoluted largely
> because of bugs in dash, so it is simpler to just avoid it.)
>
> Note that "temporary files go in the build directory, not /tmp" is
> the way autoconf behaves.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
Reviewed-by: Eric Blake <eblake@redhat.com>
>
> -# 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
While we don't need a trap that jumps through hoops, it may still be
nice to have a 'rm -r ${TMPDIR1}' at the end of configure. Just because
we cleanup a leftover config-temp on start from an earlier aborted run
doesn't mean that a clean run shouldn't clean up after itself.
--
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] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] configure: Put tempfiles in a subdir of the build directory
@ 2014-05-19 17:46 ` Eric Blake
0 siblings, 0 replies; 6+ messages in thread
From: Eric Blake @ 2014-05-19 17:46 UTC (permalink / raw)
To: Peter Maydell, qemu-devel; +Cc: qemu-trivial, Paolo Bonzini, patches
[-- Attachment #1: Type: text/plain, Size: 2011 bytes --]
On 05/19/2014 11:19 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
> as a subdirectory of the build directory, so we can easily clean it up,
> and don't need fragile or complicated code for creation to avoid it
> clashing with temporary directories from other instances of QEMU
> configure or being subject to attack from adversaries who can write
> to /tmp.
>
> Since the temporaries now live in the build tree, we have no
> need to jump through hoops with a trap handler to try to remove
> them when configure exits; this fixes some weird bugs where hitting
> ^C during a configure run wouldn't actually make it stop, because
> we would run the trap handler but then not stop. (It is possible
> to get the trap handler semantics right but it is convoluted largely
> because of bugs in dash, so it is simpler to just avoid it.)
>
> Note that "temporary files go in the build directory, not /tmp" is
> the way autoconf behaves.
>
> Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
> ---
Reviewed-by: Eric Blake <eblake@redhat.com>
>
> -# 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
While we don't need a trap that jumps through hoops, it may still be
nice to have a 'rm -r ${TMPDIR1}' at the end of configure. Just because
we cleanup a leftover config-temp on start from an earlier aborted run
doesn't mean that a clean run shouldn't clean up after itself.
--
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] 6+ messages in thread
* Re: [Qemu-trivial] [PATCH] configure: Put tempfiles in a subdir of the build directory
2014-05-19 17:46 ` [Qemu-devel] " Eric Blake
@ 2014-05-19 17:50 ` Peter Maydell
-1 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2014-05-19 17:50 UTC (permalink / raw)
To: Eric Blake; +Cc: QEMU Trivial, Paolo Bonzini, QEMU Developers, Patch Tracking
On 19 May 2014 18:46, Eric Blake <eblake@redhat.com> wrote:
> On 05/19/2014 11:19 AM, Peter Maydell wrote:
>> -# 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
>
> While we don't need a trap that jumps through hoops, it may still be
> nice to have a 'rm -r ${TMPDIR1}' at the end of configure. Just because
> we cleanup a leftover config-temp on start from an earlier aborted run
> doesn't mean that a clean run shouldn't clean up after itself.
Yeah, I was in two minds about that, but you're right that
it's a little neater to clean up after a successful run.
thanks
-- PMM
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Qemu-devel] [PATCH] configure: Put tempfiles in a subdir of the build directory
@ 2014-05-19 17:50 ` Peter Maydell
0 siblings, 0 replies; 6+ messages in thread
From: Peter Maydell @ 2014-05-19 17:50 UTC (permalink / raw)
To: Eric Blake; +Cc: QEMU Trivial, Paolo Bonzini, QEMU Developers, Patch Tracking
On 19 May 2014 18:46, Eric Blake <eblake@redhat.com> wrote:
> On 05/19/2014 11:19 AM, Peter Maydell wrote:
>> -# 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
>
> While we don't need a trap that jumps through hoops, it may still be
> nice to have a 'rm -r ${TMPDIR1}' at the end of configure. Just because
> we cleanup a leftover config-temp on start from an earlier aborted run
> doesn't mean that a clean run shouldn't clean up after itself.
Yeah, I was in two minds about that, but you're right that
it's a little neater to clean up after a successful run.
thanks
-- PMM
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-05-19 17:51 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-05-19 17:19 [Qemu-trivial] [PATCH] configure: Put tempfiles in a subdir of the build directory Peter Maydell
2014-05-19 17:19 ` [Qemu-devel] " Peter Maydell
2014-05-19 17:46 ` [Qemu-trivial] " Eric Blake
2014-05-19 17:46 ` [Qemu-devel] " Eric Blake
2014-05-19 17:50 ` [Qemu-trivial] " Peter Maydell
2014-05-19 17:50 ` [Qemu-devel] " Peter Maydell
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.