diff --git a/NEWS b/NEWS index 82fe6e391..fa154b72c 100644 --- a/NEWS +++ b/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. diff --git a/src/bin/man/ltlcross.x b/src/bin/man/ltlcross.x index c96e7509a..0f4c5603d 100644 --- a/src/bin/man/ltlcross.x +++ b/src/bin/man/ltlcross.x @@ -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), diff --git a/src/misc/tmpfile.cc b/src/misc/tmpfile.cc index daabe9916..c0d5a9f87 100644 --- a/src/misc/tmpfile.cc +++ b/src/misc/tmpfile.cc @@ -30,20 +30,40 @@ namespace spot { std::list 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(malloc(len + 6 + 1)); + *name = static_cast(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_); }