From: "Grégoire Sutre" <gregoire.sutre@gmail.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Subject: Re: Portable mktemp invocation?
Date: Sat, 25 Sep 2010 13:10:35 +0200 [thread overview]
Message-ID: <4C9DD8AB.4080206@gmail.com> (raw)
In-Reply-To: <4C9B8003.4090003@gmail.com>
[-- Attachment #1: Type: text/plain, Size: 260 bytes --]
On 09/23/2010 06:27 PM, Grégoire Sutre wrote:
> A simple solution would be to replace those invocations with:
>
> mktemp [-d] ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX
The attached patch implements this solution. Build tested on Debian
GNU/Linux and NetBSD.
Grégoire
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: mktemp-fix.diff --]
[-- Type: text/x-patch; name="mktemp-fix.diff", Size: 10189 bytes --]
=== modified file 'ChangeLog'
--- ChangeLog 2010-09-25 05:18:48 +0000
+++ ChangeLog 2010-09-25 10:59:05 +0000
@@ -1,3 +1,16 @@
+2010-09-25 Grégoire Sutre <gregoire.sutre@gmail.com>
+
+ Make mktemp invocations portable.
+
+ * grub-core/genmod.sh.in: Use mktemp with an explicit template.
+ * tests/grub_script_blockarg.in: Likewise.
+ * tests/partmap_test.in: Likewise.
+ * tests/util/grub-shell-tester.in: Likewise.
+ * tests/util/grub-shell.in: Likewise.
+ * util/powerpc/ieee1275/grub-mkrescue.in: Likewise.
+ * Makefile.am: Likewise, and chain shell commands with `&&'
+ instead of ';'.
+
2010-09-25 BVK Chaitanya <bvk.groups@gmail.com>
* grub-core/kern/emu/full.c (grub_emu_post_init): Fix typo.
=== modified file 'Makefile.am'
--- Makefile.am 2010-09-20 12:55:49 +0000
+++ Makefile.am 2010-09-25 10:45:56 +0000
@@ -189,31 +189,31 @@ kopenbsd.init.x86_64: $(srcdir)/grub-cor
$(TARGET_CC) -o $@ $< -m64 -DTARGET_OPENBSD=1 -nostdlib -nostdinc -DSUCCESSFUL_BOOT_STRING=\"$(SUCCESSFUL_BOOT_STRING)\"
linux-initramfs.i386: linux.init.i386 Makefile
- TDIR=`mktemp -d`; cp $< $$TDIR/init; (cd $$TDIR; echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@; rm -rf $$TDIR
+ TDIR=`mktemp -d $${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR
linux-initramfs.x86_64: linux.init.x86_64 Makefile
- TDIR=`mktemp -d`; cp $< $$TDIR/init; (cd $$TDIR; echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@; rm -rf $$TDIR
+ TDIR=`mktemp -d $${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` && cp $< $$TDIR/init && (cd $$TDIR && echo ./init | cpio --quiet --dereference -o -H newc) | gzip > $@ && rm -rf $$TDIR
kfreebsd-mfsroot.i386.img: kfreebsd.init.i386 Makefile
- TDIR=`mktemp -d`; mkdir $$TDIR/dev; mkdir $$TDIR/sbin; cp $< $$TDIR/sbin/init; makefs -t ffs -s 30m -f 1000 -o minfree=0,version=1 $@ $$TDIR; rm -rf $$TDIR
+ TDIR=`mktemp -d $${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -t ffs -s 30m -f 1000 -o minfree=0,version=1 $@ $$TDIR && rm -rf $$TDIR
knetbsd.image.i386: knetbsd.init.i386 $(srcdir)/grub-core/tests/boot/kbsd.spec.txt
- TDIR=`mktemp -d` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -F $(srcdir)/grub-core/tests/boot/kbsd.spec.txt -t ffs -s 64k -f 10 -o minfree=0,version=1 $@ $$TDIR && rm -rf $$TDIR
+ TDIR=`mktemp -d $${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -F $(srcdir)/grub-core/tests/boot/kbsd.spec.txt -t ffs -s 64k -f 10 -o minfree=0,version=1 $@ $$TDIR && rm -rf $$TDIR
kopenbsd.image.i386: kopenbsd.init.i386 $(srcdir)/grub-core/tests/boot/kopenbsdlabel.txt
- TDIR=`mktemp -d` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -F $(srcdir)/grub-core/tests/boot/kbsd.spec.txt -t ffs -s 128k -f 10 -o minfree=0,version=1 $@ $$TDIR && bsdlabel -f -R $@ $(srcdir)/grub-core/tests/boot/kopenbsdlabel.txt && rm -rf $$TDIR || rm -f $@
+ TDIR=`mktemp -d $${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -F $(srcdir)/grub-core/tests/boot/kbsd.spec.txt -t ffs -s 128k -f 10 -o minfree=0,version=1 $@ $$TDIR && bsdlabel -f -R $@ $(srcdir)/grub-core/tests/boot/kopenbsdlabel.txt && rm -rf $$TDIR || rm -f $@
kopenbsd.image.x86_64: kopenbsd.init.x86_64 $(srcdir)/grub-core/tests/boot/kopenbsdlabel.txt
- TDIR=`mktemp -d` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -F $(srcdir)/grub-core/tests/boot/kbsd.spec.txt -t ffs -s 128k -f 10 -o minfree=0,version=1 $@ $$TDIR && bsdlabel -f -R $@ $(srcdir)/grub-core/tests/boot/kopenbsdlabel.txt && rm -rf $$TDIR || rm -f $@
+ TDIR=`mktemp -d $${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -F $(srcdir)/grub-core/tests/boot/kbsd.spec.txt -t ffs -s 128k -f 10 -o minfree=0,version=1 $@ $$TDIR && bsdlabel -f -R $@ $(srcdir)/grub-core/tests/boot/kopenbsdlabel.txt && rm -rf $$TDIR || rm -f $@
knetbsd.miniroot-image.i386.img: knetbsd.image.i386 $(GRUB_PAYLOADS_DIR)/knetbsd.miniroot.i386
$(OBJCOPY) --add-section=miniroot=$< $(GRUB_PAYLOADS_DIR)/knetbsd.miniroot.i386 $@
kfreebsd-mfsroot.x86_64.img: kfreebsd.init.x86_64 Makefile
- TDIR=`mktemp -d`; mkdir $$TDIR/dev; mkdir $$TDIR/sbin; cp $< $$TDIR/sbin/init; makefs -t ffs -s 30m -f 1000 -o minfree=0,version=1 $@ $$TDIR; rm -rf $$TDIR
+ TDIR=`mktemp -d $${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -t ffs -s 30m -f 1000 -o minfree=0,version=1 $@ $$TDIR && rm -rf $$TDIR
knetbsd.image.x86_64: knetbsd.init.x86_64 $(srcdir)/grub-core/tests/boot/kbsd.spec.txt
- TDIR=`mktemp -d` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -F $(srcdir)/grub-core/tests/boot/kbsd.spec.txt -t ffs -s 64k -f 10 -o minfree=0,version=1 $@ $$TDIR && rm -rf $$TDIR
+ TDIR=`mktemp -d $${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` && mkdir $$TDIR/dev && mkdir $$TDIR/sbin && cp $< $$TDIR/sbin/init && makefs -F $(srcdir)/grub-core/tests/boot/kbsd.spec.txt -t ffs -s 64k -f 10 -o minfree=0,version=1 $@ $$TDIR && rm -rf $$TDIR
knetbsd.miniroot-image.x86_64.img: knetbsd.image.x86_64 $(GRUB_PAYLOADS_DIR)/knetbsd.miniroot.x86_64
$(OBJCOPY) --add-section=miniroot=$< $(GRUB_PAYLOADS_DIR)/knetbsd.miniroot.x86_64 $@
=== modified file 'grub-core/genmod.sh.in'
--- grub-core/genmod.sh.in 2010-09-19 13:59:36 +0000
+++ grub-core/genmod.sh.in 2010-09-25 09:51:57 +0000
@@ -38,10 +38,10 @@ rm -f $tmpfile $outfile
objcopy -R .modname -R .moddeps $infile $tmpfile
# Attach .modname and .moddeps sections
-t1=`mktemp`
+t1=`mktemp ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` || exit 1
printf "$modname\0" >$t1
-t2=`mktemp`
+t2=`mktemp ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` || exit 1
for dep in $deps; do printf "$dep\0" >> $t2; done
if test -n "$deps"; then
=== modified file 'tests/grub_script_blockarg.in'
--- tests/grub_script_blockarg.in 2010-08-09 16:12:24 +0000
+++ tests/grub_script_blockarg.in 2010-09-25 09:09:19 +0000
@@ -27,7 +27,7 @@ cmd='test_blockarg { true }'
v=`echo "$cmd" | @builddir@/grub-shell`
error_if_not "$v" '{ true }'
-tmp=`mktemp`
+tmp=`mktemp ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` || exit 1
cmd='test_blockarg { test_blockarg { true } }'
echo "$cmd" | @builddir@/grub-shell >$tmp
error_if_not "`head -n1 $tmp|tail -n1`" '{ test_blockarg { true } }'
=== modified file 'tests/partmap_test.in'
--- tests/partmap_test.in 2010-09-09 15:54:17 +0000
+++ tests/partmap_test.in 2010-09-25 09:10:03 +0000
@@ -51,8 +51,8 @@ list_parts () {
echo
}
-imgfile=`mktemp`
-outfile=`mktemp`
+imgfile=`mktemp ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` || exit 1
+outfile=`mktemp ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` || exit 1
#
# MSDOS partition types
=== modified file 'tests/util/grub-shell-tester.in'
--- tests/util/grub-shell-tester.in 2010-08-19 12:20:05 +0000
+++ tests/util/grub-shell-tester.in 2010-09-25 09:08:23 +0000
@@ -83,17 +83,17 @@ for option in "$@"; do
done
if [ "x${source}" = x ] ; then
- tmpfile=`mktemp`
+ tmpfile=`mktemp ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` || exit 1
while read REPLY; do
echo $REPLY >> ${tmpfile}
done
source=${tmpfile}
fi
-outfile1=`mktemp`
+outfile1=`mktemp ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` || exit 1
@builddir@/grub-shell --qemu-opts="${qemuopts}" --modules=${modules} ${source} >${outfile1}
-outfile2=`mktemp`
+outfile2=`mktemp ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` || exit 1
bash ${source} >${outfile2}
if ! diff -q ${outfile1} ${outfile2} >/dev/null
=== modified file 'tests/util/grub-shell.in'
--- tests/util/grub-shell.in 2010-09-13 12:03:05 +0000
+++ tests/util/grub-shell.in 2010-09-25 09:06:21 +0000
@@ -107,14 +107,14 @@ for option in "$@"; do
done
if [ "x${source}" = x ] ; then
- tmpfile=`mktemp`
+ tmpfile=`mktemp ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` || exit 1
while read REPLY; do
echo "$REPLY" >> ${tmpfile}
done
source=${tmpfile}
fi
-cfgfile=`mktemp`
+cfgfile=`mktemp ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` || exit 1
cat <<EOF >${cfgfile}
grubshell=yes
insmod serial
@@ -123,7 +123,7 @@ terminal_input serial
terminal_output serial
EOF
-rom_directory=`mktemp -d`
+rom_directory=`mktemp -d ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` || exit 1
for mod in ${modules}
do
@@ -135,7 +135,7 @@ source /boot/grub/testcase.cfg
halt
EOF
-isofile=`mktemp`
+isofile=`mktemp ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` || exit 1
if [ x$boot != xnet ]; then
sh @builddir@/grub-mkrescue --grub-mkimage=${builddir}/grub-mkimage --output=${isofile} --override-directory=${builddir}/grub-core \
--rom-directory="${rom_directory}" \
@@ -161,7 +161,7 @@ if [ x$boot = xqemu ]; then
fi
if [ x$boot = xcoreboot ]; then
- imgfile=`mktemp`
+ imgfile=`mktemp ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` || exit 1
cp "${GRUB_COREBOOT_ROM}" "${imgfile}"
"${GRUB_CBFSTOOL}" "${imgfile}" add-payload "${rom_directory}/coreboot.elf" fallback/payload
bootdev="-bios ${imgfile}"
@@ -169,7 +169,7 @@ if [ x$boot = xcoreboot ]; then
fi
if [ x$boot = xnet ]; then
- netdir=`mktemp -d`
+ netdir=`mktemp -d ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` || exit 1
sh @builddir@/grub-mknetdir --grub-mkimage=${builddir}/grub-mkimage --override-directory=${builddir}/grub-core --net-directory=$netdir
cp ${cfgfile} $netdir/boot/grub/grub.cfg
cp ${source} $netdir/boot/grub/testcase.cfg
=== modified file 'util/powerpc/ieee1275/grub-mkrescue.in'
--- util/powerpc/ieee1275/grub-mkrescue.in 2010-06-29 15:20:49 +0000
+++ util/powerpc/ieee1275/grub-mkrescue.in 2010-09-25 09:14:44 +0000
@@ -121,13 +121,13 @@ if [ "x${modules}" = "x" ] ; then
modules=`cd ${input_dir}/ && ls *.mod`
fi
-map_file=`mktemp`
+map_file=`mktemp ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` || exit 1
cat >${map_file} <<EOF
# EXTN XLate CREATOR TYPE Comment
grub.img Raw 'UNIX' 'tbxi' "bootstrap"
EOF
-iso_dir=`mktemp -d`
+iso_dir=`mktemp -d ${TMPDIR:-/tmp}/tmp.XXXXXXXXXX` || exit 1
boot_dir=${iso_dir}/boot/grub
mkdir ${iso_dir}/boot
mkdir ${boot_dir}
next prev parent reply other threads:[~2010-09-25 11:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-09-23 16:27 Portable mktemp invocation? Grégoire Sutre
2010-09-25 11:10 ` Grégoire Sutre [this message]
2010-10-11 17:14 ` Grégoire Sutre
2010-10-16 14:04 ` Vladimir 'φ-coder/phcoder' Serbinenko
2010-10-18 21:11 ` Grégoire Sutre
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4C9DD8AB.4080206@gmail.com \
--to=gregoire.sutre@gmail.com \
--cc=grub-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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.