~ubuntu-branches/ubuntu/utopic/cups/utopic

« back to all changes in this revision

Viewing changes to debian/patches/dont-use-dbus-from-two-threads.patch

  • Committer: Package Import Robot
  • Author(s): Didier Raboud, Till Kamppeter, Steve Langasek, Didier Raboud
  • Date: 2014-01-03 18:42:39 UTC
  • mfrom: (99.2.3 sid)
  • Revision ID: package-import@ubuntu.com-20140103184239-85wju2l7weie4dgo
Tags: 1.7.0-1
* New 1.7.0 upstream release

[ Till Kamppeter ]
* Refresh most patches with quilt
* Removed usb-backend-do-not-crash-if-usb-disabled-in-bios and
  cupsd-no-crash-on-avahi-threaded-poll-shutdown patches as they got
  applied upstream
* Removed drop-arch-specifics-from-doc patch as it is not needed
  anymore
* Updated drop_unnecessary_dependencies, manpage-hyphen-minus,
  manpage-translations and ppd-poll-with-client-conf patches manually
  to apply to the new CUPS version
* Added error counting exception from
  usb-backend-do-not-crash-if-usb-disabled-in-bios to
  tests-ignore-warnings
* Install the newly added ippfind utility and its manpage in
  cups-client
* Added pwg.h to libcups2-dev package
* Call dh_auto_clean only if the file Makedefs is present, to avoid a
  FTBFS
* Added color management extensions from Joe Simon's GSoC 2013
  project.
