gnash-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Gnash-commit] /srv/bzr/gnash/trunk r12115: Give the child process one s


From: Bastiaan Jacques
Subject: [Gnash-commit] /srv/bzr/gnash/trunk r12115: Give the child process one second to go away by itself, without
Date: Fri, 26 Mar 2010 06:49:11 +0100
User-agent: Bazaar (2.0.3)

------------------------------------------------------------
revno: 12115
committer: Bastiaan Jacques <address@hidden>
branch nick: trunk
timestamp: Fri 2010-03-26 06:49:11 +0100
message:
  Give the child process one second to go away by itself, without
  blocking the main thread. Apparently DestroyStream is not guaranteed
  to be called before the plugin instance is closed, so force the file
  descriptor closed when that happens.
modified:
  plugin/npapi/plugin.cpp
=== modified file 'plugin/npapi/plugin.cpp'
--- a/plugin/npapi/plugin.cpp   2010-03-26 04:03:47 +0000
+++ b/plugin/npapi/plugin.cpp   2010-03-26 05:49:11 +0000
@@ -351,6 +351,31 @@
 
 }
 
+gboolean
+cleanup_childpid(gpointer data)
+{
+    int* pid = static_cast<int*>(data);
+
+    int status;
+    int rv = waitpid(*pid, &status, WNOHANG);
+
+    if (rv <= 0) {
+        // The child process has not exited; it may be deadlocked. Kill it.
+        logError("BUG: Child process is stuck. Killing it.");
+
+        kill(*pid, SIGKILL);
+        waitpid(*pid, &status, 0);
+    }
+ 
+#if GNASH_PLUGIN_DEBUG > 1
+        std::cout << "Child process exited with status "  << status << 
std::endl;
+#endif
+
+    delete pid;
+
+    return FALSE;
+}
+
 /// \brief Destructor
 nsPluginInstance::~nsPluginInstance()
 {
@@ -370,23 +395,14 @@
         int rv = waitpid(_childpid, &status, WNOHANG);
 
         if (rv <= 0) {
-            // The childprocess has not exited; it may be deadlocked.
-            // We'll first try a gentle approach... which probably won't work.
-            logError("Child process ignored fd closure; trying SIGTERM. 
(bug)");
-            kill(_childpid, SIGTERM);
-            rv = waitpid(_childpid, &status, WNOHANG);
-
-            if (rv <= 0) {
-                // That still didn't work. Try to force-kill the process...
-                logError("Child process ignored SIGTERM. Trying SIGKILL. 
(BUG)");
-                kill(_childpid, SIGKILL);
-                waitpid(_childpid, &status, 0);
-            }
-        }
+            int* pid = new int(_childpid);
+            g_timeout_add_seconds (1, cleanup_childpid, pid);
+        } else {
 
 #if GNASH_PLUGIN_DEBUG > 1
         std::cout << "Child process exited with status "  << status << 
std::endl;
 #endif
+        }
     }
     _childpid = 0;
 }
@@ -426,6 +442,14 @@
 {
     logDebug("Gnash plugin shutting down");
 
+    if (_streamfd != -1) {
+        if (close(_streamfd) == -1) {
+            perror("closing _streamfd");
+        } else {
+            _streamfd = -1;
+        }
+    }
+
     int ret = close(_controlfd);
     if (ret != 0) {
         logDebug("Gnash plugin failed to close the control socket!");


reply via email to

[Prev in Thread] Current Thread [Next in Thread]