[Xfce4-commits] <xfce4-panel:devel> Fix auto restart code for external plugins.

Nick Schermer noreply at xfce.org
Mon Jan 25 15:22:02 CET 2010


Updating branch refs/heads/devel
         to e7630d29809f002c4fa883cb8fd814d8db4b9c36 (commit)
       from 8a91fe62a85593342fb5d0aa5a1011d2e0e99b22 (commit)

commit e7630d29809f002c4fa883cb8fd814d8db4b9c36
Author: Nick Schermer <nick at xfce.org>
Date:   Mon Jan 25 13:38:48 2010 +0100

    Fix auto restart code for external plugins.

 panel/panel-dialogs.c            |    7 +++--
 panel/panel-plugin-external-46.c |   45 +++++++++++++++++++++----------------
 panel/panel-plugin-external.c    |   43 +++++++++++++++++++----------------
 wrapper/main.c                   |    6 ++--
 4 files changed, 55 insertions(+), 46 deletions(-)

diff --git a/panel/panel-dialogs.c b/panel/panel-dialogs.c
index 35f67db..3de1cd0 100644
--- a/panel/panel-dialogs.c
+++ b/panel/panel-dialogs.c
@@ -161,9 +161,10 @@ panel_dialogs_restart_plugin (GtkWindow   *parent,
                                    GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
                                    _("Plugin \"%s\" unexpectedly left the panel, do you want to restart it?"),
                                    plugin_name);
-  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("If you press Execute "
-                                            "the panel will try to restart the plugin otherwise it "
-                                            "will be permanently removed from the panel."));
+  gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), _("The plugin restarted more then once in "
+                                            "the last %d seconds. If you press Execute  the panel will try to restart "
+                                            "the plugin otherwise it will be permanently removed from the panel."),
+                                            PANEL_PLUGIN_AUTO_RESTART);
   gtk_dialog_add_buttons (GTK_DIALOG (dialog), GTK_STOCK_EXECUTE, GTK_RESPONSE_OK,
                           GTK_STOCK_REMOVE, GTK_RESPONSE_CLOSE, NULL);
   gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
diff --git a/panel/panel-plugin-external-46.c b/panel/panel-plugin-external-46.c
index 99cf462..1d39517 100644
--- a/panel/panel-plugin-external-46.c
+++ b/panel/panel-plugin-external-46.c
@@ -469,13 +469,10 @@ panel_plugin_external_46_plug_removed (GtkSocket *socket)
   window = gtk_widget_get_toplevel (GTK_WIDGET (socket));
   panel_return_val_if_fail (PANEL_IS_WINDOW (window), FALSE);
 
-  /* create a restart timer if we don't have any */
-  if (external->restart_timer == NULL)
-    external->restart_timer = g_timer_new ();
-
-  if (g_timer_elapsed (external->restart_timer, NULL) > PANEL_PLUGIN_AUTO_RESTART)
+  if (external->restart_timer == NULL
+      || g_timer_elapsed (external->restart_timer, NULL) > PANEL_PLUGIN_AUTO_RESTART)
     {
-      g_message ("Plugin %s-%d: auto restart after crash.",
+      g_message ("Plugin %s-%d has been automatically restarted after crash.",
                  panel_module_get_name (external->module),
                  external->unique_id);
     }
@@ -492,8 +489,11 @@ panel_plugin_external_46_plug_removed (GtkSocket *socket)
       return FALSE;
     }
 
-  /* reset the restart counter, user agreed to restart again */
-  g_timer_reset (external->restart_timer);
+  /* create or reset the retart timer */
+  if (external->restart_timer == NULL)
+    external->restart_timer = g_timer_new ();
+  else
+    g_timer_reset (external->restart_timer);
 
   /* send panel information to the plugin (queued until realize) */
   panel_window_set_povider_info (PANEL_WINDOW (window), GTK_WIDGET (external));
