olga / rpms / glibc

Forked from rpms/glibc 5 years ago
Clone

Blame SOURCES/glibc-rh1609067.patch

00db10
commit b04acb2651e0aaf615de50e9138cddfd5c24021f
00db10
Author: Andreas Schwab <schwab@suse.de>
00db10
Date:   Tue Jul 30 11:58:45 2013 +0200
00db10
00db10
    Fix race conditions in pldd that may leave the process stopped after detaching
00db10
    
00db10
    Fixes bug 15804
00db10
00db10
diff --git a/elf/pldd.c b/elf/pldd.c
00db10
index 684aff4..75f7812 100644
00db10
--- a/elf/pldd.c
00db10
+++ b/elf/pldd.c
00db10
@@ -34,6 +34,7 @@
00db10
 #include <unistd.h>
00db10
 #include <sys/ptrace.h>
00db10
 #include <sys/stat.h>
00db10
+#include <sys/wait.h>
00db10
 
00db10
 #include <ldsodefs.h>
00db10
 #include <version.h>
00db10
@@ -82,6 +83,7 @@ static char *exe;
00db10
 
00db10
 /* Local functions.  */
00db10
 static int get_process_info (int dfd, long int pid);
00db10
+static void wait_for_ptrace_stop (long int pid);
00db10
 
00db10
 
00db10
 int
00db10
@@ -170,6 +172,8 @@ main (int argc, char *argv[])
00db10
 		 tid);
00db10
 	}
00db10
 
00db10
+      wait_for_ptrace_stop (tid);
00db10
+
00db10
       struct thread_list *newp = alloca (sizeof (*newp));
00db10
       newp->tid = tid;
00db10
       newp->next = thread_list;
00db10
@@ -194,6 +198,27 @@ main (int argc, char *argv[])
00db10
 }
00db10
 
00db10
 
00db10
+/* Wait for PID to enter ptrace-stop state after being attached.  */
00db10
+static void
00db10
+wait_for_ptrace_stop (long int pid)
00db10
+{
00db10
+  int status;
00db10
+
00db10
+  /* While waiting for SIGSTOP being delivered to the tracee we have to
00db10
+     reinject any other pending signal.  Ignore all other errors.  */
00db10
+  while (waitpid (pid, &status, __WALL) == pid && WIFSTOPPED (status))
00db10
+    {
00db10
+      /* The STOP signal should not be delivered to the tracee.  */
00db10
+      if (WSTOPSIG (status) == SIGSTOP)
00db10
+	return;
00db10
+      if (ptrace (PTRACE_CONT, pid, NULL,
00db10
+		  (void *) (uintptr_t) WSTOPSIG (status)))
00db10
+	/* The only possible error is that the process died.  */
00db10
+	return;
00db10
+    }
00db10
+}
00db10
+
00db10
+
00db10
 /* Handle program arguments.  */
00db10
 static error_t
00db10
 parse_opt (int key, char *arg, struct argp_state *state)