]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Make the location for temporary files configurable at runtime.
authorFlorian Krohm <florian@eich-krohm.de>
Tue, 12 Jul 2011 19:07:05 +0000 (19:07 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Tue, 12 Jul 2011 19:07:05 +0000 (19:07 +0000)
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
coregrind/m_libcfile.c
coregrind/m_libcprint.c
coregrind/m_main.c
coregrind/pub_core_libcprint.h

diff --git a/NEWS b/NEWS
index 8f027ef4ddba54ab3ce82c22c489af5f6d8d8244..2b336b5aac5c6caeec3cbfaa4f0c11800991f05c 100644 (file)
--- 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)
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
index a38df075d9a51a1fd50b657ba424a297ee0936f4..2f3306a955d664bb46aeb4b5e6c2adf77862f253 100644 (file)
@@ -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);
 
index fb2544d514384dbee1b28a5e0d9f36f46acd88aa..75eff72d07b80b1063e83b6a4824c47a9cecdbd9 100644 (file)
@@ -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);
 }
 
 
index 97fed583cd9e25b28292990009a13aba3ddb7937..cc217f40eaadf581d975ca5071ca9608f44a966f 100644 (file)
@@ -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;
    }
index 5692972c1b46403bd0c8d5e0cde3ac6c5574f895..471d5d215ca552eb849db7a1b9fd5414295a8a65 100644 (file)
@@ -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