* Patch cups-files.conf to activate CUPS daemon syncing of files when
  closing, so that config files (like printers.conf) do not
  mysteriously disappear (LP: #1157972)
* In the AppArmor profile, allow execution of programs in
  /etc/cups/interfaces/, needed to make CUPS working with queues based
  on System V interface scripts, especially PPD-less queues
  auto-generated by cups-browsed from cups-filters 1.0.41 on.
* Silenced AppArmor noise from udev.conf in syslog (LP: #1229766)

[ Steve Langasek ]
* Add cups-filters (>= 1.0.42) as alternative to foomatic-filters
  (which is deprecated) in package relationships

[ Didier Raboud ]
* Remove Roger Leigh from uploaders on his request with thanks for his
  past work!
* Switch avahi LSB Should-Start dependency to be avahi-daemon; also
  bump package relationship to >= 0.6.31-3~ (Closes: #731608)
* Refresh the manpage translation files
* Move the USB backend quirk rules file to cups-server-common
* Add 38 new 1.7.0 libcups2 symbols
* Mark one C++ libcupsppdc1 symbol as optional as it isn't exported in
  1.7.0 anymore
* Import Fedora patches:
  - to avoid sign-extending CRCs in gz decompression
  - to build with full read-only relocations
  - to fix job history logging (upstream patch)
  - to set the internal default for SyncOnClose to Yes, instead of
    only configuring it to Yes
  - to fix a stringpool corruption issue
  - to prevent USB timeouts causing incorrect print output
* Import Fedora patch updates:
  - to dont-use-dbus-from-two-threads patch so it removes a call to
    avahi_threaded_poll_stop()
  - to avoid_stale_lockfile_in_dbus_notifier patch to call _exit when
    handling SIGTERM
* Move manpage-translations patch at the very end of the patch series
  to have it include all our patches

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Description: Don't use D-Bus from two threads
 
2
Author: Tim Waugh <twaugh@redhat.com>
 
3
Bug-Redhat: https://bugzilla.redhat.com/show_bug.cgi?id=979748
 
4
Last-Updated: 2013-11-28
 
5
--- /dev/null
 
6
+++ b/scheduler/avahi.c
 
7
@@ -0,0 +1,441 @@
 
8
+/*
 
9
+ * "$Id$"
 
10
+ *
 
11
+ *   Avahi poll implementation for the CUPS scheduler.
 
12
+ *
 
13
+ *   Copyright (C) 2010, 2011 Red Hat, Inc.
 
14
+ *   Authors:
 
15
+ *    Tim Waugh <twaugh@redhat.com>
 
16
+ *
 
17
+ *   Redistribution and use in source and binary forms, with or without
 
18
+ *   modification, are permitted provided that the following conditions
 
19
+ *   are met:
 
20
+ *
 
21
+ *   Redistributions of source code must retain the above copyright
 
22
+ *   notice, this list of conditions and the following disclaimer.
 
23
+ *
 
24
+ *   Redistributions in binary form must reproduce the above copyright
 
25
+ *   notice, this list of conditions and the following disclaimer in the
 
26
+ *   documentation and/or other materials provided with the distribution.
 
27
+ *
 
28
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
29
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
30
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 
31
+ *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 
32
+ *   COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 
33
+ *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
34
+ *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
35
+ *   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
36
+ *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 
37
+ *   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
38
+ *   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 
39
+ *   OF THE POSSIBILITY OF SUCH DAMAGE.
 
40
+ *
 
41
+ * Contents:
 
42
+ *
 
43
+ *   watch_read_cb         - Read callback for file descriptor
 
44
+ *   watch_write_cb        - Write callback for file descriptor
 
45
+ *   watched_fd_add_select() - Call cupsdAddSelect() as needed
 
46
+ *   watch_new()           - Create a new file descriptor watch
 
47
+ *   watch_free()          - Free a file descriptor watch
 
48
+ *   watch_update()        - Update watched events for a file descriptor
 
49
+ *   watch_get_events()    - Get events that happened for a file descriptor
 
50
+ *   timeout_cb()          - Run a timed Avahi callback
 
51
+ *   timeout_new()         - Set a wakeup time
 
52
+ *   timeout_update()      - Update the expiration time for a timeout
 
53
+ *   timeout_free()        - Free a timeout
 
54
+ *   compare_watched_fds() - Compare watched file descriptors for array sorting
 
55
+ *   avahi_cups_poll_new() - Create a new Avahi main loop object for CUPS
 
56
+ *   avahi_cups_poll_free() - Free an Avahi main loop object for CUPS
 
57
+ *   avahi_cups_poll_get() - Get the abstract poll API structure
 
58
+ */
 
59
+
 
60
+#include <config.h>
 
61
+
 
62
+#ifdef HAVE_AVAHI /* Applies to entire file... */
 
63
+
 
64
+/*
 
65
+ * Include necessary headers...
 
66
+ */
 
67
+
 
68
+#include "cupsd.h"
 
69
+
 
70
+#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
 
71
+#  include <malloc.h>
 
72
+#endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
 
73
+
 
74
+#ifdef HAVE_AVAHI
 
75
+#  include <avahi-common/timeval.h>
 
76
+#endif /* HAVE_AVAHI */
 
77
+
 
78
+
 
79
+typedef struct
 
80
+{
 
81
+  AvahiCupsPoll *cups_poll;
 
82
+
 
83
+  int fd;
 
84
+  AvahiWatchEvent occurred;
 
85
+  cups_array_t *watches;
 
86
+} cupsd_watched_fd_t;
 
87
+
 
88
+struct AvahiWatch
 
89
+{
 
90
+  cupsd_watched_fd_t *watched_fd;
 
91
+
 
92
+  AvahiWatchEvent events;
 
93
+  AvahiWatchCallback callback;
 
94
+  void *userdata;
 
95
+};
 
96
+
 
97
+struct AvahiTimeout
 
98
+{
 
99
+  AvahiCupsPoll *cups_poll;
 
100
+  AvahiTimeoutCallback callback;
 
101
+  void *userdata;
 
102
+  cupsd_timeout_t *cupsd_timeout;
 
103
+};
 
104
+
 
105
+/*
 
106
+ * Local functions...
 
107
+ */
 
108
+
 
109
+static AvahiWatch *    watch_new(const AvahiPoll *api,
 
110
+                                 int fd,
 
111
+                                 AvahiWatchEvent events,
 
112
+                                 AvahiWatchCallback callback,
 
113
+                                 void *userdata);
 
114
+static void            watch_free(AvahiWatch *watch);
 
115
+static void            watch_update(AvahiWatch *watch,
 
116
+                                    AvahiWatchEvent events);
 
117
+static AvahiWatchEvent watch_get_events(AvahiWatch *watch);
 
118
+
 
119
+
 
120
+/*
 
121
+ * 'watch_read_cb' - Read callback for file descriptor
 
122
+ */
 
123
+
 
124
+static void
 
125
+watch_read_cb (void *userdata)
 
126
+{
 
127
+  AvahiWatch *watch;
 
128
+  cupsd_watched_fd_t *watched_fd = userdata;
 
129
+  watched_fd->occurred |= AVAHI_WATCH_IN;
 
130
+  for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
 
131
+       watch;
 
132
+       watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
 
133
+  {
 
134
+    if (watch->events & watched_fd->occurred)
 
135
+    {
 
136
+      (watch->callback) (watch, watched_fd->fd,
 
137
+                        AVAHI_WATCH_IN, watch->userdata);
 
138
+      watched_fd->occurred &= ~AVAHI_WATCH_IN;
 
139
+      break;
 
140
+    }
 
141
+  }
 
142
+}
 
143
+
 
144
+
 
145
+/*
 
146
+ * 'watch_write_cb' - Write callback for file descriptor
 
147
+ */
 
148
+
 
149
+static void
 
150
+watch_write_cb (void *userdata)
 
151
+{
 
152
+  AvahiWatch *watch;
 
153
+  cupsd_watched_fd_t *watched_fd = userdata;
 
154
+  watched_fd->occurred |= AVAHI_WATCH_OUT;
 
155
+  for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
 
156
+       watch;
 
157
+       watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
 
158
+  {
 
159
+    if (watch->events & watched_fd->occurred)
 
160
+    {
 
161
+      (watch->callback) (watch, watched_fd->fd,
 
162
+                        AVAHI_WATCH_OUT, watch->userdata);
 
163
+      watched_fd->occurred &= ~AVAHI_WATCH_OUT;
 
164
+      break;
 
165
+    }
 
166
+  }
 
167
+}
 
168
+
 
169
+
 
170
+/*
 
171
+ * 'watched_fd_add_select' - Call cupsdAddSelect() as needed
 
172
+ */
 
173
+
 
174
+static int                                             /* O - Watches? */
 
175
+watched_fd_add_select (cupsd_watched_fd_t *watched_fd)
 
176
+{
 
177
+  AvahiWatch *watch;
 
178
+  cupsd_selfunc_t read_cb = NULL, write_cb = NULL;
 
179
+  int any_watches = 0;
 
180
+
 
181
+  for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
 
182
+       watch;
 
183
+       watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
 
184
+  {
 
185
+    any_watches = 1;
 
186
+    if (watch->events & (AVAHI_WATCH_IN |
 
187
+                            AVAHI_WATCH_ERR |
 
188
+                            AVAHI_WATCH_HUP))
 
189
+    {
 
190
+      read_cb = (cupsd_selfunc_t)watch_read_cb;
 
191
+      if (write_cb != NULL)
 
192
+       break;
 
193
+    }
 
194
+
 
195
+    if (watch->events & AVAHI_WATCH_OUT)
 
196
+    {
 
197
+      write_cb = (cupsd_selfunc_t)watch_write_cb;
 
198
+      if (read_cb != NULL)
 
199
+       break;
 
200
+    }
 
201
+  }
 
202
+
 
203
+  if (read_cb || write_cb)
 
204
+    cupsdAddSelect (watched_fd->fd, read_cb, write_cb, watched_fd);
 
205
+  else
 
206
+    cupsdRemoveSelect (watched_fd->fd);
 
207
+
 
208
+  return (any_watches);
 
209
+}
 
210
+
 
211
+/*
 
212
+ * 'watch_new' - Create a new file descriptor watch
 
213
+ */
 
214
+
 
215
+static AvahiWatch *
 
216
+watch_new (const AvahiPoll *api,
 
217
+          int fd,
 
218
+          AvahiWatchEvent events,
 
219
+          AvahiWatchCallback callback,
 
220
+          void *userdata)
 
221
+{
 
222
+  cupsd_watched_fd_t key, *watched_fd;
 
223
+  AvahiCupsPoll *cups_poll = api->userdata;
 
224
+  AvahiWatch *watch = malloc(sizeof(AvahiWatch));
 
225
+  if (watch == NULL)
 
226
+    return (NULL);
 
227
+
 
228
+  watch->events = events;
 
229
+  watch->callback = callback;
 
230
+  watch->userdata = userdata;
 
231
+
 
232
+  key.fd = fd;
 
233
+  watched_fd = cupsArrayFind (cups_poll->watched_fds, &key);
 
234
+  if (watched_fd == NULL)
 
235
+  {
 
236
+    watched_fd = malloc(sizeof(cupsd_watched_fd_t));
 
237
+    if (watched_fd == NULL)
 
238
+    {
 
239
+      free (watch);
 
240
+      return (NULL);
 
241
+    }
 
242
+
 
243
+    watched_fd->fd = fd;
 
244
+    watched_fd->occurred = 0;
 
245
+    watched_fd->cups_poll = cups_poll;
 
246
+    watched_fd->watches = cupsArrayNew (NULL, NULL);
 
247
+    cupsArrayAdd (cups_poll->watched_fds, watched_fd);
 
248
+  }
 
249
+
 
250
+  watch->watched_fd = watched_fd;
 
251
+  cupsArrayAdd(watched_fd->watches, watch);
 
252
+  watched_fd_add_select (watched_fd);
 
253
+  return (watch);
 
254
+}
 
255
+
 
256
+
 
257
+/*
 
258
+ * 'watch_free' - Free a file descriptor watch
 
259
+ */
 
260
+
 
261
+static void
 
262
+watch_free (AvahiWatch *watch)
 
263
+{
 
264
+  cupsd_watched_fd_t *watched_fd = watch->watched_fd;
 
265
+  AvahiCupsPoll *cups_poll = watched_fd->cups_poll;
 
266
+
 
267
+  cupsArrayRemove (watched_fd->watches, watch);
 
268
+  free (watch);
 
269
+
 
270
+  if (!watched_fd_add_select (watched_fd))
 
271
+  {
 
272
+    /* No more watches */
 
273
+    cupsArrayRemove (cups_poll->watched_fds, watched_fd);
 
274
+    free (watched_fd);
 
275
+  }
 
276
+}
 
277
+
 
278
+
 
279
+/*
 
280
+ * 'watch_update' - Update watched events for a file descriptor
 
281
+ */
 
282
+
 
283
+static void
 
284
+watch_update (AvahiWatch *watch,
 
285
+             AvahiWatchEvent events)
 
286
+{
 
287
+  watch->events = events;
 
288
+  watched_fd_add_select (watch->watched_fd);
 
289
+}
 
290
+
 
291
+
 
292
+/*
 
293
+ * 'watch_get_events' - Get events that happened for a file descriptor
 
294
+ */
 
295
+
 
296
+static AvahiWatchEvent
 
297
+watch_get_events (AvahiWatch *watch)
 
298
+{
 
299
+  return (watch->watched_fd->occurred);
 
300
+}
 
301
+
 
302
+
 
303
+/*
 
304
+ * 'timeout_cb()' - Run a timed Avahi callback
 
305
+ */
 
306
+
 
307
+static void
 
308
+timeout_cb (cupsd_timeout_t *cupsd_timeout, void *userdata)
 
309
+{
 
310
+  AvahiTimeout *timeout = userdata;
 
311
+  (timeout->callback) (timeout, timeout->userdata);
 
312
+}
 
313
+
 
314
+
 
315
+/*
 
316
+ * 'timeout_new' - Set a wakeup time
 
317
+ */
 
318
+
 
319
+static AvahiTimeout *
 
320
+timeout_new (const AvahiPoll *api,
 
321
+            const struct timeval *tv,
 
322
+            AvahiTimeoutCallback callback,
 
323
+            void *userdata)
 
324
+{
 
325
+  AvahiTimeout *timeout;
 
326
+  AvahiCupsPoll *cups_poll = api->userdata;
 
327
+
 
328
+  timeout = malloc(sizeof(AvahiTimeout));
 
329
+  if (timeout == NULL)
 
330
+    return (NULL);
 
331
+
 
332
+  timeout->cups_poll = cups_poll;
 
333
+  timeout->callback = callback;
 
334
+  timeout->userdata = userdata;
 
335
+  timeout->cupsd_timeout = cupsdAddTimeout (tv,
 
336
+                                           (cupsd_timeoutfunc_t)timeout_cb,
 
337
+                                           timeout);
 
338
+  cupsArrayAdd (cups_poll->timeouts, timeout);
 
339
+  return (timeout);
 
340
+}
 
341
+
 
342
+
 
343
+/*
 
344
+ * 'timeout_update' - Update the expiration time for a timeout
 
345
+ */
 
346
+
 
347
+static void
 
348
+timeout_update (AvahiTimeout *timeout,
 
349
+               const struct timeval *tv)
 
350
+{
 
351
+  cupsdUpdateTimeout (timeout->cupsd_timeout, tv);
 
352
+}
 
353
+
 
354
+
 
355
+/*
 
356
+ * ' timeout_free' - Free a timeout
 
357
+ */
 
358
+
 
359
+static void
 
360
+timeout_free (AvahiTimeout *timeout)
 
361
+{
 
362
+  cupsArrayRemove (timeout->cups_poll->timeouts, timeout);
 
363
+  cupsdRemoveTimeout (timeout->cupsd_timeout);
 
364
+  free (timeout);
 
365
+}
 
366
+
 
367
+
 
368
+/*
 
369
+ * 'compare_watched_fds' - Compare watched file descriptors for array sorting
 
370
+ */
 
371
+static int
 
372
+compare_watched_fds(cupsd_watched_fd_t *p0,
 
373
+                   cupsd_watched_fd_t *p1)
 
374
+{
 
375
+  /*
 
376
+   * Compare by fd (no two elements have the same fd)
 
377
+   */
 
378
+
 
379
+  if (p0->fd == p1->fd)
 
380
+    return 0;
 
381
+
 
382
+  return (p0->fd < p1->fd ? -1 : 1);
 
383
+}
 
384
+
 
385
+
 
386
+/*
 
387
+ * 'avahi_cups_poll_new' - Create a new Avahi main loop object for CUPS
 
388
+ */
 
389
+
 
390
+AvahiCupsPoll *
 
391
+avahi_cups_poll_new (void)
 
392
+{
 
393
+  AvahiCupsPoll *cups_poll = malloc(sizeof(AvahiCupsPoll));
 
394
+  if (cups_poll == NULL)
 
395
+    return (NULL);
 
396
+
 
397
+  cups_poll->watched_fds = cupsArrayNew ((cups_array_func_t)compare_watched_fds,
 
398
+                                        NULL);
 
399
+  cups_poll->timeouts = cupsArrayNew (NULL, NULL);
 
400
+
 
401
+  cups_poll->api.userdata = cups_poll;
 
402
+  cups_poll->api.watch_new = watch_new;
 
403
+  cups_poll->api.watch_free = watch_free;
 
404
+  cups_poll->api.watch_update = watch_update;
 
405
+  cups_poll->api.watch_get_events = watch_get_events;
 
406
+
 
407
+  cups_poll->api.timeout_new = timeout_new;
 
408
+  cups_poll->api.timeout_update = timeout_update;
 
409
+  cups_poll->api.timeout_free = timeout_free;
 
410
+
 
411
+  return (cups_poll);
 
412
+}
 
413
+
 
414
+
 
415
+/*
 
416
+ * 'avahi_cups_poll_free' - Free an Avahi main loop object for CUPS
 
417
+ */
 
418
+void
 
419
+avahi_cups_poll_free (AvahiCupsPoll *cups_poll)
 
420
+{
 
421
+  cupsd_watched_fd_t *watched_fd;
 
422
+
 
423
+  for (watched_fd = (cupsd_watched_fd_t*)cupsArrayFirst(cups_poll->watched_fds);
 
424
+       watched_fd;
 
425
+       watched_fd = (cupsd_watched_fd_t*)cupsArrayNext(cups_poll->watched_fds))
 
426
+    cupsArrayClear (watched_fd->watches);
 
427
+
 
428
+  cupsArrayClear (cups_poll->watched_fds);
 
429
+  cupsArrayClear (cups_poll->timeouts);
 
430
+}
 
431
+
 
432
+
 
433
+/*
 
434
+ * 'avahi_cups_poll_get' - Get the abstract poll API structure
 
435
+ */
 
436
+
 
437
+const AvahiPoll *
 
438
+avahi_cups_poll_get (AvahiCupsPoll *cups_poll)
 
439
+{
 
440
+  return (&cups_poll->api);
 
441
+}
 
442
+
 
443
+
 
444
+#endif /* HAVE_AVAHI ... from top of file */
 
445
+
 
446
+/*
 
447
+ * End of "$Id$".
 
448
+ */
 
449
--- /dev/null
 
450
+++ b/scheduler/avahi.h
 
451
@@ -0,0 +1,69 @@
 
452
+/*
 
453
+ * "$Id$"
 
454
+ *
 
455
+ *   Avahi poll implementation for the CUPS scheduler.
 
456
+ *
 
457
+ *   Copyright (C) 2010, 2011 Red Hat, Inc.
 
458
+ *   Authors:
 
459
+ *    Tim Waugh <twaugh@redhat.com>
 
460
+ *
 
461
+ *   Redistribution and use in source and binary forms, with or without
 
462
+ *   modification, are permitted provided that the following conditions
 
463
+ *   are met:
 
464
+ *
 
465
+ *   Redistributions of source code must retain the above copyright
 
466
+ *   notice, this list of conditions and the following disclaimer.
 
467
+ *
 
468
+ *   Redistributions in binary form must reproduce the above copyright
 
469
+ *   notice, this list of conditions and the following disclaimer in the
 
470
+ *   documentation and/or other materials provided with the distribution.
 
471
+ *
 
472
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
473
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
474
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 
475
+ *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 
476
+ *   COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 
477
+ *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
478
+ *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
479
+ *   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
480
+ *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 
481
+ *   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
482
+ *   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 
483
+ *   OF THE POSSIBILITY OF SUCH DAMAGE.
 
484
+ */
 
485
+
 
486
+#include <config.h>
 
487
+
 
488
+#ifdef HAVE_AVAHI
 
489
+#  include <avahi-client/client.h>
 
490
+#  include <avahi-client/publish.h>
 
491
+#endif /* HAVE_AVAHI */
 
492
+
 
493
+#ifdef HAVE_AUTHORIZATION_H
 
494
+#  include <Security/Authorization.h>
 
495
+#endif /* HAVE_AUTHORIZATION_H */
 
496
+
 
497
+
 
498
+#ifdef HAVE_AVAHI
 
499
+typedef struct
 
500
+{
 
501
+    AvahiPoll api;
 
502
+    cups_array_t *watched_fds;
 
503
+    cups_array_t *timeouts;
 
504
+} AvahiCupsPoll;
 
505
+#endif /* HAVE_AVAHI */
 
506
+
 
507
+/*
 
508
+ * Prototypes...
 
509
+ */
 
510
+
 
511
+#ifdef HAVE_AVAHI
 
512
+extern AvahiCupsPoll * avahi_cups_poll_new(void);
 
513
+extern void            avahi_cups_poll_free(AvahiCupsPoll *cups_poll);
 
514
+extern const AvahiPoll *avahi_cups_poll_get(AvahiCupsPoll *cups_poll);
 
515
+#endif /* HAVE_AVAHI */
 
516
+
 
517
+
 
518
+/*
 
519
+ * End of "$Id$".
 
520
+ */
 
521
--- a/scheduler/cupsd.h
 
522
+++ b/scheduler/cupsd.h
 
523
@@ -119,6 +119,7 @@
 
524
 #include "colorman.h"
 
525
 #include "conf.h"
 
526
 #include "banners.h"
 
527
+#include "avahi.h"
 
528
 #include "dirsvc.h"
 
529
 #include "network.h"
 
530
 #include "subscriptions.h"
 
531
@@ -139,6 +140,15 @@
 
532
 
 
533
 typedef void (*cupsd_selfunc_t)(void *data);
 
534
 
 
535
+#ifdef HAVE_AVAHI
 
536
+/*
 
537
+ * Timeout callback function type...
 
538
+ */
 
539
+
 
540
+typedef struct _cupsd_timeout_s cupsd_timeout_t;
 
541
+typedef void (*cupsd_timeoutfunc_t)(cupsd_timeout_t *timeout, void *data);
 
542
+#endif /* HAVE_AVAHI */
 
543
+
 
544
 
 
545
 /*
 
546
  * Globals...
 
547
@@ -165,6 +175,11 @@
 
548
                                        /* Running from launchd */
 
549
 #endif /* HAVE_LAUNCH_H */
 
550
 
 
551
+#ifdef HAVE_AVAHI
 
552
+VAR cups_array_t *Timeouts;            /* Timed callbacks for main loop */
 
553
+#endif /* HAVE_AVAHI */
 
554
+
 
555
+
 
556
 
 
557
 /*
 
558
  * Prototypes...
 
559
@@ -229,6 +244,17 @@
 
560
 extern void            cupsdStartServer(void);
 
561
 extern void            cupsdStopServer(void);
 
562
 
 
563
+#ifdef HAVE_AVAHI
 
564
+extern void     cupsdInitTimeouts(void);
 
565
+extern cupsd_timeout_t *cupsdAddTimeout (const struct timeval *tv,
 
566
+                                        cupsd_timeoutfunc_t cb,
 
567
+                                        void *data);
 
568
+extern cupsd_timeout_t *cupsdNextTimeout (long *delay);
 
569
+extern void     cupsdRunTimeout (cupsd_timeout_t *timeout);
 
570
+extern void     cupsdUpdateTimeout (cupsd_timeout_t *timeout,
 
571
+                                   const struct timeval *tv);
 
572
+extern void     cupsdRemoveTimeout (cupsd_timeout_t *timeout);
 
573
+#endif /* HAVE_AVAHI */
 
574
 
 
575
 /*
 
576
  * End of "$Id: cupsd.h 10996 2013-05-29 11:51:34Z msweet $".
 
577
--- a/scheduler/dirsvc.c
 
578
+++ b/scheduler/dirsvc.c
 
579
@@ -212,7 +212,7 @@
 
580
     }
 
581
 
 
582
 #  else /* HAVE_AVAHI */
 
583
-    if ((DNSSDMaster = avahi_threaded_poll_new()) == NULL)
 
584
+    if ((DNSSDMaster = avahi_cups_poll_new()) == NULL)
 
585
     {
 
586
       cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create DNS-SD thread.");
 
587
 
 
588
@@ -223,7 +223,7 @@
 
589
     {
 
590
       int error;                       /* Error code, if any */
 
591
 
 
592
-      DNSSDClient = avahi_client_new(avahi_threaded_poll_get(DNSSDMaster), 0,
 
593
+      DNSSDClient = avahi_client_new(avahi_cups_poll_get(DNSSDMaster), 0,
 
594
                                      NULL, NULL, &error);
 
595
 
 
596
       if (DNSSDClient == NULL)
 
597
@@ -235,11 +235,9 @@
 
598
         if (FatalErrors & CUPSD_FATAL_BROWSE)
 
599
          cupsdEndProcess(getpid(), 0);
 
600
 
 
601
-        avahi_threaded_poll_free(DNSSDMaster);
 
602
+        avahi_cups_poll_free(DNSSDMaster);
 
603
         DNSSDMaster = NULL;
 
604
       }
 
605
-      else
 
606
-       avahi_threaded_poll_start(DNSSDMaster);
 
607
     }
 
608
 #  endif /* HAVE_DNSSD */
 
609
 
 
610
@@ -754,9 +752,7 @@
 
611
   DNSServiceRefDeallocate(*srv);
 
612
 
 
613
 #  else /* HAVE_AVAHI */
 
614
-  avahi_threaded_poll_lock(DNSSDMaster);
 
615
   avahi_entry_group_free(*srv);
 
616
-  avahi_threaded_poll_unlock(DNSSDMaster);
 
617
 #  endif /* HAVE_DNSSD */
 
618
 
 
619
   *srv = NULL;
 
620
@@ -1051,14 +1047,10 @@
 
621
   (void)commit;
 
622
 
 
623
 #  else /* HAVE_AVAHI */
 
624
-  avahi_threaded_poll_lock(DNSSDMaster);
 
625
-
 
626
   if (!*srv)
 
627
     *srv = avahi_entry_group_new(DNSSDClient, dnssdRegisterCallback, NULL);
 
628
   if (!*srv)
 
629
   {
 
630
-    avahi_threaded_poll_unlock(DNSSDMaster);
 
631
-
 
632
     cupsdLogMessage(CUPSD_LOG_WARN, "DNS-SD registration of \"%s\" failed: %s",
 
633
                     name, dnssdErrorString(avahi_client_errno(DNSSDClient)));
 
634
     return (0);
 
635
@@ -1173,8 +1165,6 @@
 
636
       cupsdLogMessage(CUPSD_LOG_DEBUG, "DNS-SD commit of \"%s\" failed.",
 
637
                       name);
 
638
   }
 
639
-
 
640
-  avahi_threaded_poll_unlock(DNSSDMaster);
 
641
 #  endif /* HAVE_DNSSD */
 
642
 
 
643
   if (error)
 
644
@@ -1341,12 +1331,10 @@
 
645
   DNSSDMaster = NULL;
 
646
 
 
647
 #  else /* HAVE_AVAHI */
 
648
-  avahi_threaded_poll_stop(DNSSDMaster);
 
649
-
 
650
   avahi_client_free(DNSSDClient);
 
651
   DNSSDClient = NULL;
 
652
 
 
653
-  avahi_threaded_poll_free(DNSSDMaster);
 
654
+  avahi_cups_poll_free(DNSSDMaster);
 
655
   DNSSDMaster = NULL;
 
656
 #  endif /* HAVE_DNSSD */
 
657
 
 
658
--- a/scheduler/dirsvc.h
 
659
+++ b/scheduler/dirsvc.h
 
660
@@ -51,7 +51,7 @@
 
661
 VAR DNSServiceRef      DNSSDMaster     VALUE(NULL);
 
662
                                        /* Master DNS-SD service reference */
 
663
 #  else /* HAVE_AVAHI */
 
664
-VAR AvahiThreadedPoll  *DNSSDMaster    VALUE(NULL);
 
665
+VAR AvahiCupsPoll      *DNSSDMaster    VALUE(NULL);
 
666
                                        /* Master polling interface for Avahi */
 
667
 VAR AvahiClient                *DNSSDClient    VALUE(NULL);
 
668
                                        /* Client information */
 
669
--- a/scheduler/main.c
 
670
+++ b/scheduler/main.c
 
671
@@ -148,6 +148,10 @@
 
672
   int                  launchd_idle_exit;
 
673
                                        /* Idle exit on select timeout? */
 
674
 #endif /* HAVE_LAUNCHD */
 
675
+#ifdef HAVE_AVAHI
 
676
+  cupsd_timeout_t      *tmo;           /* Next scheduled timed callback */
 
677
+  long                 tmo_delay;      /* Time before it must be called */
 
678
+#endif /* HAVE_AVAHI */
 
679
 
 
680
 
 
681
 #ifdef HAVE_GETEUID
 
682
@@ -572,6 +576,14 @@
 
683
 
 
684
   httpInitialize();
 
685
 
 
686
+#ifdef HAVE_AVAHI
 
687
+ /*
 
688
+  * Initialize timed callback structures.
 
689
+  */
 
690
+
 
691
+  cupsdInitTimeouts();
 
692
+#endif /* HAVE_AVAHI */
 
693
+
 
694
   cupsdStartServer();
 
695
 
 
696
  /*
 
697
@@ -889,6 +901,16 @@
 
698
     }
 
699
 #endif /* __APPLE__ */
 
700
 
 
701
+#ifdef HAVE_AVAHI
 
702
+   /*
 
703
+    * If a timed callback is due, run it.
 
704
+    */
 
705
+
 
706
+    tmo = cupsdNextTimeout (&tmo_delay);
 
707
+    if (tmo && tmo_delay == 0)
 
708
+      cupsdRunTimeout (tmo);
 
709
+#endif /* HAVE_AVAHI */
 
710
+
 
711
 #ifndef __APPLE__
 
712
    /*
 
713
     * Update the network interfaces once a minute...
 
714
@@ -1804,6 +1826,10 @@
 
715
   cupsd_job_t          *job;           /* Job information */
 
716
   cupsd_subscription_t *sub;           /* Subscription information */
 
717
   const char           *why;           /* Debugging aid */
 
718
+#ifdef HAVE_AVAHI
 
719
+  cupsd_timeout_t      *tmo;           /* Timed callback */
 
720
+  long                 tmo_delay;      /* Seconds before calling it */
 
721
+#endif /* HAVE_AVAHI */
 
722
 
 
723
 
 
724
   cupsdLogMessage(CUPSD_LOG_DEBUG2, "select_timeout: JobHistoryUpdate=%ld",
 
725
@@ -1849,6 +1875,19 @@
 
726
   }
 
727
 #endif /* __APPLE__ */
 
728
 
 
729
+#ifdef HAVE_AVAHI
 
730
+ /*
 
731
+  * See if there are any scheduled timed callbacks to run.
 
732
+  */
 
733
+
 
734
+  if ((tmo = cupsdNextTimeout(&tmo_delay)) != NULL &&
 
735
+      (now + tmo_delay) < timeout)
 
736
+  {
 
737
+    timeout = tmo_delay;
 
738
+    why = "run a timed callback";
 
739
+  }
 
740
+#endif /* HAVE_AVAHI */
 
741
+
 
742
  /*
 
743
   * Check whether we are accepting new connections...
 
744
   */
 
745
--- a/scheduler/Makefile
 
746
+++ b/scheduler/Makefile
 
747
@@ -17,6 +17,7 @@
 
748
 
 
749
 CUPSDOBJS =    \
 
750
                auth.o \
 
751
+               avahi.o \
 
752
                banners.o \
 
753
                cert.o \
 
754
                classes.o \
 
755
@@ -41,6 +42,7 @@
 
756
                statbuf.o \
 
757
                subscriptions.o \
 
758
                sysman.o \
 
759
+               timeout.o \
 
760
                tls.o
 
761
 LIBOBJS =      \
 
762
                filter.o \
 
763
--- /dev/null
 
764
+++ b/scheduler/timeout.c
 
765
@@ -0,0 +1,235 @@
 
766
+/*
 
767
+ * "$Id$"
 
768
+ *
 
769
+ *   Timeout functions for the Common UNIX Printing System (CUPS).
 
770
+ *
 
771
+ *   Copyright (C) 2010, 2011 Red Hat, Inc.
 
772
+ *   Authors:
 
773
+ *     Tim Waugh <twaugh@redhat.com>
 
774
+ *
 
775
+ *   Redistribution and use in source and binary forms, with or without
 
776
+ *   modification, are permitted provided that the following conditions
 
777
+ *   are met:
 
778
+ *
 
779
+ *   Redistributions of source code must retain the above copyright
 
780
+ *   notice, this list of conditions and the following disclaimer.
 
781
+ *
 
782
+ *   Redistributions in binary form must reproduce the above copyright
 
783
+ *   notice, this list of conditions and the following disclaimer in the
 
784
+ *   documentation and/or other materials provided with the distribution.
 
785
+ *
 
786
+ *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
787
+ *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
788
+ *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 
789
+ *   FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 
790
+ *   COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 
791
+ *   INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
792
+ *   (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
793
+ *   SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
794
+ *   HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 
795
+ *   STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 
796
+ *   ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 
797
+ *   OF THE POSSIBILITY OF SUCH DAMAGE.
 
798
+ *
 
799
+ * Contents:
 
800
+ *
 
801
+ *   cupsdInitTimeouts()  - Initialise timeout structure.
 
802
+ *   cupsdAddTimeout()    - Add a timed callback.
 
803
+ *   cupsdNextTimeout()   - Find the next enabled timed callback.
 
804
+ *   cupsdUpdateTimeout() - Adjust the time of a timed callback or disable it.
 
805
+ *   cupsdRemoveTimeout() - Discard a timed callback.
 
806
+ *   compare_timeouts()   - Compare timed callbacks for array sorting.
 
807
+ */
 
808
+
 
809
+#include <config.h>
 
810
+
 
811
+#ifdef HAVE_AVAHI /* Applies to entire file... */
 
812
+
 
813
+/*
 
814
+ * Include necessary headers...
 
815
+ */
 
816
+
 
817
+#include "cupsd.h"
 
818
+
 
819
+#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
 
820
+#  include <malloc.h>
 
821
+#endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
 
822
+
 
823
+#ifdef HAVE_AVAHI
 
824
+#  include <avahi-common/timeval.h>
 
825
+#endif /* HAVE_AVAHI */
 
826
+
 
827
+
 
828
+struct _cupsd_timeout_s
 
829
+{
 
830
+  struct timeval when;
 
831
+  int enabled;
 
832
+  cupsd_timeoutfunc_t callback;
 
833
+  void *data;
 
834
+};
 
835
+
 
836
+/*
 
837
+ * Local functions...
 
838
+ */
 
839
+
 
840
+/*
 
841
+ * 'compare_timeouts()' - Compare timed callbacks for array sorting.
 
842
+ */
 
843
+
 
844
+static int
 
845
+compare_addrs (void *p0, void *p1)
 
846
+{
 
847
+  if (p0 == p1)
 
848
+    return (0);
 
849
+  if (p0 < p1)
 
850
+    return (-1);
 
851
+  return (1);
 
852
+}
 
853
+
 
854
+static int
 
855
+compare_timeouts (cupsd_timeout_t *p0, cupsd_timeout_t *p1)
 
856
+{
 
857
+  int addrsdiff = compare_addrs (p0, p1);
 
858
+  int tvdiff;
 
859
+
 
860
+  if (addrsdiff == 0)
 
861
+    return (0);
 
862
+
 
863
+  if (!p0->enabled || !p1->enabled)
 
864
+  {
 
865
+    if (!p0->enabled && !p1->enabled)
 
866
+      return (addrsdiff);
 
867
+
 
868
+    return (p0->enabled ? -1 : 1);
 
869
+  }
 
870
+
 
871
+  tvdiff = avahi_timeval_compare (&p0->when, &p1->when);
 
872
+  if (tvdiff != 0)
 
873
+    return (tvdiff);
 
874
+
 
875
+  return (addrsdiff);
 
876
+}
 
877
+
 
878
+
 
879
+/*
 
880
+ * 'cupsdInitTimeouts()' - Initialise timeout structures.
 
881
+ */
 
882
+
 
883
+void
 
884
+cupsdInitTimeouts(void)
 
885
+{
 
886
+  Timeouts = cupsArrayNew ((cups_array_func_t)compare_timeouts, NULL);
 
887
+}
 
888
+
 
889
+
 
890
+/*
 
891
+ * 'cupsdAddTimeout()' - Add a timed callback.
 
892
+ */
 
893
+
 
894
+cupsd_timeout_t *                              /* O - Timeout handle */
 
895
+cupsdAddTimeout(const struct timeval *tv,      /* I - Absolute time */
 
896
+               cupsd_timeoutfunc_t cb,         /* I - Callback function */
 
897
+               void *data)                     /* I - User data */
 
898
+{
 
899
+  cupsd_timeout_t *timeout;
 
900
+
 
901
+  timeout = malloc (sizeof(cupsd_timeout_t));
 
902
+  if (timeout != NULL)
 
903
+  {
 
904
+    timeout->enabled = (tv != NULL);
 
905
+    if (tv)
 
906
+    {
 
907
+      timeout->when.tv_sec = tv->tv_sec;
 
908
+      timeout->when.tv_usec = tv->tv_usec;
 
909
+    }
 
910
+
 
911
+    timeout->callback = cb;
 
912
+    timeout->data = data;
 
913
+    cupsArrayAdd (Timeouts, timeout);
 
914
+  }
 
915
+
 
916
+  return timeout;
 
917
+}
 
918
+
 
919
+
 
920
+/*
 
921
+ * 'cupsdNextTimeout()' - Find the next enabled timed callback.
 
922
+ */
 
923
+
 
924
+cupsd_timeout_t *              /* O - Next enabled timeout or NULL */
 
925
+cupsdNextTimeout(long *delay)  /* O - Seconds before scheduled */
 
926
+{
 
927
+  cupsd_timeout_t *first = cupsArrayFirst (Timeouts);
 
928
+  struct timeval curtime;
 
929
+
 
930
+  if (first && !first->enabled)
 
931
+    first = NULL;
 
932
+
 
933
+  if (first && delay)
 
934
+  {
 
935
+    gettimeofday (&curtime, NULL);
 
936
+    if (avahi_timeval_compare (&curtime, &first->when) > 0)
 
937
+    {
 
938
+      *delay = 0;
 
939
+    } else {
 
940
+      *delay = 1 + first->when.tv_sec - curtime.tv_sec;
 
941
+      if (first->when.tv_usec < curtime.tv_usec)
 
942
+       (*delay)--;
 
943
+    }
 
944
+  }
 
945
+
 
946
+  return (first);
 
947
+}
 
948
+
 
949
+
 
950
+/*
 
951
+ * 'cupsdRunTimeout()' - Run a timed callback.
 
952
+ */
 
953
+
 
954
+void
 
955
+cupsdRunTimeout(cupsd_timeout_t *timeout)      /* I - Timeout */
 
956
+{
 
957
+  if (!timeout)
 
958
+    return;
 
959
+  timeout->enabled = 0;
 
960
+  if (!timeout->callback)
 
961
+    return;
 
962
+  timeout->callback (timeout, timeout->data);
 
963
+}
 
964
+
 
965
+/*
 
966
+ * 'cupsdUpdateTimeout()' - Adjust the time of a timed callback or disable it.
 
967
+ */
 
968
+
 
969
+void
 
970
+cupsdUpdateTimeout(cupsd_timeout_t *timeout,   /* I - Timeout */
 
971
+                  const struct timeval *tv)    /* I - Absolute time or NULL */
 
972
+{
 
973
+  cupsArrayRemove (Timeouts, timeout);
 
974
+  timeout->enabled = (tv != NULL);
 
975
+  if (tv)
 
976
+  {
 
977
+    timeout->when.tv_sec = tv->tv_sec;
 
978
+    timeout->when.tv_usec = tv->tv_usec;
 
979
+  }
 
980
+  cupsArrayAdd (Timeouts, timeout);
 
981
+}
 
982
+
 
983
+
 
984
+/*
 
985
+ * 'cupsdRemoveTimeout()' - Discard a timed callback.
 
986
+ */
 
987
+
 
988
+void
 
989
+cupsdRemoveTimeout(cupsd_timeout_t *timeout)   /* I - Timeout */
 
990
+{
 
991
+  cupsArrayRemove (Timeouts, timeout);
 
992
+  free (timeout);
 
993
+}
 
994
+
 
995
+
 
996
+#endif /* HAVE_AVAHI ... from top of file */
 
997
+
 
998
+/*
 
999
+ * End of "$Id$".
 
1000
+ */