[Xfce4-commits] <tumbler:master> Simplify the race fix. Failed name ownership implies already running.

Jannis Pohlmann noreply at xfce.org
Wed Sep 28 23:34:01 CEST 2011


Updating branch refs/heads/master
         to 72525b63d3fb581e1077c10e4b7be61a171ffd01 (commit)
       from 776070012e3d5d2bff5a1b2a9e175ced7122f125 (commit)

commit 72525b63d3fb581e1077c10e4b7be61a171ffd01
Author: Jannis Pohlmann <jannis at xfce.org>
Date:   Wed Sep 28 23:30:56 2011 +0200

    Simplify the race fix. Failed name ownership implies already running.
    
    The only other results dbus_bus_request_name() returns are either not
    possible or imply that the service is already provided by another
    instance, so we don't have to treat DBUS_REQUEST_NAME_REPLY_EXISTS
    special.

 tumblerd/main.c                  |   28 ++++++----------------------
 tumblerd/tumbler-cache-service.c |   28 ++--------------------------
 tumblerd/tumbler-manager.c       |   28 ++--------------------------
 tumblerd/tumbler-service.c       |   27 ++-------------------------
 4 files changed, 12 insertions(+), 99 deletions(-)

diff --git a/tumblerd/main.c b/tumblerd/main.c
index f79049b..d8e9876 100644
--- a/tumblerd/main.c
+++ b/tumblerd/main.c
@@ -65,7 +65,6 @@ main (int    argc,
   TumblerService          *service;
   TumblerCacheService     *cache_service;
   GMainLoop               *main_loop;
-  gboolean                 already_running = FALSE;
   GError                  *error = NULL;
   GList                   *providers;
   GList                   *thumbnailers;
@@ -166,9 +165,6 @@ main (int    argc,
   /* try to start the service and exit if that fails */
   if (!tumbler_cache_service_start (cache_service, &error))
     {
-      if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_ADDRESS_IN_USE)
-        already_running = TRUE;
-
       g_warning (_("Failed to start the thumbnail cache service: %s"), error->message);
       g_error_free (error);
 
@@ -179,18 +175,13 @@ main (int    argc,
 
       dbus_g_connection_unref (connection);
 
-      if (already_running)
-        return EXIT_SUCCESS;
-      else
-        return EXIT_FAILURE;
+      /* service already running, exit gracefully to not break clients */
+      return EXIT_SUCCESS;
     }
 
   /* try to start the service and exit if that fails */
   if (!tumbler_manager_start (manager, &error))
     {
-      if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_ADDRESS_IN_USE)
-        already_running = TRUE;
-
       g_warning (_("Failed to start the thumbnailer manager: %s"), error->message);
       g_error_free (error);
 
@@ -201,18 +192,13 @@ main (int    argc,
 
       dbus_g_connection_unref (connection);
 
-      if (already_running)
-        return EXIT_SUCCESS;
-      else
-        return EXIT_FAILURE;
+      /* service already running, exit gracefully to not break clients */
+      return EXIT_SUCCESS;
     }
 
   /* try to start the service and exit if that fails */
   if (!tumbler_service_start (service, &error))
     {
-      if (error->domain == DBUS_GERROR && error->code == DBUS_GERROR_ADDRESS_IN_USE)
-        already_running = TRUE;
-
       g_warning (_("Failed to start the thumbnailer service: %s"), error->message);
       g_error_free (error);
 
@@ -223,10 +209,8 @@ main (int    argc,
 
       dbus_g_connection_unref (connection);
 
-      if (already_running)
-        return EXIT_SUCCESS;
-      else
-        return EXIT_FAILURE;
+      /* service already running, exit gracefully to not break clients */
+      return EXIT_SUCCESS;
     }
 
   /* create a new main loop */
diff --git a/tumblerd/tumbler-cache-service.c b/tumblerd/tumbler-cache-service.c
index f6b2dc5..d9ecfe6 100644
--- a/tumblerd/tumbler-cache-service.c
+++ b/tumblerd/tumbler-cache-service.c
@@ -390,7 +390,6 @@ tumbler_cache_service_start (TumblerCacheService *service,
                              GError             **error)
 {
   DBusConnection *connection;
-  DBusError       dbus_error;
   gint            result;
 
   g_return_val_if_fail (TUMBLER_IS_CACHE_SERVICE (service), FALSE);
@@ -398,41 +397,18 @@ tumbler_cache_service_start (TumblerCacheService *service,
 
   g_mutex_lock (service->mutex);
 
-  /* initialize the D-Bus error */
-  dbus_error_init (&dbus_error);
-
   /* get the native D-Bus connection */
   connection = dbus_g_connection_get_connection (service->connection);
 
   /* request ownership for the cache interface */
   result = dbus_bus_request_name (connection, "org.freedesktop.thumbnails.Cache1", 
-                                  DBUS_NAME_FLAG_DO_NOT_QUEUE, &dbus_error);
+                                  DBUS_NAME_FLAG_DO_NOT_QUEUE, NULL);
 
   /* check if that failed */
-  if (result == DBUS_REQUEST_NAME_REPLY_EXISTS)
+  if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
     {
       if (error != NULL)
         {
-          g_set_error (error, DBUS_GERROR, DBUS_GERROR_ADDRESS_IN_USE,
-                       _("Another thumbnail cache service is already running"));
-        }
-
-      g_mutex_unlock (service->mutex);
-
-      return FALSE;
-    }
-  else if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
-    {
-      /* propagate the D-Bus error */
-      if (dbus_error_is_set (&dbus_error))
-        {
-          if (error != NULL)
-            dbus_set_g_error (error, &dbus_error);
-
-          dbus_error_free (&dbus_error);
-        }
-      else if (error != NULL)
-        {
           g_set_error (error, DBUS_GERROR, DBUS_GERROR_FAILED,
                        _("Another thumbnail cache service is already running"));
         }
diff --git a/tumblerd/tumbler-manager.c b/tumblerd/tumbler-manager.c
index feb2943..cb8af5c 100644
--- a/tumblerd/tumbler-manager.c
+++ b/tumblerd/tumbler-manager.c
@@ -1840,7 +1840,6 @@ tumbler_manager_start (TumblerManager *manager,
                        GError        **error)
 {
   DBusConnection *connection;
-  DBusError       dbus_error;
   gint            result;
 
   g_return_val_if_fail (TUMBLER_IS_MANAGER (manager), FALSE);
@@ -1848,41 +1847,18 @@ tumbler_manager_start (TumblerManager *manager,
 
   g_mutex_lock (manager->mutex);
 
-  /* initialize the D-Bus error */
-  dbus_error_init (&dbus_error);
-
   /* get the native D-Bus connection */
   connection = dbus_g_connection_get_connection (manager->connection);
 
   /* request ownership for the manager interface */
   result = dbus_bus_request_name (connection, "org.freedesktop.thumbnails.Manager1",
-                                  DBUS_NAME_FLAG_DO_NOT_QUEUE, &dbus_error);
+                                  DBUS_NAME_FLAG_DO_NOT_QUEUE, NULL);
 
   /* check if that failed */
-  if (result == DBUS_REQUEST_NAME_REPLY_EXISTS)
+  if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
     {
       if (error != NULL)
         {
-          g_set_error (error, DBUS_GERROR, DBUS_GERROR_ADDRESS_IN_USE,
-                       _("Another thumbnail cache service is already running"));
-        }
-
-      g_mutex_unlock (manager->mutex);
-
-      return FALSE;
-    }
-  else if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
-    {
-      /* propagate the D-Bus error */
-      if (dbus_error_is_set (&dbus_error))
-        {
-          if (error != NULL)
-            dbus_set_g_error (error, &dbus_error);
-
-          dbus_error_free (&dbus_error);
-        }
-      else if (error != NULL)
-        {
           g_set_error (error, DBUS_GERROR, DBUS_GERROR_FAILED,
                        _("Another thumbnailer manager is already running"));
         }
diff --git a/tumblerd/tumbler-service.c b/tumblerd/tumbler-service.c
index 8214a45..3039df9 100644
--- a/tumblerd/tumbler-service.c
+++ b/tumblerd/tumbler-service.c
@@ -735,7 +735,6 @@ tumbler_service_start (TumblerService *service,
                        GError        **error)
 {
   DBusConnection *connection;
-  DBusError       dbus_error;
   gint            result;
 
   g_return_val_if_fail (TUMBLER_IS_SERVICE (service), FALSE);
@@ -743,40 +742,18 @@ tumbler_service_start (TumblerService *service,
 
   g_mutex_lock (service->mutex);
 
-  dbus_error_init (&dbus_error);
-
   /* get the native D-Bus connection */
   connection = dbus_g_connection_get_connection (service->connection);
 
   /* request ownership for the generic thumbnailer interface */
   result = dbus_bus_request_name (connection, THUMBNAILER_SERVICE,
-                                  DBUS_NAME_FLAG_DO_NOT_QUEUE, &dbus_error);
+                                  DBUS_NAME_FLAG_DO_NOT_QUEUE, NULL);
 
   /* check if that failed */
-  if (result == DBUS_REQUEST_NAME_REPLY_EXISTS)
+  if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
     {
       if (error != NULL)
         {
-          g_set_error (error, DBUS_GERROR, DBUS_GERROR_ADDRESS_IN_USE,
-                       _("Another thumbnail cache service is already running"));
-        }
-
-      g_mutex_unlock (service->mutex);
-
-      return FALSE;
-    }
-  else if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)
-    {
-      /* propagate the D-Bus error */
-      if (dbus_error_is_set (&dbus_error))
-        {
-          if (error != NULL)
-            dbus_set_g_error (error, &dbus_error);
-
-          dbus_error_free (&dbus_error);
-        }
-      else if (error != NULL)
-        {
           g_set_error (error, DBUS_GERROR, DBUS_GERROR_FAILED,
                        _("Another generic thumbnailer is already running"));
         }


More information about the Xfce4-commits mailing list