commit 5ca32f6ffd606513d0bdc02aac0ee7012cf69a05
Author: Jim Meyering <meyering(a)redhat.com>
Date: Mon Sep 12 12:56:00 2011 +0200
don't hard-code the use of /tmp for a small temporary file
* iwh.h (tmpfile_template): New global.
* rest.c: Include "xvasprintf.h".
(main): Define it.
* backend.c (s3_init_tmpfile): Use it, in place of
hard-coded "/tmp/iwh.XXXXXX".
* bootstrap.conf (gnulib_modules): Use xvasprintf.
* man/iwhd.x (FILES): Mention $TMPDIR and the default of /tmp.
backend.c | 3 +--
bootstrap.conf | 1 +
gnulib-tests/.gitignore | 4 ++++
iwh.h | 1 +
lib/.gitignore | 18 ++++++++++++++++++
man/iwhd.x | 3 +++
rest.c | 5 +++++
7 files changed, 33 insertions(+), 2 deletions(-)
---
diff --git a/backend.c b/backend.c
index 20a5d1c..5a38cca 100644
--- a/backend.c
+++ b/backend.c
@@ -331,8 +331,7 @@ s3_init_tmpfile (const char *value)
size_t len;
ssize_t written;
- /* FIXME: do not hard-code /tmp. */
- path = strdup("/tmp/iwtmp.XXXXXX");
+ path = strdup(tmpfile_template);
if (!path) {
return NULL;
}
diff --git a/bootstrap.conf b/bootstrap.conf
index 49c2dfb..23703d1 100644
--- a/bootstrap.conf
+++ b/bootstrap.conf
@@ -78,6 +78,7 @@ xalloc
xalloc-die
xalloc-oversized
xstrtoumax
+xvasprintf
'
gnulib_name=libiwhd
diff --git a/gnulib-tests/.gitignore b/gnulib-tests/.gitignore
index cbae675..8e013fa 100644
--- a/gnulib-tests/.gitignore
+++ b/gnulib-tests/.gitignore
@@ -11,6 +11,7 @@
/float+.h
/float.h
/float.in.h
+/fpucw.h
/fpurge.c
/fseeko.c
/ftell.c
@@ -89,6 +90,7 @@
/test-fflush2.sh
/test-file-has-acl.c
/test-file-has-acl.sh
+/test-float.c
/test-fpending.c
/test-fpending.sh
/test-fpurge.c
@@ -189,6 +191,7 @@
/test-unsetenv.c
/test-update-copyright.sh
/test-vasnprintf.c
+/test-vasprintf.c
/test-vc-list-files-cvs.sh
/test-vc-list-files-git.sh
/test-verify.c
@@ -214,6 +217,7 @@
/test-xstrtoul.c
/test-xstrtoumax.c
/test-xstrtoumax.sh
+/test-xvasprintf.c
/time.h
/time.in.h
/uinttostr.c
diff --git a/iwh.h b/iwh.h
index e18a7a0..ed2e01d 100644
--- a/iwh.h
+++ b/iwh.h
@@ -27,6 +27,7 @@ GLOBAL(unsigned short, master_port, MY_PORT);
GLOBAL(char *, db_host, NULL);
GLOBAL(unsigned short, db_port, 0);
GLOBAL(const char *, me, "here");
+GLOBAL(char *, tmpfile_template, NULL);
#ifndef __attribute__
# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8)
diff --git a/lib/.gitignore b/lib/.gitignore
index 05bc38e..14f2de4 100644
--- a/lib/.gitignore
+++ b/lib/.gitignore
@@ -4,6 +4,8 @@
/alloca.h
/alloca.in.h
/arg-nonnull.h
+/asnprintf.c
+/asprintf.c
/base64.c
/base64.h
/basename-lgpl.c
@@ -48,6 +50,10 @@
/fd-hook.h
/fflush.c
/file-has-acl.c
+/float+.h
+/float.c
+/float.h
+/float.in.h
/fpending.c
/fpending.h
/fpurge.c
@@ -113,6 +119,10 @@
/mkstemp.c
/open.c
/pipe.c
+/printf-args.c
+/printf-args.h
+/printf-parse.c
+/printf-parse.h
/progname.c
/progname.h
/propername.c
@@ -132,6 +142,7 @@
/safe-write.c
/safe-write.h
/set-mode-acl.c
+/size_max.h
/stat.c
/stdarg.h
/stdarg.in.h
@@ -193,6 +204,9 @@
/uniwidth.in.h
/unlink.c
/unlocked-io.h
+/vasnprintf.c
+/vasnprintf.h
+/vasprintf.c
/verify.h
/version-etc-fsf.c
/version-etc.c
@@ -207,7 +221,9 @@
/xalloc-die.c
/xalloc-oversized.h
/xalloc.h
+/xasprintf.c
/xmalloc.c
+/xsize.h
/xstriconv.c
/xstriconv.h
/xstrndup.c
@@ -217,3 +233,5 @@
/xstrtol.h
/xstrtoul.c
/xstrtoumax.c
+/xvasprintf.c
+/xvasprintf.h
diff --git a/man/iwhd.x b/man/iwhd.x
index 415ca29..0b797bb 100644
--- a/man/iwhd.x
+++ b/man/iwhd.x
@@ -2,3 +2,6 @@
.TP
.I /var/log/iwhd.log
Log file established by default /etc/init file.
+.I /tmp
+Directory for small temporary files, configurable via the $TMPDIR
+environment variable.
diff --git a/rest.c b/rest.c
index eeae361..92f36cb 100644
--- a/rest.c
+++ b/rest.c
@@ -52,6 +52,7 @@
#include "state_defs.h"
#include "version-etc.h"
#include "xstrtol.h"
+#include "xvasprintf.h"
const char version_etc_copyright[] =
/* Do *not* mark this string for translation. %s is a copyright
@@ -2365,6 +2366,10 @@ args_done:
usage (EXIT_FAILURE);
}
+ char *t;
+ char const *tmpdir = ((t = getenv ("TMPDIR")) ? t : "/tmp");
+ tmpfile_template = xasprintf ("%s/iwhd.XXXXXX", tmpdir);
+
sem_init(&the_sem,0,0);
if (verbose) {