← Back to team overview

maria-developers team mailing list archive

[Branch ~maria-captains/maria/5.1] Rev 2844: Fixed race condition in safe_process.cc which may have caused some mysqltests to be reported as f...

 

------------------------------------------------------------
revno: 2844
committer: Michael Widenius <monty@xxxxxxxxxxxx>
branch nick: maria-5.1
timestamp: Thu 2010-04-08 14:56:57 +0300
message:
  Fixed race condition in safe_process.cc which may have caused some mysqltests to be reported as failed even if they succeded.
modified:
  mysql-test/lib/My/SafeProcess/safe_process.cc


--
lp:maria
https://code.launchpad.net/~maria-captains/maria/5.1

Your team Maria developers is subscribed to branch lp:maria.
To unsubscribe from this branch go to https://code.launchpad.net/~maria-captains/maria/5.1/+edit-subscription
=== modified file 'mysql-test/lib/My/SafeProcess/safe_process.cc'
--- mysql-test/lib/My/SafeProcess/safe_process.cc	2010-03-28 18:10:00 +0000
+++ mysql-test/lib/My/SafeProcess/safe_process.cc	2010-04-08 11:56:57 +0000
@@ -85,17 +85,18 @@
   va_end(args);
   if (int last_err= errno)
     fprintf(stderr, "error: %d, %s\n", last_err, strerror(last_err));
-  exit(1);
+  exit(6);
 }
 
 
-static void kill_child(void)
+static void kill_child(bool was_killed)
 {
   int status= 0;
 
   message("Killing child: %d", child_pid);
   // Terminate whole process group
-  kill(-child_pid, SIGKILL);
+  if (! was_killed)
+    kill(-child_pid, SIGKILL);
 
   pid_t ret_pid= waitpid(child_pid, &status, 0);
   if (ret_pid == child_pid)
@@ -115,7 +116,7 @@
 
     exit(exit_code);
   }
-  exit(1);
+  exit(5);
 }
 
 
@@ -135,7 +136,7 @@
   terminated= 1;
 
   if (child_pid > 0)
-    kill_child();
+    kill_child(sig == SIGCHLD);
 
   // Ignore further signals
   signal(SIGTERM, SIG_IGN);
@@ -240,8 +241,8 @@
     // Close write end
     close(pfd[1]);
 
-    if (execvp(child_argv[0], child_argv) < 0)
-      die("Failed to exec child");
+    execvp(child_argv[0], child_argv);
+    die("Failed to exec child");
   }
 
   close(pfd[1]); // Close unused write end
@@ -257,39 +258,19 @@
   /* Monitor loop */
   message("Started child %d, terminated: %d", child_pid, terminated);
 
-  while(!terminated)
+  while (!terminated)
   {
     // Check if parent is still alive
-    if (kill(parent_pid, 0) != 0){
+    if (kill(parent_pid, 0) != 0)
+    {
       message("Parent is not alive anymore");
       break;
     }
-
-    // Check if child has exited, normally this will be
-    // detected immediately with SIGCHLD handler
-    int status= 0;
-    pid_t ret_pid= waitpid(child_pid, &status, WNOHANG);
-    if (ret_pid == child_pid)
-    {
-      int ret_code= 2;
-      if (WIFEXITED(status))
-      {
-        // Process has exited, collect return status
-        ret_code= WEXITSTATUS(status);
-        message("Child exit: %d", ret_code);
-        // Exit with exit status of the child
-        exit(ret_code);
-      }
-
-      if (WIFSIGNALED(status))
-        message("Child killed by signal: %d", WTERMSIG(status));
-
-      exit(ret_code);
-    }
+    /* Wait for parent or child to die */
     sleep(1);
   }
-  kill_child();
+  kill_child(0);
 
-  return 1;
+  return 4;
 }