aboutsummaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorMarcel Moolenaar <marcel@FreeBSD.org>2014-05-22 20:24:30 +0000
committerMarcel Moolenaar <marcel@FreeBSD.org>2014-05-22 20:24:30 +0000
commitaa30ba04c3d132fffb5194a3853b5f4e1fbd0a55 (patch)
treee30c821cd9c76b943c0258f1dff60fce0d5c49df /usr.bin
parent47206692f2cca020891d1eec5028e02c3e6f56c5 (diff)
downloadsrc-aa30ba04c3d132fffb5194a3853b5f4e1fbd0a55.tar.gz
src-aa30ba04c3d132fffb5194a3853b5f4e1fbd0a55.zip
Create our temporary file in $TMPDIR, if the environment variable
is set. /tmp otherwise. Submitted by: Dan McGregor <danismostlikely@gmail.com>
Notes
Notes: svn path=/head/; revision=266556
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mkimg/image.c10
-rw-r--r--usr.bin/mkimg/mkimg.17
2 files changed, 15 insertions, 2 deletions
diff --git a/usr.bin/mkimg/image.c b/usr.bin/mkimg/image.c
index e92b1f278791..e8dc8fe2082f 100644
--- a/usr.bin/mkimg/image.c
+++ b/usr.bin/mkimg/image.c
@@ -30,6 +30,9 @@ __FBSDID("$FreeBSD$");
#include <sys/types.h>
#include <assert.h>
#include <errno.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -38,7 +41,7 @@ __FBSDID("$FreeBSD$");
#define BUFFER_SIZE (1024*1024)
-static char image_tmpfile[] = "/tmp/mkimg-XXXXXX";
+static char image_tmpfile[PATH_MAX];
static int image_fd = -1;
static lba_t image_size;
@@ -161,9 +164,14 @@ image_write(lba_t blk, void *buf, ssize_t len)
int
image_init(void)
{
+ const char *tmpdir;
if (atexit(cleanup) == -1)
return (errno);
+ if ((tmpdir = getenv("TMPDIR")) == NULL || *tmpdir == '\0')
+ tmpdir = _PATH_TMP;
+ snprintf(image_tmpfile, sizeof(image_tmpfile), "%s/mkimg-XXXXXX",
+ tmpdir);
image_fd = mkstemp(image_tmpfile);
if (image_fd == -1)
return (errno);
diff --git a/usr.bin/mkimg/mkimg.1 b/usr.bin/mkimg/mkimg.1
index f5144bef871c..cf86308ab680 100644
--- a/usr.bin/mkimg/mkimg.1
+++ b/usr.bin/mkimg/mkimg.1
@@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd March 27, 2014
+.Dd May 22, 2014
.Dt MKIMG 1
.Os
.Sh NAME
@@ -159,6 +159,11 @@ For partitioning schemes that feature partition labels, the
utility supports assigning labels to the partitions specified.
In the following example the file system partition is labeled as 'backup':
.Dl % mkimg -s gpt -p freebsd-ufs/backup:=file-system.ufs -o gpt.img
+.Sh ENVIRONMENT
+.Bl -tag -width "TMPDIR" -compact
+.It Ev TMPDIR
+Directory to put temporary files in; default is
+.Pa /tmp .
.Sh SEE ALSO
.Xr gpart 8
.Xr makefs 8