All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Grégoire Sutre" <gregoire.sutre@gmail.com>
To: grub-devel@gnu.org
Subject: Re: Portable mktemp invocation?
Date: Mon, 11 Oct 2010 19:14:51 +0200	[thread overview]
Message-ID: <4CB3460B.4010409@gmail.com> (raw)
In-Reply-To: <4C9B8003.4090003@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 231 bytes --]

This is a new version of the patch.  Changes with respect to the previous
version:

- use double quotes (i.e. "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX")
- apply the same scheme to util/grub-mkrescue.in (intead of MKTEMP_TEMPLATE)

Grégoire

[-- Attachment #2: ChangeLog.mktemp --]
[-- Type: text/plain, Size: 575 bytes --]

2010-10-11  Grégoire Sutre  <gregoire.sutre@gmail.com>

	Make mktemp invocations portable.

	* grub-core/genmod.sh.in: Use mktemp with an explicit template, and
	exit if mktemp fails.
	* 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 ';'.
	* util/grub-mkrescue.in: Use the same explicit template as above, and
	exit if mktemp fails.

[-- Attachment #3: mktemp-fix_v2.diff --]
[-- Type: text/plain, Size: 11532 bytes --]

=== modified file 'Makefile.am'
--- Makefile.am	2010-09-20 12:55:49 +0000
+++ Makefile.am	2010-10-11 15:16:54 +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-10-11 15:34:47 +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-10-11 15:34:24 +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-10-11 15:34:19 +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-10-11 15:34:53 +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-10-11 15:34:40 +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/grub-mkrescue.in'
--- util/grub-mkrescue.in	2010-09-20 12:14:44 +0000
+++ util/grub-mkrescue.in	2010-10-11 15:33:56 +0000
@@ -152,15 +152,7 @@ else
     exit 1
 fi
 
-if test "x$TMP" != x; then
-  MKTEMP_TEMPLATE="$TMP/grub-mkrescue.XXXXXXXXXX"
-elif test "x$TEMP" != x; then
-  MKTEMP_TEMPLATE="$TEMP/grub-mkrescue.XXXXXXXXXX"
-else
-  MKTEMP_TEMPLATE="/tmp/grub-mkrescue.XXXXXXXXXX"
-fi
-
-iso9660_dir=`mktemp -d "$MKTEMP_TEMPLATE"`
+iso9660_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
 mkdir -p ${iso9660_dir}/boot/grub
 
 process_input_dir ()
@@ -197,8 +189,8 @@ make_image ()
 
     echo "Enabling $2 support ..."
 
-    memdisk_img=`mktemp "$MKTEMP_TEMPLATE"`
-    memdisk_dir=`mktemp -d "$MKTEMP_TEMPLATE"`
+    memdisk_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
+    memdisk_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
     mkdir -p ${memdisk_dir}/boot/grub
 
     cat << EOF > ${memdisk_dir}/boot/grub/grub.cfg
@@ -263,12 +255,12 @@ grub_mkisofs_arguments="${grub_mkisofs_a
 # build BIOS core.img
 if test -e "${pc_dir}" ; then
     echo "Enabling BIOS support ..."
-    core_img=`mktemp "$MKTEMP_TEMPLATE"`
+    core_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
     $grub_mkimage -O i386-pc -d ${pc_dir}/ -o ${core_img} --prefix=/boot/grub/i386-pc \
         iso9660 biosdisk
     cat ${pc_dir}/cdboot.img ${core_img} > ${iso9660_dir}/boot/grub/i386-pc/eltorito.img
 
-    embed_img=`mktemp "$MKTEMP_TEMPLATE"`
+    embed_img=`mktemp "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
     cat ${pc_dir}/boot.img ${core_img} > ${embed_img}
 
     rm -f ${core_img}
@@ -287,7 +279,7 @@ fi
 make_image "${multiboot_dir}" i386-multiboot "${iso9660_dir}/boot/multiboot.img" "ata at_keyboard"
 
 if test -e "${efi64_dir}" || test -e "${efi32_dir}"; then
-    efi_dir=`mktemp -d "$MKTEMP_TEMPLATE"`
+    efi_dir=`mktemp -d "${TMPDIR:-/tmp}/tmp.XXXXXXXXXX"` || exit 1
     mkdir -p "${efi_dir}/efi/boot"
 
     # build bootx64.efi

=== 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-10-11 15:34:02 +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}


  parent reply	other threads:[~2010-10-11 17:15 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
2010-10-11 17:14 ` Grégoire Sutre [this message]
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=4CB3460B.4010409@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.