tmpfile: Honor SPOT_TMPFILE and SPOT_TMPKEEP.
* src/misc/tmpfile.cc: Check these environment variables. * src/bin/man/ltlcross.x, NEWS: Document them.
This commit is contained in:
parent
1bb5cbd90c
commit
4bafa4e1b0
3 changed files with 50 additions and 7 deletions
4
NEWS
4
NEWS
|
|
@ -6,6 +6,10 @@ New in spot 1.1.4a (not relased)
|
|||
* ltlcross has a new option --color to color its output. It is enabled
|
||||
by default when the output is a terminal.
|
||||
|
||||
* Environment variables SPOT_TMPDIR and SPOT_TMPKEEP control where
|
||||
temporary files are created and if they should be erased. Read
|
||||
the man page of ltlcross for detail.
|
||||
|
||||
* Cleanup of exported symbols
|
||||
|
||||
All symbols in the library now have hidden visibility on ELF systems.
|
||||
|
|
|
|||
|
|
@ -35,6 +35,23 @@ potential problems, avoid the \fB\-\-csv\fR and \fB\-\-json\fR
|
|||
options: ltlcross is faster when it does not have to compute these
|
||||
statistics.
|
||||
|
||||
[ENVIRONMENT VARIABLES]
|
||||
|
||||
.TP
|
||||
\fBSPOT_TMPDIR\fR, \fBTMPDIR\fR
|
||||
These variables control in which directory temporary files (e.g.,
|
||||
those who contain the input and output when interfacing with
|
||||
translators) are created. \fBTMPDIR\fR is only read if
|
||||
\fBSPOT_TMPDIR\fR does not exist. If none of these environment
|
||||
variables exist, or if their value is empty, files are created in the
|
||||
current directory.
|
||||
|
||||
.TP
|
||||
\fBSPOT_TMPKEEP\fR
|
||||
When this variable is defined, temporary files are not removed.
|
||||
This is mostly useful for debugging.
|
||||
|
||||
|
||||
[SEE ALSO]
|
||||
.BR randltl (1),
|
||||
.BR genltl (1),
|
||||
|
|
|
|||
|
|
@ -30,20 +30,40 @@ namespace spot
|
|||
{
|
||||
std::list<temporary_file*> to_clean;
|
||||
|
||||
static
|
||||
int create_temporary_file(const char* prefix,
|
||||
const char* suffix,
|
||||
char** name)
|
||||
static const char*
|
||||
get_tmpdir()
|
||||
{
|
||||
const char* res = secure_getenv("SPOT_TMPDIR");
|
||||
if (res)
|
||||
return res;
|
||||
return secure_getenv("TMPDIR");
|
||||
}
|
||||
|
||||
static int
|
||||
create_temporary_file(const char* prefix,
|
||||
const char* suffix,
|
||||
char** name)
|
||||
throw(std::bad_alloc, std::runtime_error)
|
||||
{
|
||||
static const char* tmpdir = get_tmpdir();
|
||||
static int tmpdirlen = tmpdir ? strlen(tmpdir) : 0;
|
||||
|
||||
size_t len = strlen(prefix);
|
||||
size_t slen = 0;
|
||||
if (suffix)
|
||||
len += slen = strlen(suffix);
|
||||
*name = static_cast<char*>(malloc(len + 6 + 1));
|
||||
*name = static_cast<char*>(malloc(tmpdirlen + 1 + len + 6 + 1));
|
||||
if (!name)
|
||||
throw std::bad_alloc();
|
||||
char* x = stpcpy(stpcpy(*name, prefix), "XXXXXX");
|
||||
char* x = *name;
|
||||
if (tmpdir)
|
||||
{
|
||||
x = stpcpy(x, tmpdir);
|
||||
if (x[-1] != '/')
|
||||
*x++ = '/';
|
||||
}
|
||||
x = stpcpy(x, prefix);
|
||||
x = stpcpy(x, "XXXXXX");
|
||||
int fd;
|
||||
if (suffix)
|
||||
{
|
||||
|
|
@ -68,7 +88,9 @@ namespace spot
|
|||
|
||||
temporary_file::~temporary_file()
|
||||
{
|
||||
unlink(name_);
|
||||
static bool must_unlink = !secure_getenv("SPOT_TMPKEEP");
|
||||
if (must_unlink)
|
||||
unlink(name_);
|
||||
free(name_);
|
||||
to_clean.erase(cleanpos_);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue