[PATCH] don't hard-code the use of /tmp for a small temporary file
Jim Meyering
jim at meyering.net
Mon Sep 12 11:01:39 UTC 2011
FYI,
This is probably not even worth a review, but then again, it seems
like skipping a "trivial" review is often the best way to commit code
with some silly error, so I'll wait for an ACK.
[I've elided the distractingly-large .gitignore diffs below. ]
>From be6026757abb8ad01f7f38d40df55999906e4f55 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering at redhat.com>
Date: Mon, 12 Sep 2011 12:56:00 +0200
Subject: [PATCH] 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.
---
backend.c | 3 +--
bootstrap.conf | 1 +
gnulib-tests/.gitignore | 4 ++++
iwh.h | 1 +
lib/.gitignore | 18 ++++++++++++++++++
rest.c | 5 +++++
6 files changed, 30 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
...
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
...
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) {
--
1.7.7.rc0.362.g5a14
More information about the iwhd-devel
mailing list