Fix 338698  race condition between gdbsrv and vgdb on startup



git-svn-id: svn://svn.valgrind.org/valgrind/trunk@14475 a5019735-40e9-0310-863c-91ae7b9d1cf9
diff --git a/NEWS b/NEWS
index 24f79ab..e16456a 100644
--- a/NEWS
+++ b/NEWS
@@ -309,6 +309,7 @@
 338499  --sim-hints parsing broken due to wrong order in tokens
 338615  suppress glibc 2.20 optimized strcmp implementation for ARMv7
 338681  Unable to unwind through clone thread created on i386-linux
+338698  race condition between gdbsrv and vgdb on startup
 338703  helgrind on arm-linux gets false positives in dynamic loader
 n-i-bz  Fix KVM_CREATE_IRQCHIP ioctl handling
 n-i-bz  s390x: Fix memory corruption for multithreaded applications
diff --git a/coregrind/m_gdbserver/remote-utils.c b/coregrind/m_gdbserver/remote-utils.c
index 6ee1f7e..aa2cd4a 100644
--- a/coregrind/m_gdbserver/remote-utils.c
+++ b/coregrind/m_gdbserver/remote-utils.c
@@ -390,11 +390,6 @@
       VG_(unlink)(to_gdb);
       VG_(unlink)(shared_mem);
 
-      safe_mknod(from_gdb);
-      safe_mknod(to_gdb);
-
-      pid_from_to_creator = pid;
-      
       o = VG_(open) (shared_mem, VKI_O_CREAT|VKI_O_RDWR, 0600);
       if (sr_isError (o)) {
          sr_perror(o, "cannot create shared_mem file %s\n", shared_mem);
@@ -421,6 +416,15 @@
       }
       shared = (VgdbShared*) addr_shared;
       VG_(close) (shared_mem_fd);
+
+      safe_mknod(to_gdb);
+      safe_mknod(from_gdb);
+      /* from_gdb is the last resource created: vgdb searches such FIFOs
+         to detect the presence of a valgrind process.
+         So, we better create this resource when all the rest needed by
+         vgdb is ready : the other FIFO and the shared memory. */
+
+      pid_from_to_creator = pid;
    }
    
    setup_remote_desc_for_reading ();