Browse Source

fix extra kill message

David Rose 16 years ago
parent
commit
f28a01b52b
2 changed files with 29 additions and 2 deletions
  1. 22 2
      direct/src/plugin/p3dAuthSession.cxx
  2. 7 0
      direct/src/plugin/p3dSession.cxx

+ 22 - 2
direct/src/plugin/p3dAuthSession.cxx

@@ -40,6 +40,11 @@ P3DAuthSession(P3DInstance *inst) :
 {
 {
   P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
   P3DInstanceManager *inst_mgr = P3DInstanceManager::get_global_ptr();
 
 
+#ifdef _WIN32
+  _p3dcert_handle = INVALID_HANDLE_VALUE;
+#else
+  _p3dcert_pid = -1;
+#endif
   _p3dcert_started = false;
   _p3dcert_started = false;
   _p3dcert_running = false;
   _p3dcert_running = false;
   _started_wait_thread = false;
   _started_wait_thread = false;
@@ -104,7 +109,7 @@ shutdown(bool send_message) {
     _inst = NULL;
     _inst = NULL;
   }
   }
 
 
-  if (_p3dcert_started) {
+  if (_p3dcert_running) {
     nout << "Killing p3dcert process\n";
     nout << "Killing p3dcert process\n";
 #ifdef _WIN32
 #ifdef _WIN32
     TerminateProcess(_p3dcert_handle, 2);
     TerminateProcess(_p3dcert_handle, 2);
@@ -112,11 +117,21 @@ shutdown(bool send_message) {
 
 
 #else  // _WIN32
 #else  // _WIN32
     kill(_p3dcert_pid, SIGKILL);
     kill(_p3dcert_pid, SIGKILL);
+
+    // Wait a few milliseconds for the process to exit, and then get
+    // its return status to clean up the zombie status.  If we don't
+    // wait long enough, don't sweat it.
+    struct timeval tv;
+    tv.tv_sec = 0;
+    tv.tv_usec = 100000;
+    select(0, NULL, NULL, NULL, &tv);
+    int status;
+    waitpid(_p3dcert_pid, &status, WNOHANG);
 #endif  // _WIN32
 #endif  // _WIN32
     
     
     _p3dcert_running = false;
     _p3dcert_running = false;
-    _p3dcert_started = false;
   }
   }
+  _p3dcert_started = false;
 
 
   // Now that the process has stopped, the thread should stop itself
   // Now that the process has stopped, the thread should stop itself
   // quickly too.
   // quickly too.
@@ -266,6 +281,9 @@ wt_thread_run() {
   if (result != 0) {
   if (result != 0) {
     nout << "Wait for process failed: " << GetLastError() << "\n";
     nout << "Wait for process failed: " << GetLastError() << "\n";
   }
   }
+  CloseHandle(_p3dcert_handle);
+  _p3dcert_handle = INVALID_HANDLE_VALUE;
+  _p3dcert_running = false;
   nout << "p3dcert process has successfully stopped.\n";
   nout << "p3dcert process has successfully stopped.\n";
 #else
 #else
   int status;
   int status;
@@ -273,6 +291,8 @@ wt_thread_run() {
   if (result == -1) {
   if (result == -1) {
     perror("waitpid");
     perror("waitpid");
   }
   }
+  _p3dcert_pid = -1;
+  _p3dcert_running = false;
       
       
   nout << "p3dcert process has successfully stopped.\n";
   nout << "p3dcert process has successfully stopped.\n";
   if (WIFEXITED(status)) {
   if (WIFEXITED(status)) {

+ 7 - 0
direct/src/plugin/p3dSession.cxx

@@ -60,6 +60,11 @@ P3DSession(P3DInstance *inst) {
   _keep_user_env = false;
   _keep_user_env = false;
   _failed = false;
   _failed = false;
 
 
+#ifdef _WIN32
+  _p3dpython_handle = INVALID_HANDLE_VALUE;
+#else
+  _p3dpython_pid = -1;
+#endif
   _p3dpython_one_process = false;
   _p3dpython_one_process = false;
   _p3dpython_started = false;
   _p3dpython_started = false;
   _p3dpython_running = false;
   _p3dpython_running = false;
@@ -132,6 +137,7 @@ shutdown() {
       }
       }
       
       
       CloseHandle(_p3dpython_handle);
       CloseHandle(_p3dpython_handle);
+      _p3dpython_handle = INVALID_HANDLE_VALUE;
 
 
 #else  // _WIN32
 #else  // _WIN32
       // Wait for a certain amount of time for the process to stop by
       // Wait for a certain amount of time for the process to stop by
@@ -168,6 +174,7 @@ shutdown() {
         select(0, NULL, NULL, NULL, &tv);
         select(0, NULL, NULL, NULL, &tv);
         result = waitpid(_p3dpython_pid, &status, WNOHANG);
         result = waitpid(_p3dpython_pid, &status, WNOHANG);
       }
       }
+      _p3dpython_pid = -1;
       
       
       nout << "Python process has successfully stopped.\n";
       nout << "Python process has successfully stopped.\n";
       if (WIFEXITED(status)) {
       if (WIFEXITED(status)) {