summaryrefslogtreecommitdiffstats
path: root/bind-9.4.0-dbus-race-condition.patch
blob: 67892bc70b60c1edc5223f29c858f88459f24a1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
--- bind-9.4.0/contrib/dbus/dbus_service.c.race-condition	2006-09-28 07:53:47.000000000 +0200
+++ bind-9.4.0/contrib/dbus/dbus_service.c	2007-04-27 15:10:03.000000000 +0200
@@ -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 @@
 #include <dbus/dbus.h>
 
 #include <named/dbus_service.h>
+#include <isc/result.h>
 
 typedef struct dbcs_s
 {
@@ -914,38 +916,39 @@
     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 @@
 	      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 @@
 {
     DBusConnection       *connection;
     DBusError            error;
-    DBusConnectionState  *cs;
     char *session_bus_address=0L;
 
     memset(&error,'\0',sizeof(DBusError));
@@ -1015,7 +1018,7 @@
 	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 @@
 	    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 @@
 	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 @@
 	    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 @@
 	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 @@
 	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)
--- bind-9.4.0/contrib/dbus/dbus_mgr.c.race-condition	2006-01-23 05:56:26.000000000 +0100
+++ bind-9.4.0/contrib/dbus/dbus_mgr.c	2007-04-27 15:03:19.000000000 +0200
@@ -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 @@
 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 @@
 	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 )
     {
--- bind-9.4.0/contrib/dbus/dbus_service.h.race-condition	2006-01-23 05:56:26.000000000 +0100
+++ bind-9.4.0/contrib/dbus/dbus_service.h	2007-04-27 15:03:19.000000000 +0200
@@ -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 @@
 
 #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 */