This is the mail archive of the gdb-patches@sources.redhat.com mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

[PATCH RFA] Retry open of /proc/PID/ctl in procfs.c


I request approval for committing the patch below.  The comments in the
patch explain why this patch is needed.  (It definitely cures some
intermittent problems that I'm seeing on AIX5.)

Tested on i586-sco-sysv5uw7.1.1 and i386-pc-solaris2.8.  No regressions.

	* procfs.c (procfs_init_inferior): Add code for retrying the
	open of the /proc control file for the newly created process.

Index: procfs.c
===================================================================
RCS file: /cvs/src/src/gdb/procfs.c,v
retrieving revision 1.26
diff -u -p -r1.26 procfs.c
--- procfs.c	2001/03/27 02:01:11	1.26
+++ procfs.c	2001/04/13 07:57:26
@@ -4773,6 +4773,7 @@ procfs_init_inferior (int pid)
   procinfo *pi;
   gdb_sigset_t signals;
   int fail;
+  int retry_count;
 
   /* This routine called on the parent side (GDB side)
      after GDB forks the inferior.  */
@@ -4782,8 +4783,25 @@ procfs_init_inferior (int pid)
   if ((pi = create_procinfo (pid, 0)) == NULL)
     perror ("procfs: out of memory in 'init_inferior'");
 
-  if (!open_procinfo_files (pi, FD_CTL))
-    proc_error (pi, "init_inferior, open_proc_files", __LINE__);
+  /* Open the /proc control (ctl) file, but be prepared to retry
+     this open in the event that it hasn't been created yet.  */
+  retry_count = 3;
+  while (!open_procinfo_files (pi, FD_CTL))
+    {
+      if (retry_count == 0)
+	{
+	  /* Retry count exceeded; print error and return to top level.  */
+	  proc_error (pi, "init_inferior, open_proc_files", __LINE__);
+	}
+      else
+	{
+	  /* In some /proc implementations, GDB tries to open /proc/PID/ctl
+	     before the kernel has created it.  Sleep for a bit to give
+	     the kernel a chance to catch up.  */
+	  sleep (1);
+	  retry_count--;
+	}
+    }
 
   /*
     xmalloc			// done


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]