Gentoo Archives: gentoo-commits

From: "Stephen Klimaszewski (steev)" <steev@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] gentoo-x86 commit in sys-apps/dbus/files: 0001-Fix-inotify-shutdown.patch 0002-Fix-compilation-in-disable-selinux-case.patch
Date: Wed, 03 Feb 2010 16:07:39
Message-Id: E1NchlI-0008QD-DW@stork.gentoo.org
1 steev 10/02/03 16:07:28
2
3 Added: 0001-Fix-inotify-shutdown.patch
4 0002-Fix-compilation-in-disable-selinux-case.patch
5 Log:
6 Bump dbus, add 2 patches from upstream, one to fix a compilation issue
7 with selinux disabled, the other to move the shutdown handler into
8 inotify.
9 (Portage version: 2.1.7.17/cvs/Linux i686)
10
11 Revision Changes Path
12 1.1 sys-apps/dbus/files/0001-Fix-inotify-shutdown.patch
13
14 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-apps/dbus/files/0001-Fix-inotify-shutdown.patch?rev=1.1&view=markup
15 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-apps/dbus/files/0001-Fix-inotify-shutdown.patch?rev=1.1&content-type=text/plain
16
17 Index: 0001-Fix-inotify-shutdown.patch
18 ===================================================================
19 From 90fe96b1875350f86a4a773d4a0a22009950dd4d Mon Sep 17 00:00:00 2001
20 From: Colin Walters <walters@××××××.org>
21 Date: Tue, 2 Feb 2010 12:37:17 -0500
22 Subject: [PATCH 1/2] Fix inotify shutdown
23
24 We were incorrectly passing NULL for a DBusList when the usage expected
25 is a pointer to a NULL DBusList pointer. Also during dbus_shutdown
26 we need to actually close the inotify fd, and remove our watch.
27
28 Move the shutdown handler out of bus.c and into inotify where we
29 can do all of this cleanly.
30 ---
31 bus/bus.c | 8 ---
32 bus/dir-watch-inotify.c | 128 ++++++++++++++++++++++++++++++-----------------
33 2 files changed, 82 insertions(+), 54 deletions(-)
34
35 diff --git a/bus/bus.c b/bus/bus.c
36 index bfd398e..8150df2 100644
37 --- a/bus/bus.c
38 +++ b/bus/bus.c
39 @@ -551,12 +551,6 @@ process_config_postinit (BusContext *context,
40 return TRUE;
41 }
42
43 -static void
44 -bus_shutdown_all_directory_watches (void *data)
45 -{
46 - bus_set_watched_dirs ((BusContext *) data, NULL);
47 -}
48 -
49 BusContext*
50 bus_context_new (const DBusString *config_file,
51 ForceForkSetting force_fork,
52 @@ -588,8 +582,6 @@ bus_context_new (const DBusString *config_file,
53
54 _dbus_generate_uuid (&context->uuid);
55
56 - _dbus_register_shutdown_func (bus_shutdown_all_directory_watches, context);
57 -
58 if (!_dbus_string_copy_data (config_file, &context->config_file))
59 {
60 BUS_SET_OOM (error);
61 diff --git a/bus/dir-watch-inotify.c b/bus/dir-watch-inotify.c
62 index f87a634..bb71394 100644
63 --- a/bus/dir-watch-inotify.c
64 +++ b/bus/dir-watch-inotify.c
65 @@ -92,59 +92,16 @@ _handle_inotify_watch (DBusWatch *passed_watch, unsigned int flags, void *data)
66 return TRUE;
67 }
68
69 -static int
70 -_init_inotify (BusContext *context)
71 -{
72 - int ret = 0;
73 -
74 - if (inotify_fd == -1) {
75 -#ifdef HAVE_INOTIFY_INIT1
76 - inotify_fd = inotify_init1 (IN_CLOEXEC);
77 -#else
78 - inotify_fd = inotify_init ();
79 -#endif
80 - if (inotify_fd <= 0) {
81 - _dbus_warn ("Cannot initialize inotify\n");
82 - goto out;
83 - }
84 - loop = bus_context_get_loop (context);
85 -
86 - watch = _dbus_watch_new (inotify_fd, DBUS_WATCH_READABLE, TRUE,
87 - _handle_inotify_watch, NULL, NULL);
88 -
89 - if (watch == NULL)
90 - {
91 - _dbus_warn ("Unable to create inotify watch\n");
92 - goto out;
93 - }
94 -
95 - if (!_dbus_loop_add_watch (loop, watch, _inotify_watch_callback,
96 - NULL, NULL))
97 - {
98 - _dbus_warn ("Unable to add reload watch to main loop");
99 - _dbus_watch_unref (watch);
100 - watch = NULL;
101 - goto out;
102 - }
103 - }
104 +#include <stdio.h>
105
106 - ret = 1;
107 -
108 -out:
109 - return ret;
110 -}
111 -
112 -void
113 -bus_set_watched_dirs (BusContext *context, DBusList **directories)
114 +static void
115 +_set_watched_dirs_internal (DBusList **directories)
116 {
117 int new_wds[MAX_DIRS_TO_WATCH];
118 char *new_dirs[MAX_DIRS_TO_WATCH];
119 DBusList *link;
120 int i, j, wd;
121
122 - if (!_init_inotify (context))
123 - goto out;
124 -
125 for (i = 0; i < MAX_DIRS_TO_WATCH; i++)
126 {
127 new_wds[i] = -1;
128 @@ -226,3 +183,82 @@ bus_set_watched_dirs (BusContext *context, DBusList **directories)
129
130 out:;
131 }
132 +
133 +#include <stdio.h>
134 +static void
135 +_shutdown_inotify (void *data)
136 +{
137 + DBusList *empty = NULL;
138 +
139 + if (inotify_fd == -1)
140 + return;
141 +
142 + _set_watched_dirs_internal (&empty);
143 +
144 + close (inotify_fd);
145 + inotify_fd = -1;
146 + if (watch != NULL)
147 + {
148 + _dbus_loop_remove_watch (loop, watch, _inotify_watch_callback, NULL);
149 + _dbus_watch_unref (watch);
150 + _dbus_loop_unref (loop);
151 + }
152 + watch = NULL;
153 + loop = NULL;
154 +}
155 +
156 +static int
157 +_init_inotify (BusContext *context)
158 +{
159 + int ret = 0;
160 +
161 + if (inotify_fd == -1)
162 + {
163 +#ifdef HAVE_INOTIFY_INIT1
164 + inotify_fd = inotify_init1 (IN_CLOEXEC);
165 +#else
166 + inotify_fd = inotify_init ();
167 +#endif
168 + if (inotify_fd <= 0)
169 + {
170 + _dbus_warn ("Cannot initialize inotify\n");
171 + goto out;
172 + }
173 + loop = bus_context_get_loop (context);
174 + _dbus_loop_ref (loop);
175 +
176 + watch = _dbus_watch_new (inotify_fd, DBUS_WATCH_READABLE, TRUE,
177 + _handle_inotify_watch, NULL, NULL);
178 +
179 + if (watch == NULL)
180 + {
181 + _dbus_warn ("Unable to create inotify watch\n");
182 + goto out;
183 + }
184 +
185 + if (!_dbus_loop_add_watch (loop, watch, _inotify_watch_callback,
186 + NULL, NULL))
187 + {
188 + _dbus_warn ("Unable to add reload watch to main loop");
189 + _dbus_watch_unref (watch);
190 + watch = NULL;
191 + goto out;
192 + }
193 +
194 + _dbus_register_shutdown_func (_shutdown_inotify, NULL);
195 + }
196 +
197 + ret = 1;
198 +
199 +out:
200 + return ret;
201 +}
202 +
203 +void
204 +bus_set_watched_dirs (BusContext *context, DBusList **directories)
205 +{
206 + if (!_init_inotify (context))
207 + return;
208 +
209 + _set_watched_dirs_internal (directories);
210 +}
211 --
212 1.6.2.5
213
214
215
216
217 1.1 sys-apps/dbus/files/0002-Fix-compilation-in-disable-selinux-case.patch
218
219 file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-apps/dbus/files/0002-Fix-compilation-in-disable-selinux-case.patch?rev=1.1&view=markup
220 plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/sys-apps/dbus/files/0002-Fix-compilation-in-disable-selinux-case.patch?rev=1.1&content-type=text/plain
221
222 Index: 0002-Fix-compilation-in-disable-selinux-case.patch
223 ===================================================================
224 From 3dac125d61ebc4f614a1723580043e2f1c811f59 Mon Sep 17 00:00:00 2001
225 From: Colin Walters <walters@××××××.org>
226 Date: Tue, 2 Feb 2010 14:57:47 -0500
227 Subject: [PATCH 2/2] Fix compilation in --disable-selinux case
228
229 _dbus_change_to_daemon_user moved into selinux.c for the --with-selinux
230 (and audit) case because that's where all of the relevant libcap headers
231 were being used. However in the --disable-selinux case this didn't
232 compile and wasn't very clean.
233
234 If we don't have libaudit, use the legacy direct setgid/setuid bits
235 we had before in dbus-sysdeps-util-unix.c.
236 ---
237 bus/selinux.c | 35 ++---------------------
238 bus/selinux.h | 2 -
239 dbus/dbus-sysdeps-util-unix.c | 62 +++++++++++++++++++++++++++++++++++++++++
240 dbus/dbus-sysdeps.h | 3 ++
241 4 files changed, 68 insertions(+), 34 deletions(-)
242
243 diff --git a/bus/selinux.c b/bus/selinux.c
244 index 456723a..e61efc5 100644
245 --- a/bus/selinux.c
246 +++ b/bus/selinux.c
247 @@ -1017,6 +1017,8 @@ bus_selinux_shutdown (void)
248 #endif /* HAVE_SELINUX */
249 }
250
251 +/* The !HAVE_LIBAUDIT case lives in dbus-sysdeps-util-unix.c */
252 +#ifdef HAVE_LIBAUDIT
253 /**
254 * Changes the user and group the bus is running as.
255 *
256 @@ -1042,7 +1044,6 @@ _dbus_change_to_daemon_user (const char *user,
257 return FALSE;
258 }
259
260 -#ifdef HAVE_LIBAUDIT
261 /* If we were root */
262 if (_dbus_geteuid () == 0)
263 {
264 @@ -1083,38 +1084,8 @@ _dbus_change_to_daemon_user (const char *user,
265 return FALSE;
266 }
267 }
268 -#else
269 - /* setgroups() only works if we are a privileged process,
270 - * so we don't return error on failure; the only possible
271 - * failure is that we don't have perms to do it.
272 - *
273 - * not sure this is right, maybe if setuid()
274 - * is going to work then setgroups() should also work.
275 - */
276 - if (setgroups (0, NULL) < 0)
277 - _dbus_warn ("Failed to drop supplementary groups: %s\n",
278 - _dbus_strerror (errno));
279 -
280 - /* Set GID first, or the setuid may remove our permission
281 - * to change the GID
282 - */
283 - if (setgid (gid) < 0)
284 - {
285 - dbus_set_error (error, _dbus_error_from_errno (errno),
286 - "Failed to set GID to %lu: %s", gid,
287 - _dbus_strerror (errno));
288 - return FALSE;
289 - }
290 -
291 - if (setuid (uid) < 0)
292 - {
293 - dbus_set_error (error, _dbus_error_from_errno (errno),
294 - "Failed to set UID to %lu: %s", uid,
295 - _dbus_strerror (errno));
296 - return FALSE;
297 - }
298 -#endif /* !HAVE_LIBAUDIT */
299
300 return TRUE;
301 }
302 +#endif
303
304 diff --git a/bus/selinux.h b/bus/selinux.h
305 index f208fbe..3bab36d 100644
306 --- a/bus/selinux.h
307 +++ b/bus/selinux.h
308 @@ -68,7 +68,5 @@ BusSELinuxID* bus_selinux_init_connection_id (DBusConnection *connection,
309
310
311 void bus_selinux_audit_init(void);
312 -dbus_bool_t _dbus_change_to_daemon_user (const char *user,
313 - DBusError *error);
314
315 #endif /* BUS_SELINUX_H */
316 diff --git a/dbus/dbus-sysdeps-util-unix.c b/dbus/dbus-sysdeps-util-unix.c
317 index 27cdbb0..74e8d88 100644
318 --- a/dbus/dbus-sysdeps-util-unix.c
319 +++ b/dbus/dbus-sysdeps-util-unix.c
320 @@ -303,6 +303,68 @@ _dbus_verify_daemon_user (const char *user)
321 return _dbus_get_user_id_and_primary_group (&u, NULL, NULL);
322 }
323
324 +
325 +/* The HAVE_LIBAUDIT case lives in selinux.c */
326 +#ifndef HAVE_LIBAUDIT
327 +/**
328 + * Changes the user and group the bus is running as.
329 + *
330 + * @param user the user to become
331 + * @param error return location for errors
332 + * @returns #FALSE on failure
333 + */
334 +dbus_bool_t
335 +_dbus_change_to_daemon_user (const char *user,
336 + DBusError *error)
337 +{
338 + dbus_uid_t uid;
339 + dbus_gid_t gid;
340 + DBusString u;
341 +
342 + _dbus_string_init_const (&u, user);
343 +
344 + if (!_dbus_get_user_id_and_primary_group (&u, &uid, &gid))
345 + {
346 + dbus_set_error (error, DBUS_ERROR_FAILED,
347 + "User '%s' does not appear to exist?",
348 + user);
349 + return FALSE;
350 + }
351 +
352 + /* setgroups() only works if we are a privileged process,
353 + * so we don't return error on failure; the only possible
354 + * failure is that we don't have perms to do it.
355 + *
356 + * not sure this is right, maybe if setuid()
357 + * is going to work then setgroups() should also work.
358 + */
359 + if (setgroups (0, NULL) < 0)
360 + _dbus_warn ("Failed to drop supplementary groups: %s\n",
361 + _dbus_strerror (errno));
362 +
363 + /* Set GID first, or the setuid may remove our permission
364 + * to change the GID
365 + */
366 + if (setgid (gid) < 0)
367 + {
368 + dbus_set_error (error, _dbus_error_from_errno (errno),
369 + "Failed to set GID to %lu: %s", gid,
370 + _dbus_strerror (errno));
371 + return FALSE;
372 + }
373 +
374 + if (setuid (uid) < 0)
375 + {
376 + dbus_set_error (error, _dbus_error_from_errno (errno),
377 + "Failed to set UID to %lu: %s", uid,
378 + _dbus_strerror (errno));
379 + return FALSE;
380 + }
381 +
382 + return TRUE;
383 +}
384 +#endif /* !HAVE_LIBAUDIT */
385 +
386 void
387 _dbus_init_system_log (void)
388 {
389 diff --git a/dbus/dbus-sysdeps.h b/dbus/dbus-sysdeps.h
390 index b154f01..80f0ba2 100644
391 --- a/dbus/dbus-sysdeps.h
392 +++ b/dbus/dbus-sysdeps.h
393 @@ -512,6 +512,9 @@ unsigned long _dbus_pid_for_log (void);
394 */
395 dbus_pid_t _dbus_getpid (void);
396
397 +dbus_bool_t _dbus_change_to_daemon_user (const char *user,
398 + DBusError *error);
399 +
400 void _dbus_flush_caches (void);
401
402 /** @} */
403 --
404 1.6.2.5