[Xfce4-commits] <parole:master> Kill the gst child process in case we failed to shut it down via D-Bus to avoid a zombie process.
Ali Abdallah
noreply at xfce.org
Sat Nov 21 14:34:03 CET 2009
Updating branch refs/heads/master
to b4082d0e84e1f47ca48d1ca03d5990a1aac7a48c (commit)
from 6b8227e356147a92c141cf9e5269fe79b5d68443 (commit)
commit b4082d0e84e1f47ca48d1ca03d5990a1aac7a48c
Author: Ali Abdallah <ali at ali-xfce.org>
Date: Fri Nov 20 16:32:29 2009 +0100
Kill the gst child process in case we failed to shut it down
via D-Bus to avoid a zombie process.
browser-plugin/plugin.cpp | 42 +++++++++++++++++++++++++++++++++++-------
browser-plugin/plugin.h | 4 +++-
2 files changed, 38 insertions(+), 8 deletions(-)
diff --git a/browser-plugin/plugin.cpp b/browser-plugin/plugin.cpp
index 6138a3e..dc81e0a 100644
--- a/browser-plugin/plugin.cpp
+++ b/browser-plugin/plugin.cpp
@@ -73,11 +73,21 @@ CPlugin::CPlugin (NPP pNPInstance)
mInstance = pNPInstance;
mInitialized = TRUE;
window_set = FALSE;
+ child_spawned = FALSE;
url = NULL;
bus = NULL;
proxy = NULL;
}
+void kill_child (GPid child_pid)
+{
+ gchar *command;
+
+ command = g_strdup_printf ("kill -9 %d", child_pid);
+ g_spawn_command_line_async (command, NULL);
+ g_free (command);
+}
+
CPlugin::~CPlugin()
{
g_debug ("Destructor");
@@ -87,10 +97,28 @@ CPlugin::~CPlugin()
if ( proxy )
{
- dbus_g_proxy_call_no_reply (proxy, "Quit",
- G_TYPE_INVALID,
- G_TYPE_INVALID);
+ GError *error = NULL;
+
+ dbus_g_proxy_call (proxy, "Quit", &error,
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
+
+ /*
+ * This might happen if the browser unload the plugin quickly
+ * while the process didn't get the dbus name.
+ */
+ if ( error )
+ {
+#ifdef DEBUG
+ g_debug ("Failed to stop the backend via D-Bus killing the process %d", child_pid);
+#endif
+ kill_child (child_pid);
+ }
}
+ else if ( child_spawned )
+ {
+ kill_child (child_pid);
+ }
if ( bus )
dbus_g_connection_unref (bus);
@@ -137,8 +165,8 @@ void CPlugin::shut()
if ( proxy )
{
dbus_g_proxy_call_no_reply (proxy, "Terminate",
- G_TYPE_INVALID,
- G_TYPE_INVALID);
+ G_TYPE_INVALID,
+ G_TYPE_INVALID);
}
}
@@ -197,14 +225,14 @@ NPError CPlugin::NewStream(NPMIMEType type, NPStream * stream, NPBool seekable,
NULL,
(GSpawnFlags) 0,
NULL, NULL,
- NULL,
+ &child_pid,
&error) )
{
g_critical ("Failed to spawn command : %s", error->message);
g_error_free (error);
return NPERR_GENERIC_ERROR;
}
-
+ child_spawned = TRUE;
g_free (socket);
g_free (app);
diff --git a/browser-plugin/plugin.h b/browser-plugin/plugin.h
index 29234cc..4bc10fa 100644
--- a/browser-plugin/plugin.h
+++ b/browser-plugin/plugin.h
@@ -82,9 +82,11 @@ class CPlugin {
DBusGProxy *proxy;
gboolean window_set;
+ gboolean child_spawned;
gchar *url;
Window window;
-
+ GPid child_pid;
+
public:
NPP mInstance;
uint16 mode;
More information about the Xfce4-commits
mailing list