@@ -762,25 +762,30 @@ panel_plugin_external_46_set_sensitive (PanelPluginExternal46 *external)
 
 static void
 panel_plugin_external_46_child_watch (GPid     pid,
-                                   gint     status,
-                                   gpointer user_data)
+                                      gint     status,
+                                      gpointer user_data)
 {
   PanelPluginExternal46 *external = PANEL_PLUGIN_EXTERNAL_46 (user_data);
 
   panel_return_if_fail (PANEL_IS_PLUGIN_EXTERNAL_46 (external));
   panel_return_if_fail (external->pid == pid);
 
-  switch (WEXITSTATUS (status))
+  /* only handle our exit status if the plugin exited normally */
+  if (WIFEXITED (status))
     {
-      case PLUGIN_EXIT_SUCCESS:
-      case PLUGIN_EXIT_FAILURE:
-      case PLUGIN_EXIT_PREINIT_FAILED:
-      case PLUGIN_EXIT_CHECK_FAILED:
-      case PLUGIN_EXIT_NO_PROVIDER:
-        /* wait until everything is settled, then destroy the
-         * external plugin so it is removed from the configuration */
-        exo_gtk_object_destroy_later (GTK_OBJECT (external));
-        break;
+      /* extract our return value from the status */
+      switch (WEXITSTATUS (status))
+        {
+          case PLUGIN_EXIT_SUCCESS:
+          case PLUGIN_EXIT_FAILURE:
+          case PLUGIN_EXIT_PREINIT_FAILED:
+          case PLUGIN_EXIT_CHECK_FAILED:
+          case PLUGIN_EXIT_NO_PROVIDER:
+            /* wait until everything is settled, then destroy the
+             * external plugin so it is removed from the configuration */
+            exo_gtk_object_destroy_later (GTK_OBJECT (external));
+            break;
+        }
     }
 
   g_spawn_close_pid (pid);
diff --git a/panel/panel-plugin-external.c b/panel/panel-plugin-external.c
index 390221b..2f35a08 100644
--- a/panel/panel-plugin-external.c
+++ b/panel/panel-plugin-external.c
@@ -464,8 +464,6 @@ panel_plugin_external_plug_removed (GtkSocket *socket)
   PanelPluginExternal *external = PANEL_PLUGIN_EXTERNAL (socket);
   GtkWidget           *window;
 
-  panel_return_val_if_fail (PANEL_IS_MODULE (external->module), FALSE);
-
   /* leave when the plugin was already removed */
   if (!external->plug_embedded)
     return FALSE;
@@ -487,13 +485,10 @@ panel_plugin_external_plug_removed (GtkSocket *socket)
   window = gtk_widget_get_toplevel (GTK_WIDGET (socket));
   panel_return_val_if_fail (PANEL_IS_WINDOW (window), FALSE);
 
-  /* create a restart timer if we don't have any */
-  if (external->restart_timer == NULL)
-    external->restart_timer = g_timer_new ();
-
-  if (g_timer_elapsed (external->restart_timer, NULL) > PANEL_PLUGIN_AUTO_RESTART)
+  if (external->restart_timer == NULL
+      || g_timer_elapsed (external->restart_timer, NULL) > PANEL_PLUGIN_AUTO_RESTART)
     {
-      g_message ("Plugin %s-%d: auto restart after crash.",
+      g_message ("Plugin %s-%d has been automatically restarted after crash.",
                  panel_module_get_name (external->module),
                  external->unique_id);
     }
@@ -510,8 +505,11 @@ panel_plugin_external_plug_removed (GtkSocket *socket)
       return FALSE;
     }
 
-  /* reset the restart counter, user agreed to restart again */
-  g_timer_reset (external->restart_timer);
+  /* create or reset the retart timer */
+  if (external->restart_timer == NULL)
+    external->restart_timer = g_timer_new ();
+  else
+    g_timer_reset (external->restart_timer);
 
   /* send panel information to the plugin (queued until realize) */
   panel_window_set_povider_info (PANEL_WINDOW (window), GTK_WIDGET (external));
@@ -875,17 +873,22 @@ panel_plugin_external_child_watch (GPid     pid,
   panel_return_if_fail (PANEL_IS_PLUGIN_EXTERNAL (external));
   panel_return_if_fail (external->pid == pid);
 
-  switch (WEXITSTATUS (status))
+  /* only handle our exit status if the plugin exited normally */
+  if (WIFEXITED (status))
     {
-      case PLUGIN_EXIT_SUCCESS:
-      case PLUGIN_EXIT_FAILURE:
-      case PLUGIN_EXIT_PREINIT_FAILED:
-      case PLUGIN_EXIT_CHECK_FAILED:
-      case PLUGIN_EXIT_NO_PROVIDER:
-        /* wait until everything is settled, then destroy the
-         * external plugin so it is removed from the configuration */
-        exo_gtk_object_destroy_later (GTK_OBJECT (external));
-        break;
+      /* extract our return value from the status */
+      switch (WEXITSTATUS (status))
+        {
+          case PLUGIN_EXIT_SUCCESS:
+          case PLUGIN_EXIT_FAILURE:
+          case PLUGIN_EXIT_PREINIT_FAILED:
+          case PLUGIN_EXIT_CHECK_FAILED:
+          case PLUGIN_EXIT_NO_PROVIDER:
+            /* wait until everything is settled, then destroy the
+             * external plugin so it is removed from the configuration */
+            exo_gtk_object_destroy_later (GTK_OBJECT (external));
+            break;
+        }
     }
 
   g_spawn_close_pid (pid);
diff --git a/wrapper/main.c b/wrapper/main.c
index 533ff03..bce41f2 100644
--- a/wrapper/main.c
+++ b/wrapper/main.c
@@ -302,9 +302,6 @@ main (gint argc, gchar **argv)
       /* show the plugin */
       gtk_widget_show (GTK_WIDGET (provider));
 
-      /* everything when fine */
-      retval = PLUGIN_EXIT_SUCCESS;
-
       /* enter the main loop */
       gtk_main ();
 
@@ -316,6 +313,9 @@ main (gint argc, gchar **argv)
       /* destroy the plug and provider */
       if (plug != NULL)
         gtk_widget_destroy (GTK_WIDGET (plug));
+
+      /* everything when fine */
+      retval = PLUGIN_EXIT_SUCCESS;
     }
   else
     {



More information about the Xfce4-commits mailing list