From: Florian Krohm Date: Thu, 29 Sep 2011 03:03:45 +0000 (+0000) Subject: Remove hardwired /tmp directory in vgdb. Honour VG_TMPDIR X-Git-Tag: svn/VALGRIND_3_7_0~174 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=47c681afb8159394cc29518ead0cfa418eb2046d;p=thirdparty%2Fvalgrind.git Remove hardwired /tmp directory in vgdb. Honour VG_TMPDIR and TMPDIR which was introduced when fixing bugzilla #267020. Factor out VG_(tmpdir). New function VG_(vgdb_path_prefix). Partially fixes bugzilla #280757. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12063 --- diff --git a/coregrind/m_gdbserver/remote-utils.c b/coregrind/m_gdbserver/remote-utils.c index 022049c318..69f6aed922 100644 --- a/coregrind/m_gdbserver/remote-utils.c +++ b/coregrind/m_gdbserver/remote-utils.c @@ -228,7 +228,7 @@ void remote_open (char *name) offsetof(ThreadState, status), offsetof(ThreadState, os_state) + offsetof(ThreadOSstate, lwpid)}; const int pid = VG_(getpid)(); - const int name_default = strcmp(name, VG_CLO_VGDB_PREFIX_DEFAULT) == 0; + const int name_default = strcmp(name, VG_(vgdb_prefix_default)()) == 0; Addr addr_shared; SysRes o; int shared_mem_fd = INVALID_DESCRIPTOR; @@ -1059,3 +1059,19 @@ int decode_X_packet (char *from, int packet_len, CORE_ADDR *mem_addr_ptr, return 0; } + +/* Return the path prefix for the named pipes (FIFOs) used by vgdb/gdb + to communicate with valgrind */ +HChar * +VG_(vgdb_prefix_default)(void) +{ + const HChar *tmpdir; + HChar *prefix; + + tmpdir = VG_(tmpdir)(); + prefix = malloc(strlen(tmpdir) + strlen("/vgdb-pipe") + 1); + strcpy(prefix, tmpdir); + strcat(prefix, "/vgdb-pipe"); + + return prefix; +} diff --git a/coregrind/m_libcfile.c b/coregrind/m_libcfile.c index d5b425dff5..0b8ab41437 100644 --- a/coregrind/m_libcfile.c +++ b/coregrind/m_libcfile.c @@ -601,6 +601,18 @@ SysRes VG_(pread) ( Int fd, void* buf, Int count, OffT offset ) # endif } +/* Return the name of a directory for temporary files. */ +const HChar *VG_(tmpdir)(void) +{ + const HChar *tmpdir; + + tmpdir = VG_(getenv)("TMPDIR"); + if (tmpdir == NULL || *tmpdir == '\0') tmpdir = VG_TMPDIR; + if (tmpdir == NULL || *tmpdir == '\0') tmpdir = "/tmp"; /* fallback */ + + return tmpdir; +} + /* Create and open (-rw------) a tmp file name incorporating said arg. Returns -1 on failure, else the fd of the file. If fullname is non-NULL, the file's name is written into it. The number of bytes @@ -621,9 +633,7 @@ 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 */ + tmpdir = VG_(tmpdir)(); tries = 0; while (True) { diff --git a/coregrind/m_main.c b/coregrind/m_main.c index ca82eb473b..49b2daf0ce 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -671,6 +671,10 @@ void main_process_cmd_line_options ( /*OUT*/Bool* logging_to_fd, /* END command-line processing loop */ + /* Determine the path prefix for vgdb */ + if (VG_(clo_vgdb_prefix) == NULL) + VG_(clo_vgdb_prefix) = VG_(vgdb_prefix_default)(); + /* Make VEX control parameters sane */ if (VG_(clo_vex_control).guest_chase_thresh diff --git a/coregrind/m_options.c b/coregrind/m_options.c index abc5b2da0f..7ae9a7a2b9 100644 --- a/coregrind/m_options.c +++ b/coregrind/m_options.c @@ -54,7 +54,7 @@ VgVgdb VG_(clo_vgdb) = Vg_VgdbYes; #endif Int VG_(clo_vgdb_poll) = 5000; Int VG_(clo_vgdb_error) = 999999999; -Char* VG_(clo_vgdb_prefix) = VG_CLO_VGDB_PREFIX_DEFAULT; +HChar* VG_(clo_vgdb_prefix) = NULL; Bool VG_(clo_vgdb_shadow_registers) = False; Bool VG_(clo_db_attach) = False; diff --git a/coregrind/pub_core_gdbserver.h b/coregrind/pub_core_gdbserver.h index a001cc6c09..481162c5c6 100644 --- a/coregrind/pub_core_gdbserver.h +++ b/coregrind/pub_core_gdbserver.h @@ -32,6 +32,9 @@ #include "pub_tool_gdbserver.h" +/* Return the path prefix for the named pipes (FIFOs) used by vgdb/gdb + to communicate with valgrind */ +HChar* VG_(vgdb_prefix_default)(void); // After a fork or after an exec, call the below to (possibly) terminate // the previous gdbserver and then activate a new gdbserver diff --git a/coregrind/pub_core_libcfile.h b/coregrind/pub_core_libcfile.h index 9cfaab20d5..9a5bc5477b 100644 --- a/coregrind/pub_core_libcfile.h +++ b/coregrind/pub_core_libcfile.h @@ -90,6 +90,9 @@ extern SysRes VG_(pread) ( Int fd, void* buf, Int count, OffT offset ); written is guaranteed not to exceed 64+strlen(part_of_name). */ extern Int VG_(mkstemp) ( HChar* part_of_name, /*OUT*/HChar* fullname ); +/* Return the name of a directory for temporary files. */ +extern const HChar* VG_(tmpdir)(void); + /* Record the process' working directory at startup. Is intended to be called exactly once, at startup, before the working directory changes. Return True for success, False for failure, so that the diff --git a/coregrind/pub_core_options.h b/coregrind/pub_core_options.h index 7706d8ee19..9b06a59d6b 100644 --- a/coregrind/pub_core_options.h +++ b/coregrind/pub_core_options.h @@ -69,11 +69,10 @@ extern VgVgdb VG_(clo_vgdb); /* if > 0, checks every VG_(clo_vgdb_poll) BBS if vgdb wants to be served. */ extern Int VG_(clo_vgdb_poll); /* prefix for the named pipes (FIFOs) used by vgdb/gdb to communicate with valgrind */ -extern Char* VG_(clo_vgdb_prefix); +extern HChar* VG_(clo_vgdb_prefix); /* if True, gdbserver in valgrind will expose a target description containing shadow registers */ extern Bool VG_(clo_vgdb_shadow_registers); -#define VG_CLO_VGDB_PREFIX_DEFAULT "/tmp/vgdb-pipe" /* Enquire about whether to attach to a debugger at errors? default: NO */ extern Bool VG_(clo_db_attach); diff --git a/coregrind/vgdb.c b/coregrind/vgdb.c index 46e7b6811c..f0a66e1c49 100644 --- a/coregrind/vgdb.c +++ b/coregrind/vgdb.c @@ -46,6 +46,7 @@ int main (int argc, char** argv) #include "pub_core_libcsetjmp.h" #include "pub_core_threadstate.h" #include "pub_core_gdbserver.h" +#include "config.h" #include #include @@ -141,7 +142,7 @@ static struct timeval dbgtv; fflush(stderr), \ exit(1)) -static char *vgdb_prefix = "/tmp/vgdb-pipe"; +static char *vgdb_prefix = NULL; /* Will be set to True when any condition indicating we have to shutdown is encountered. */ @@ -178,6 +179,35 @@ void *vrealloc(void *ptr,size_t size) return mem; } +/* Return the name of a directory for temporary files. */ +static +const char *vgdb_tmpdir(void) +{ + const char *tmpdir; + + tmpdir = getenv("TMPDIR"); + if (tmpdir == NULL || *tmpdir == '\0') tmpdir = VG_TMPDIR; + if (tmpdir == NULL || *tmpdir == '\0') tmpdir = "/tmp"; /* fallback */ + + return tmpdir; +} + +/* Return the path prefix for the named pipes (FIFOs) used by vgdb/gdb + to communicate with valgrind */ +static +char *vgdb_prefix_default(void) +{ + const char *tmpdir; + HChar *prefix; + + tmpdir = vgdb_tmpdir(); + prefix = vmalloc(strlen(tmpdir) + strlen("/vgdb-pipe") + 1); + strcpy(prefix, tmpdir); + strcat(prefix, "/vgdb-pipe"); + + return prefix; +} + /* add nrw to the written_by_vgdb field of shared32 or shared64 */ static void add_written(int nrw) @@ -2264,6 +2294,9 @@ void parse_options(int argc, char** argv, } } + if (vgdb_prefix == NULL) + vgdb_prefix = vgdb_prefix_default(); + if (isatty(0) && !show_shared_mem && !show_list