]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Change the name of the pipes for vgdb by adding username and hostname.
authorFlorian Krohm <florian@eich-krohm.de>
Thu, 29 Sep 2011 21:20:49 +0000 (21:20 +0000)
committerFlorian Krohm <florian@eich-krohm.de>
Thu, 29 Sep 2011 21:20:49 +0000 (21:20 +0000)
Those are obtained by looking at some commonly defined environment
variables.
That should help with problems where /tmp is shared or process IDs get
recycled. We had some intermittent nightly build issues because of that.
Partial fix for bugzilla #280757.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@12071

coregrind/m_gdbserver/remote-utils.c
coregrind/vgdb.c

index 69f6aed922e80346bea4c8c25f3f90e12809384e..d1ae548e951c2ca46c52851eabfd4dc36d443c2f 100644 (file)
@@ -214,14 +214,15 @@ void safe_mknod (char *nod)
    NAME is the filename used for communication.  
    For Valgrind, name is the prefix for the two read and write FIFOs
    The two FIFOs names will be build by appending 
-   -from-vgdb-to-pid and -to-vgdb-from-pid
+   -from-vgdb-to-pid-by-user-on-host and -to-vgdb-from-pid-by-user-on-host
    with pid being the pidnr of the valgrind process These two FIFOs
    will be created if not existing yet. They will be removed when
    the gdbserver connection is closed or the process exits */
 
 void remote_open (char *name)
 {
-   int save_fcntl_flags;
+   const HChar *user, *host;
+   int save_fcntl_flags, len;
    VgdbShared vgdbinit = 
       {0, 0, 0, (Addr) VG_(invoke_gdbserver),
        (Addr) VG_(threads), sizeof(ThreadState), 
@@ -233,19 +234,32 @@ void remote_open (char *name)
    SysRes o;
    int shared_mem_fd = INVALID_DESCRIPTOR;
    
+   user = VG_(getenv)("LOGNAME");
+   if (user == NULL) user = VG_(getenv)("USER");
+   if (user == NULL) user = "???";
+
+   host = VG_(getenv)("HOST");
+   if (host == NULL) host = VG_(getenv)("HOSTNAME");
+   if (host == NULL) host = "???";
+
+   len = strlen(name) + strlen(user) + strlen(host) + 40;
+
    if (from_gdb != NULL) 
       free (from_gdb);
-   from_gdb = malloc (strlen(name) + 30);
+   from_gdb = malloc (len);
    if (to_gdb != NULL)
       free (to_gdb);
-   to_gdb = malloc (strlen(name) + 30);
+   to_gdb = malloc (len);
    if (shared_mem != NULL)
       free (shared_mem);
-   shared_mem = malloc (strlen(name) + 30);
+   shared_mem = malloc (len);
    /* below 3 lines must match the equivalent in vgdb.c */
-   VG_(sprintf) (from_gdb,   "%s-from-vgdb-to-%d",    name, pid);
-   VG_(sprintf) (to_gdb,     "%s-to-vgdb-from-%d",    name, pid);
-   VG_(sprintf) (shared_mem, "%s-shared-mem-vgdb-%d", name, pid);
+   VG_(sprintf) (from_gdb,   "%s-from-vgdb-to-%d-by-%s-on-%s",    name,
+                 pid, user, host);
+   VG_(sprintf) (to_gdb,     "%s-to-vgdb-from-%d-by-%s-on-%s",    name,
+                 pid, user, host);
+   VG_(sprintf) (shared_mem, "%s-shared-mem-vgdb-%d-by-%s-on-%s", name,
+                 pid, user, host);
    if (VG_(clo_verbosity) > 1) {
       VG_(umsg)("embedded gdbserver: reading from %s\n", from_gdb);
       VG_(umsg)("embedded gdbserver: writing to   %s\n", to_gdb);
index f0a66e1c494a4d12e6710e782a16376762700dcd..e250e93019a85e624f907c9d9bcd0bb8d00b5279 100644 (file)
@@ -1411,13 +1411,28 @@ Bool read_from_pid_write_to_gdb(int from_pid)
 static
 void prepare_fifos_and_shared_mem(int pid)
 {
-   from_gdb_to_pid = vmalloc (strlen(vgdb_prefix) + 30);
-   to_gdb_from_pid = vmalloc (strlen(vgdb_prefix) + 30);
-   shared_mem      = vmalloc (strlen(vgdb_prefix) + 30);
+   const HChar *user, *host;
+   unsigned len;
+
+   user = getenv("LOGNAME");
+   if (user == NULL) user = getenv("USER");
+   if (user == NULL) user = "???";
+
+   host = getenv("HOST");
+   if (host == NULL) host = getenv("HOSTNAME");
+   if (host == NULL) host = "???";
+
+   len = strlen(vgdb_prefix) + strlen(user) + strlen(host) + 40;
+   from_gdb_to_pid = vmalloc (len);
+   to_gdb_from_pid = vmalloc (len);
+   shared_mem      = vmalloc (len);
    /* below 3 lines must match the equivalent in remote-utils.c */
-   sprintf(from_gdb_to_pid, "%s-from-vgdb-to-%d",    vgdb_prefix, pid);
-   sprintf(to_gdb_from_pid, "%s-to-vgdb-from-%d",    vgdb_prefix, pid);
-   sprintf(shared_mem,      "%s-shared-mem-vgdb-%d", vgdb_prefix, pid);
+   sprintf(from_gdb_to_pid, "%s-from-vgdb-to-%d-by-%s-on-%s",    vgdb_prefix,
+           pid, user, host);
+   sprintf(to_gdb_from_pid, "%s-to-vgdb-from-%d-by-%s-on-%s",    vgdb_prefix,
+           pid, user, host);
+   sprintf(shared_mem,      "%s-shared-mem-vgdb-%d-by-%s-on-%s", vgdb_prefix,
+           pid, user, host);
    DEBUG (1, "vgdb: using %s %s %s\n", 
           from_gdb_to_pid, to_gdb_from_pid, shared_mem);
 
@@ -2109,7 +2124,7 @@ int search_arg_pid(int arg_pid, int check_trials, Bool show_list)
                             strlen (vgdb_format)) == 0) {
                   newpid = strtol(pathname + strlen (vgdb_format), 
                                   &wrongpid, 10);
-                  if (*wrongpid == '\0' && newpid > 0 
+                  if (*wrongpid == '-' && newpid > 0 
                       && kill (newpid, 0) == 0) {
                      nr_valid_pid++;
                      if (show_list) {