]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Fix assertion failure when using VG_(system) near program termination.
authorJeremy Fitzhardinge <jeremy@valgrind.org>
Tue, 2 Mar 2004 21:38:51 +0000 (21:38 +0000)
committerJeremy Fitzhardinge <jeremy@valgrind.org>
Tue, 2 Mar 2004 21:38:51 +0000 (21:38 +0000)
The problem is that the use of VG_(system) causes a SIGCHLD to be sent
to the process, which ends up being delivered to one of the proxy LWPs
(which is a small problem in itself, but nothing too bad).

The proxy tells the scheduler LWP about this, and the scheduler LWP sends
a sigACK reply.

Then, while the proxy LWP is in the SigACK state, and the SigACK reply
is still queued in the message pipe, the scheduler LWP starts shutting
Valgrind down, and sends a SIGVGKILL to all proxy LWPs.  This causes
the proxy to drop from sigACK state to WaitReq state, and it reads
further commands - one of which is the SigACK message - this causes the
assertion failure.

The fix is to simply make the proxy LWP exit immediately when it gets
a SIGVGKILL, and not process any more requests.

This change also fixes a bug in VG_(system), in which the child process
returns back into Valgrind rather than exiting when exec fails.

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

coregrind/vg_mylibc.c
coregrind/vg_proxylwp.c

index 130c29358e5746e8a186614a6a1d90f39712c8cf..2023aa58d402372600f534d0f85a0afb8afd5085 100644 (file)
@@ -1625,14 +1625,14 @@ Int VG_(system) ( Char* cmd )
                             (UInt)"/bin/sh", (UInt)argv, (UInt)envp);
 
       /* If we're still alive here, execve failed. */
-      return -1;
+      VG_(exit)(1);
    } else {
       /* parent */
-      res = VG_(do_syscall)(__NR_waitpid, pid, (UInt)NULL, 0);
+      res = VG_(waitpid)(pid, NULL, 0);
       if (VG_(is_kerror)(res)) {
          return -1;
       } else {
-       return 0;
+        return 0;
       }
    }
 }
index 55cd12a415131ca7bfa79f72030ff2866ac99067..4775b40a3ddb298a185ccbc78629cd33ffb14d5e 100644 (file)
@@ -519,11 +519,12 @@ static Int proxylwp(void *v)
            }
         } else {
            /* We got VKI_SIGVGKILL, which means we just skip all the
-              below and get back to the state machine - probably to
-              exit. */
+              below and exit.  (Don't bother dealing with any pending
+              requests, because we'll probably just get confused.) */
            px->state = PXS_WaitReq;
            px->siginfo.si_signo = 0;
-           goto state_machine;
+           ret = 0;
+           goto out;
         }
 
         px->siginfo.si_signo = 0;
@@ -628,7 +629,7 @@ static Int proxylwp(void *v)
            VG_(need_resched)(px->tid);
       }
 
-     state_machine:
+      /* state_machine: */
       px_printf("proxylwp main: state %s\n", pxs_name(px->state));
 
       switch(px->state) {