]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
2176. [contrib] dbus update to handle race condition during
authorMark Andrews <marka@isc.org>
Thu, 10 May 2007 05:47:02 +0000 (05:47 +0000)
committerMark Andrews <marka@isc.org>
Thu, 10 May 2007 05:47:02 +0000 (05:47 +0000)
                        initialisation (Bugzilla 235809). [RT #16842]

CHANGES
contrib/dbus/dbus_mgr.c
contrib/dbus/dbus_service.c
contrib/dbus/dbus_service.h

diff --git a/CHANGES b/CHANGES
index 363ada11df0bb9f88b9c32b85178de01a899473a..c580afa630a86e0a16d762b588063d98e574db5d 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,6 @@
+2176.  [contrib]       dbus update to handle race condition during
+                       initialisation (Bugzilla 235809). [RT #16842]
+
 2175.  [bug]           win32: windows broadcast condition variable support
                        was broken. [RT #16592]
 
index 832c0cac3c7fb185b495ede4a3e9d17f33b13785..71e1eacd6b8a0b2c1106b607b539cfd25a643bb0 100644 (file)
@@ -4,6 +4,7 @@
  *  response to D-BUS dhcp events or commands.
  *
  *  Copyright(C) Jason Vas Dias, Red Hat Inc., 2005
+ *  Modified by Adam Tkac, Red Hat Inc., 2007
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -281,6 +282,7 @@ static isc_result_t
 dbus_mgr_init_dbus(ns_dbus_mgr_t * mgr)
 {
     char destination[]=DBUSMGR_DESTINATION;
+    isc_result_t result;
 
     if( mgr->sockets != 0L )
     {
@@ -296,14 +298,11 @@ dbus_mgr_init_dbus(ns_dbus_mgr_t * mgr)
        mgr->dbus = 0L;
     }
 
-    mgr->dbus = 
-       dbus_svc_init
-       (   DBUS_PRIVATE_SYSTEM,
-           destination,
-           dbus_mgr_watch_handler,
-           0L, 0L,
-           mgr
-       );
+    result = dbus_svc_init(DBUS_PRIVATE_SYSTEM, destination, &mgr->dbus,
+                                       dbus_mgr_watch_handler, 0L, 0L, mgr);
+
+    if(result != ISC_R_SUCCESS)
+       goto cleanup;
 
     if( mgr->dbus == 0L )
     {
index bb9dabaff6e2debb1643c9df3ccd507e95749485..0ed903d07ce1307190982146e439cccb0f1b1181 100644 (file)
@@ -5,6 +5,7 @@
  *  Provides MINIMAL utilities for construction of D-BUS "Services".
  *  
  *  Copyright(C) Jason Vas Dias, Red Hat Inc., 2005
+ *  Modified by Adam Tkac, Red Hat Inc., 2007
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -50,6 +51,7 @@ extern void tdestroy (void *__root, __free_fn_t __freefct);
 #include <dbus/dbus.h>
 
 #include <named/dbus_service.h>
+#include <isc/result.h>
 
 typedef struct dbcs_s
 {
@@ -914,38 +916,39 @@ dbus_svc_quit( DBusConnectionState *cs )
     cs->status = SHUTDOWN;
 }
 
-static DBusConnectionState *
+static isc_result_t
 connection_setup 
-(   DBusConnection *connection,  
+(   DBusConnection *connection,
+    DBUS_SVC *dbus,
     dbus_svc_WatchHandler wh, 
     dbus_svc_ErrorHandler eh, 
     dbus_svc_ErrorHandler dh,
     void *wh_arg
 )
 {
-    DBusConnectionState *cs = dbcs_new( connection );
+    *dbus = dbcs_new( connection );
     
-    if ( cs == 0L )
+    if ( *dbus == 0L )
     {
        if(eh)(*(eh))("connection_setup: out of memory");
        goto fail;
     }
-    cs->wh = wh;
-    cs->wh_arg = wh_arg;
-    cs->eh = eh;
-    cs->dh = dh;
+    (*dbus)->wh = wh;
+    (*dbus)->wh_arg = wh_arg;
+    (*dbus)->eh = eh;
+    (*dbus)->dh = dh;
 
     if (!dbus_connection_set_watch_functions 
-        (    cs->connection,
+        (    (*dbus)->connection,
              add_watch,
              remove_watch,
              toggle_watch,
-             cs,
+             *dbus,
              no_free
          )
        )
     {
-       if( cs->eh != 0L ) (*(cs->eh))("connection_setup: dbus_connection_set_watch_functions failed");
+       if( (*dbus)->eh != 0L ) (*((*dbus)->eh))("connection_setup: dbus_connection_set_watch_functions failed");
        goto fail; 
     }
       
@@ -954,43 +957,44 @@ connection_setup
              add_timeout,
              remove_timeout,
              toggle_timeout,
-             cs, 
+             *dbus, 
              no_free
         )
        )
     {
-       if( cs->eh != 0L ) (*(cs->eh))("connection_setup: dbus_connection_set_timeout_functions failed");
+       if( (*dbus)->eh != 0L ) (*((*dbus)->eh))("connection_setup: dbus_connection_set_timeout_functions failed");
        goto fail;
     }
 
     dbus_connection_set_dispatch_status_function 
     (   connection, 
        dispatch_status, 
-       cs, 
+       *dbus, 
        no_free
     ); 
 
     if (dbus_connection_get_dispatch_status (connection) != DBUS_DISPATCH_COMPLETE)
        dbus_connection_ref(connection);    
     
-    return cs;
+    return ISC_R_SUCCESS;
   
  fail:
-    if( cs != 0L )
-       free(cs);
+    if( *dbus != 0L )
+       free(*dbus);
   
     dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
     dbus_connection_set_watch_functions (connection, NULL, NULL, NULL, NULL, NULL);
     dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL);
   
-    return 0L;
+    return ISC_R_FAILURE;
 }
 
-DBusConnectionState *
+isc_result_t
 dbus_svc_init
 (
     dbus_svc_DBUS_TYPE    bus,
     char                  *name, 
+    DBUS_SVC             *dbus,
     dbus_svc_WatchHandler wh ,
     dbus_svc_ErrorHandler eh ,
     dbus_svc_ErrorHandler dh ,
@@ -999,7 +1003,6 @@ dbus_svc_init
 {
     DBusConnection       *connection;
     DBusError            error;
-    DBusConnectionState  *cs;
     char *session_bus_address=0L;
 
     memset(&error,'\0',sizeof(DBusError));
@@ -1015,7 +1018,7 @@ dbus_svc_init
        if ( (connection = dbus_connection_open_private("unix:path=/var/run/dbus/system_bus_socket", &error)) == 0L )
        {
            if(eh)(*eh)("dbus_svc_init failed: %s %s",error.name, error.message);
-           return ( 0L );
+           return ISC_R_FAILURE;
        }
 
        if ( ! dbus_bus_register(connection,&error) )
@@ -1023,7 +1026,7 @@ dbus_svc_init
            if(eh)(*eh)("dbus_bus_register failed: %s %s", error.name, error.message);
            dbus_connection_close(connection);
            free(connection);
-           return ( 0L );
+           return ISC_R_FAILURE;
        }
        break;
 
@@ -1033,13 +1036,13 @@ dbus_svc_init
        if ( session_bus_address == 0L )
        {
            if(eh)(*eh)("dbus_svc_init failed: DBUS_SESSION_BUS_ADDRESS environment variable not set");
-           return ( 0L );
+           return ISC_R_FAILURE;
        }
 
        if ( (connection = dbus_connection_open_private(session_bus_address, &error)) == 0L )
        {
            if(eh)(*eh)("dbus_svc_init failed: %s %s",error.name, error.message);
-           return ( 0L );
+           return ISC_R_FAILURE;
        }
 
        if ( ! dbus_bus_register(connection,&error) )
@@ -1047,7 +1050,7 @@ dbus_svc_init
            if(eh)(*eh)("dbus_bus_register failed: %s %s", error.name, error.message);
            dbus_connection_close(connection);
            free(connection);
-           return ( 0L );
+           return ISC_R_FAILURE;
        }
        break;
 
@@ -1057,27 +1060,27 @@ dbus_svc_init
        if ( (connection = dbus_bus_get (bus, &error)) == 0L )
        {
            if(eh)(*eh)("dbus_svc_init failed: %s %s",error.name, error.message);
-           return ( 0L );
+           return ISC_R_FAILURE;
        }
        break;
 
     default:
        if(eh)(*eh)("dbus_svc_init failed: unknown bus type %d", bus);
-       return ( 0L );
+       return ISC_R_FAILURE;
     }
     
     dbus_connection_set_exit_on_disconnect(connection, FALSE);
 
-    if ( (cs = connection_setup(connection, wh, eh, dh, wh_arg)) == 0L )
+    if ( (connection_setup(connection, dbus, wh, eh, dh, wh_arg)) != ISC_R_SUCCESS)
     {
        if(eh)(*eh)("dbus_svc_init failed: connection_setup failed");
-       return( 0L );
+       return ISC_R_FAILURE;
     }
 
     if( name == 0L )
-       return( cs );
+       return ISC_R_SUCCESS;
     
-    cs->unique_name = dbus_bus_get_unique_name(connection);
+    (*dbus)->unique_name = dbus_bus_get_unique_name(connection);
 
     switch
        (   dbus_bus_request_name 
@@ -1102,19 +1105,19 @@ dbus_svc_init
        if(eh)(*eh)("dbus_svc_init: dbus_bus_request_name failed: %s %s", error.name, error.message);
        goto give_up;
     }
-    return ( cs );
+    return ISC_R_SUCCESS;
 
  give_up:
     dbus_connection_close( connection );
     dbus_connection_unref( connection );
-    if( cs )
+    if( *dbus )
     {
        dbus_connection_set_dispatch_status_function (connection, NULL, NULL, NULL);
        dbus_connection_set_watch_functions (connection, NULL, NULL, NULL, NULL, NULL);
        dbus_connection_set_timeout_functions (connection, NULL, NULL, NULL, NULL, NULL);
-       free(cs);    
+       free(*dbus);    
     }
-    return ( 0L );
+    return ISC_R_FAILURE;
 }
 
 const char *dbus_svc_unique_name(DBusConnectionState *cs)
index 69e7facafd843ef5ec1287bb468b6e2be4647892..d8a21f1800dcc618e6c44d2c28adb605677aeb12 100644 (file)
@@ -3,6 +3,7 @@
  *  Provides utilities for construction of D-BUS "Services"  
  *
  *  Copyright(C) Jason Vas Dias, Red Hat Inc., 2005
+ *  Modified by Adam Tkac, Red Hat Inc., 2007
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -22,6 +23,7 @@
 
 #include <stdint.h>
 #include <stdarg.h>
+#include <isc/types.h>
 
 typedef struct dbcs_s* DBUS_SVC;
 
@@ -124,9 +126,10 @@ typedef dbus_svc_HandlerResult
 
 #define SHUTDOWN 255
 
-extern  DBUS_SVC dbus_svc_init
+extern isc_result_t dbus_svc_init
 ( dbus_svc_DBUS_TYPE bus, 
   char *name,                         /* name to register with D-BUS */
+  DBUS_SVC *dbus,                     /* dbus handle */
   dbus_svc_WatchHandler wh,           /* optional handler for watch events */
   dbus_svc_ErrorHandler eh,           /* optional error log message handler */
   dbus_svc_ErrorHandler dh,           /* optional debug / info log message handler */