From 5e08a97bfe685458a0dfa4bbe9d042da0d2ee03b Mon Sep 17 00:00:00 2001 From: Florian Krohm Date: Tue, 12 Jul 2011 19:07:05 +0000 Subject: [PATCH] Make the location for temporary files configurable at runtime. To that effect observe the environment variable TMPDIR. If defined, its value takes precedence over VG_TMPDIR. Because the directory name is no longer a compile time constant, VG_(err_config_error) was changed to take a variable argument list. Fixes #267020. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@11892 --- NEWS | 2 ++ coregrind/m_libcfile.c | 10 ++++++++-- coregrind/m_libcprint.c | 10 +++++++--- coregrind/m_main.c | 8 ++++---- coregrind/pub_core_libcprint.h | 2 +- 5 files changed, 22 insertions(+), 10 deletions(-) diff --git a/NEWS b/NEWS index 8f027ef4dd..2b336b5aac 100644 --- a/NEWS +++ b/NEWS @@ -264,6 +264,8 @@ fixed 271776 - s390x: Support STFLE instruction +267020 - Make directory for temporary files configurable at run-time. + Release 3.6.1 (16 February 2011) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/coregrind/m_libcfile.c b/coregrind/m_libcfile.c index a38df075d9..2f3306a955 100644 --- a/coregrind/m_libcfile.c +++ b/coregrind/m_libcfile.c @@ -603,6 +603,7 @@ Int VG_(mkstemp) ( HChar* part_of_name, /*OUT*/HChar* fullname ) Int n, tries, fd; UInt seed; SysRes sres; + const HChar *tmpdir; vg_assert(part_of_name); n = VG_(strlen)(part_of_name); @@ -610,12 +611,17 @@ Int VG_(mkstemp) ( HChar* part_of_name, /*OUT*/HChar* fullname ) seed = (VG_(getpid)() << 9) ^ VG_(getppid)(); + /* Determine sensible location for temporary files */ + tmpdir = VG_(getenv)("TMPDIR"); + if (tmpdir == NULL || *tmpdir == '\0') tmpdir = VG_TMPDIR; + if (tmpdir == NULL || *tmpdir == '\0') tmpdir = "/tmp"; /* fallback */ + tries = 0; while (True) { if (tries++ > 10) return -1; - VG_(sprintf)( buf, "%s/valgrind_%s_%08x", - VG_TMPDIR, part_of_name, VG_(random)( &seed )); + VG_(sprintf)( buf, "%s/valgrind_%s_%08x", + tmpdir, part_of_name, VG_(random)( &seed )); if (0) VG_(printf)("VG_(mkstemp): trying: %s\n", buf); diff --git a/coregrind/m_libcprint.c b/coregrind/m_libcprint.c index fb2544d514..75eff72d07 100644 --- a/coregrind/m_libcprint.c +++ b/coregrind/m_libcprint.c @@ -590,12 +590,16 @@ void VG_(err_missing_prog) ( void ) } __attribute__((noreturn)) -void VG_(err_config_error) ( Char* msg ) +void VG_(err_config_error) ( Char* format, ... ) { + va_list vargs; + va_start(vargs,format); revert_to_stderr(); - VG_(fmsg)("Startup or configuration error:\n %s\n", msg); - VG_(fmsg)("Unable to start up properly. Giving up.\n"); + VG_(message) (Vg_FailMsg, "Startup or configuration error:\n "); + VG_(vmessage)(Vg_FailMsg, format, vargs ); + VG_(message) (Vg_FailMsg, "Unable to start up properly. Giving up.\n"); VG_(exit)(1); + va_end(vargs); } diff --git a/coregrind/m_main.c b/coregrind/m_main.c index 97fed583cd..cc217f40ea 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -391,7 +391,7 @@ void main_process_cmd_line_options ( /*OUT*/Bool* logging_to_fd, /* Check for sane path in ./configure --prefix=... */ if (VG_LIBDIR[0] != '/') VG_(err_config_error)("Please use absolute paths in " - "./configure --prefix=... or --libdir=..."); + "./configure --prefix=... or --libdir=...\n"); vg_assert( VG_(args_for_valgrind) ); @@ -1599,7 +1599,7 @@ Int valgrind_main ( Int argc, HChar **argv, HChar **envp ) { Bool ok = VG_(record_startup_wd)(); if (!ok) VG_(err_config_error)( "Can't establish current working " - "directory at startup"); + "directory at startup\n"); } { Char buf[VKI_PATH_MAX+1]; Bool ok = VG_(get_startup_wd)( buf, sizeof(buf) ); @@ -1723,7 +1723,7 @@ Int valgrind_main ( Int argc, HChar **argv, HChar **envp ) VG_(sprintf)(buf, "proc_%d_cmdline", VG_(getpid)()); fd = VG_(mkstemp)( buf, buf2 ); if (fd == -1) - VG_(err_config_error)("Can't create client cmdline file in " VG_TMPDIR); + VG_(err_config_error)("Can't create client cmdline file in %s\n", buf2); nul[0] = 0; exename = VG_(args_the_exename) ? VG_(args_the_exename) @@ -1744,7 +1744,7 @@ Int valgrind_main ( Int argc, HChar **argv, HChar **envp ) /* Now delete it, but hang on to the fd. */ r = VG_(unlink)( buf2 ); if (r) - VG_(err_config_error)("Can't delete client cmdline file in " VG_TMPDIR); + VG_(err_config_error)("Can't delete client cmdline file in %s\n", buf2); VG_(cl_cmdline_fd) = fd; } diff --git a/coregrind/pub_core_libcprint.h b/coregrind/pub_core_libcprint.h index 5692972c1b..471d5d215c 100644 --- a/coregrind/pub_core_libcprint.h +++ b/coregrind/pub_core_libcprint.h @@ -62,7 +62,7 @@ extern void VG_(err_missing_prog) ( void ); /* Similarly - complain and stop if there is some kind of config error. */ __attribute__((noreturn)) -extern void VG_(err_config_error) ( Char* msg ); +extern void VG_(err_config_error) ( Char* format, ... ); #endif // __PUB_CORE_LIBCPRINT_H -- 2.47.2