1 diff -up cups-2.0.2/scheduler/avahi.c.KUoOri cups-2.0.2/scheduler/avahi.c
2 --- cups-2.0.2/scheduler/avahi.c.KUoOri 2015-02-10 13:47:38.620396709 +0100
3 +++ cups-2.0.2/scheduler/avahi.c 2015-02-10 13:47:38.620396709 +0100
8 + * Avahi poll implementation for the CUPS scheduler.
10 + * Copyright (C) 2010, 2011 Red Hat, Inc.
12 + * Tim Waugh <twaugh@redhat.com>
14 + * Redistribution and use in source and binary forms, with or without
15 + * modification, are permitted provided that the following conditions
18 + * Redistributions of source code must retain the above copyright
19 + * notice, this list of conditions and the following disclaimer.
21 + * Redistributions in binary form must reproduce the above copyright
22 + * notice, this list of conditions and the following disclaimer in the
23 + * documentation and/or other materials provided with the distribution.
25 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
28 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
29 + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
30 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
32 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
34 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
36 + * OF THE POSSIBILITY OF SUCH DAMAGE.
40 + * watch_read_cb - Read callback for file descriptor
41 + * watch_write_cb - Write callback for file descriptor
42 + * watched_fd_add_select() - Call cupsdAddSelect() as needed
43 + * watch_new() - Create a new file descriptor watch
44 + * watch_free() - Free a file descriptor watch
45 + * watch_update() - Update watched events for a file descriptor
46 + * watch_get_events() - Get events that happened for a file descriptor
47 + * timeout_cb() - Run a timed Avahi callback
48 + * timeout_new() - Set a wakeup time
49 + * timeout_update() - Update the expiration time for a timeout
50 + * timeout_free() - Free a timeout
51 + * compare_watched_fds() - Compare watched file descriptors for array sorting
52 + * avahi_cups_poll_new() - Create a new Avahi main loop object for CUPS
53 + * avahi_cups_poll_free() - Free an Avahi main loop object for CUPS
54 + * avahi_cups_poll_get() - Get the abstract poll API structure
59 +#ifdef HAVE_AVAHI /* Applies to entire file... */
62 + * Include necessary headers...
67 +#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
69 +#endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
72 +# include <avahi-common/timeval.h>
73 +#endif /* HAVE_AVAHI */
78 + AvahiCupsPoll *cups_poll;
81 + AvahiWatchEvent occurred;
82 + cups_array_t *watches;
83 +} cupsd_watched_fd_t;
87 + cupsd_watched_fd_t *watched_fd;
89 + AvahiWatchEvent events;
90 + AvahiWatchCallback callback;
96 + AvahiCupsPoll *cups_poll;
97 + AvahiTimeoutCallback callback;
99 + cupsd_timeout_t *cupsd_timeout;
103 + * Local functions...
106 +static AvahiWatch * watch_new(const AvahiPoll *api,
108 + AvahiWatchEvent events,
109 + AvahiWatchCallback callback,
111 +static void watch_free(AvahiWatch *watch);
112 +static void watch_update(AvahiWatch *watch,
113 + AvahiWatchEvent events);
114 +static AvahiWatchEvent watch_get_events(AvahiWatch *watch);
118 + * 'watch_read_cb' - Read callback for file descriptor
122 +watch_read_cb (void *userdata)
125 + cupsd_watched_fd_t *watched_fd = userdata;
126 + watched_fd->occurred |= AVAHI_WATCH_IN;
127 + for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
129 + watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
131 + if (watch->events & watched_fd->occurred)
133 + (watch->callback) (watch, watched_fd->fd,
134 + AVAHI_WATCH_IN, watch->userdata);
135 + watched_fd->occurred &= ~AVAHI_WATCH_IN;
143 + * 'watch_write_cb' - Write callback for file descriptor
147 +watch_write_cb (void *userdata)
150 + cupsd_watched_fd_t *watched_fd = userdata;
151 + watched_fd->occurred |= AVAHI_WATCH_OUT;
152 + for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
154 + watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
156 + if (watch->events & watched_fd->occurred)
158 + (watch->callback) (watch, watched_fd->fd,
159 + AVAHI_WATCH_OUT, watch->userdata);
160 + watched_fd->occurred &= ~AVAHI_WATCH_OUT;
168 + * 'watched_fd_add_select' - Call cupsdAddSelect() as needed
171 +static int /* O - Watches? */
172 +watched_fd_add_select (cupsd_watched_fd_t *watched_fd)
175 + cupsd_selfunc_t read_cb = NULL, write_cb = NULL;
176 + int any_watches = 0;
178 + for (watch = (AvahiWatch *)cupsArrayFirst(watched_fd->watches);
180 + watch = (AvahiWatch *)cupsArrayNext(watched_fd->watches))
183 + if (watch->events & (AVAHI_WATCH_IN |
187 + read_cb = (cupsd_selfunc_t)watch_read_cb;
188 + if (write_cb != NULL)
192 + if (watch->events & AVAHI_WATCH_OUT)
194 + write_cb = (cupsd_selfunc_t)watch_write_cb;
195 + if (read_cb != NULL)
200 + if (read_cb || write_cb)
201 + cupsdAddSelect (watched_fd->fd, read_cb, write_cb, watched_fd);
203 + cupsdRemoveSelect (watched_fd->fd);
205 + return (any_watches);
209 + * 'watch_new' - Create a new file descriptor watch
213 +watch_new (const AvahiPoll *api,
215 + AvahiWatchEvent events,
216 + AvahiWatchCallback callback,
219 + cupsd_watched_fd_t key, *watched_fd;
220 + AvahiCupsPoll *cups_poll = api->userdata;
221 + AvahiWatch *watch = malloc(sizeof(AvahiWatch));
225 + watch->events = events;
226 + watch->callback = callback;
227 + watch->userdata = userdata;
230 + watched_fd = cupsArrayFind (cups_poll->watched_fds, &key);
231 + if (watched_fd == NULL)
233 + watched_fd = malloc(sizeof(cupsd_watched_fd_t));
234 + if (watched_fd == NULL)
240 + watched_fd->fd = fd;
241 + watched_fd->occurred = 0;
242 + watched_fd->cups_poll = cups_poll;
243 + watched_fd->watches = cupsArrayNew (NULL, NULL);
244 + cupsArrayAdd (cups_poll->watched_fds, watched_fd);
247 + watch->watched_fd = watched_fd;
248 + cupsArrayAdd(watched_fd->watches, watch);
249 + watched_fd_add_select (watched_fd);
255 + * 'watch_free' - Free a file descriptor watch
259 +watch_free (AvahiWatch *watch)
261 + cupsd_watched_fd_t *watched_fd = watch->watched_fd;
262 + AvahiCupsPoll *cups_poll = watched_fd->cups_poll;
264 + cupsArrayRemove (watched_fd->watches, watch);
267 + if (!watched_fd_add_select (watched_fd))
269 + /* No more watches */
270 + cupsArrayRemove (cups_poll->watched_fds, watched_fd);
277 + * 'watch_update' - Update watched events for a file descriptor
281 +watch_update (AvahiWatch *watch,
282 + AvahiWatchEvent events)
284 + watch->events = events;
285 + watched_fd_add_select (watch->watched_fd);
290 + * 'watch_get_events' - Get events that happened for a file descriptor
293 +static AvahiWatchEvent
294 +watch_get_events (AvahiWatch *watch)
296 + return (watch->watched_fd->occurred);
301 + * 'timeout_cb()' - Run a timed Avahi callback
305 +timeout_cb (cupsd_timeout_t *cupsd_timeout, void *userdata)
307 + AvahiTimeout *timeout = userdata;
308 + (timeout->callback) (timeout, timeout->userdata);
313 + * 'timeout_new' - Set a wakeup time
316 +static AvahiTimeout *
317 +timeout_new (const AvahiPoll *api,
318 + const struct timeval *tv,
319 + AvahiTimeoutCallback callback,
322 + AvahiTimeout *timeout;
323 + AvahiCupsPoll *cups_poll = api->userdata;
325 + timeout = malloc(sizeof(AvahiTimeout));
326 + if (timeout == NULL)
329 + timeout->cups_poll = cups_poll;
330 + timeout->callback = callback;
331 + timeout->userdata = userdata;
332 + timeout->cupsd_timeout = cupsdAddTimeout (tv,
333 + (cupsd_timeoutfunc_t)timeout_cb,
335 + cupsArrayAdd (cups_poll->timeouts, timeout);
341 + * 'timeout_update' - Update the expiration time for a timeout
345 +timeout_update (AvahiTimeout *timeout,
346 + const struct timeval *tv)
348 + cupsdUpdateTimeout (timeout->cupsd_timeout, tv);
353 + * ' timeout_free' - Free a timeout
357 +timeout_free (AvahiTimeout *timeout)
359 + cupsArrayRemove (timeout->cups_poll->timeouts, timeout);
360 + cupsdRemoveTimeout (timeout->cupsd_timeout);
366 + * 'compare_watched_fds' - Compare watched file descriptors for array sorting
369 +compare_watched_fds(cupsd_watched_fd_t *p0,
370 + cupsd_watched_fd_t *p1)
373 + * Compare by fd (no two elements have the same fd)
376 + if (p0->fd == p1->fd)
379 + return (p0->fd < p1->fd ? -1 : 1);
384 + * 'avahi_cups_poll_new' - Create a new Avahi main loop object for CUPS
388 +avahi_cups_poll_new (void)
390 + AvahiCupsPoll *cups_poll = malloc(sizeof(AvahiCupsPoll));
391 + if (cups_poll == NULL)
394 + cups_poll->watched_fds = cupsArrayNew ((cups_array_func_t)compare_watched_fds,
396 + cups_poll->timeouts = cupsArrayNew (NULL, NULL);
398 + cups_poll->api.userdata = cups_poll;
399 + cups_poll->api.watch_new = watch_new;
400 + cups_poll->api.watch_free = watch_free;
401 + cups_poll->api.watch_update = watch_update;
402 + cups_poll->api.watch_get_events = watch_get_events;
404 + cups_poll->api.timeout_new = timeout_new;
405 + cups_poll->api.timeout_update = timeout_update;
406 + cups_poll->api.timeout_free = timeout_free;
408 + return (cups_poll);
413 + * 'avahi_cups_poll_free' - Free an Avahi main loop object for CUPS
416 +avahi_cups_poll_free (AvahiCupsPoll *cups_poll)
418 + cupsd_watched_fd_t *watched_fd;
420 + for (watched_fd = (cupsd_watched_fd_t*)cupsArrayFirst(cups_poll->watched_fds);
422 + watched_fd = (cupsd_watched_fd_t*)cupsArrayNext(cups_poll->watched_fds))
423 + cupsArrayClear (watched_fd->watches);
425 + cupsArrayClear (cups_poll->watched_fds);
426 + cupsArrayClear (cups_poll->timeouts);
431 + * 'avahi_cups_poll_get' - Get the abstract poll API structure
435 +avahi_cups_poll_get (AvahiCupsPoll *cups_poll)
437 + return (&cups_poll->api);
441 +#endif /* HAVE_AVAHI ... from top of file */
446 diff -up cups-2.0.2/scheduler/avahi.h.KUoOri cups-2.0.2/scheduler/avahi.h
447 --- cups-2.0.2/scheduler/avahi.h.KUoOri 2015-02-10 13:47:38.620396709 +0100
448 +++ cups-2.0.2/scheduler/avahi.h 2015-02-10 13:47:38.620396709 +0100
453 + * Avahi poll implementation for the CUPS scheduler.
455 + * Copyright (C) 2010, 2011 Red Hat, Inc.
457 + * Tim Waugh <twaugh@redhat.com>
459 + * Redistribution and use in source and binary forms, with or without
460 + * modification, are permitted provided that the following conditions
463 + * Redistributions of source code must retain the above copyright
464 + * notice, this list of conditions and the following disclaimer.
466 + * Redistributions in binary form must reproduce the above copyright
467 + * notice, this list of conditions and the following disclaimer in the
468 + * documentation and/or other materials provided with the distribution.
470 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
471 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
472 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
473 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
474 + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
475 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
476 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
477 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
478 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
479 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
480 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
481 + * OF THE POSSIBILITY OF SUCH DAMAGE.
487 +# include <avahi-client/client.h>
488 +# include <avahi-client/publish.h>
489 +#endif /* HAVE_AVAHI */
491 +#ifdef HAVE_AUTHORIZATION_H
492 +# include <Security/Authorization.h>
493 +#endif /* HAVE_AUTHORIZATION_H */
500 + cups_array_t *watched_fds;
501 + cups_array_t *timeouts;
503 +#endif /* HAVE_AVAHI */
510 +extern AvahiCupsPoll * avahi_cups_poll_new(void);
511 +extern void avahi_cups_poll_free(AvahiCupsPoll *cups_poll);
512 +extern const AvahiPoll *avahi_cups_poll_get(AvahiCupsPoll *cups_poll);
513 +#endif /* HAVE_AVAHI */
519 diff -up cups-2.0.2/scheduler/cupsd.h.KUoOri cups-2.0.2/scheduler/cupsd.h
520 --- cups-2.0.2/scheduler/cupsd.h.KUoOri 2014-03-21 17:42:53.000000000 +0100
521 +++ cups-2.0.2/scheduler/cupsd.h 2015-02-10 13:47:38.624396652 +0100
522 @@ -119,6 +119,7 @@ extern const char *cups_hstrerror(int);
523 #include "colorman.h"
529 #include "subscriptions.h"
530 @@ -139,6 +140,15 @@ extern const char *cups_hstrerror(int);
532 typedef void (*cupsd_selfunc_t)(void *data);
536 + * Timeout callback function type...
539 +typedef struct _cupsd_timeout_s cupsd_timeout_t;
540 +typedef void (*cupsd_timeoutfunc_t)(cupsd_timeout_t *timeout, void *data);
541 +#endif /* HAVE_AVAHI */
546 @@ -163,6 +173,10 @@ VAR int OnDemand VALUE(0);
547 /* Launched on demand */
548 #endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */
551 +VAR cups_array_t *Timeouts; /* Timed callbacks for main loop */
552 +#endif /* HAVE_AVAHI */
557 @@ -226,6 +240,17 @@ extern void cupsdStopSelect(void);
558 extern void cupsdStartServer(void);
559 extern void cupsdStopServer(void);
562 +extern void cupsdInitTimeouts(void);
563 +extern cupsd_timeout_t *cupsdAddTimeout (const struct timeval *tv,
564 + cupsd_timeoutfunc_t cb,
566 +extern cupsd_timeout_t *cupsdNextTimeout (long *delay);
567 +extern void cupsdRunTimeout (cupsd_timeout_t *timeout);
568 +extern void cupsdUpdateTimeout (cupsd_timeout_t *timeout,
569 + const struct timeval *tv);
570 +extern void cupsdRemoveTimeout (cupsd_timeout_t *timeout);
571 +#endif /* HAVE_AVAHI */
574 * End of "$Id: cupsd.h 11717 2014-03-21 16:42:53Z msweet $".
575 diff -up cups-2.0.2/scheduler/dirsvc.c.KUoOri cups-2.0.2/scheduler/dirsvc.c
576 --- cups-2.0.2/scheduler/dirsvc.c.KUoOri 2015-01-30 17:16:12.000000000 +0100
577 +++ cups-2.0.2/scheduler/dirsvc.c 2015-02-10 13:50:47.131728120 +0100
578 @@ -195,7 +195,7 @@ cupsdStartBrowsing(void)
579 cupsdUpdateDNSSDName();
581 # else /* HAVE_AVAHI */
582 - if ((DNSSDMaster = avahi_threaded_poll_new()) == NULL)
583 + if ((DNSSDMaster = avahi_cups_poll_new()) == NULL)
585 cupsdLogMessage(CUPSD_LOG_ERROR, "Unable to create DNS-SD thread.");
587 @@ -206,7 +206,7 @@ cupsdStartBrowsing(void)
589 int error; /* Error code, if any */
591 - DNSSDClient = avahi_client_new(avahi_threaded_poll_get(DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssdClientCallback, NULL, &error);
592 + DNSSDClient = avahi_client_new(avahi_cups_poll_get(DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssdClientCallback, NULL, &error);
594 if (DNSSDClient == NULL)
596 @@ -217,11 +217,9 @@ cupsdStartBrowsing(void)
597 if (FatalErrors & CUPSD_FATAL_BROWSE)
598 cupsdEndProcess(getpid(), 0);
600 - avahi_threaded_poll_free(DNSSDMaster);
601 + avahi_cups_poll_free(DNSSDMaster);
605 - avahi_threaded_poll_start(DNSSDMaster);
607 # endif /* HAVE_DNSSD */
609 @@ -608,7 +606,7 @@ dnssdClientCallback(
610 * Renew Avahi client...
613 - DNSSDClient = avahi_client_new(avahi_threaded_poll_get(DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssdClientCallback, NULL, &error);
614 + DNSSDClient = avahi_client_new(avahi_cups_poll_get(DNSSDMaster), AVAHI_CLIENT_NO_FAIL, dnssdClientCallback, NULL, &error);
618 @@ -672,13 +670,7 @@ dnssdDeregisterInstance(
619 DNSServiceRefDeallocate(*srv);
621 # else /* HAVE_AVAHI */
622 - if (!from_callback)
623 - avahi_threaded_poll_lock(DNSSDMaster);
625 avahi_entry_group_free(*srv);
627 - if (!from_callback)
628 - avahi_threaded_poll_unlock(DNSSDMaster);
629 # endif /* HAVE_DNSSD */
632 @@ -999,16 +991,10 @@ dnssdRegisterInstance(
635 # else /* HAVE_AVAHI */
636 - if (!from_callback)
637 - avahi_threaded_poll_lock(DNSSDMaster);
640 *srv = avahi_entry_group_new(DNSSDClient, dnssdRegisterCallback, NULL);
643 - if (!from_callback)
644 - avahi_threaded_poll_unlock(DNSSDMaster);
646 cupsdLogMessage(CUPSD_LOG_WARN, "DNS-SD registration of \"%s\" failed: %s",
647 name, dnssdErrorString(avahi_client_errno(DNSSDClient)));
649 @@ -1123,9 +1109,6 @@ dnssdRegisterInstance(
650 cupsdLogMessage(CUPSD_LOG_DEBUG, "DNS-SD commit of \"%s\" failed.",
654 - if (!from_callback)
655 - avahi_threaded_poll_unlock(DNSSDMaster);
656 # endif /* HAVE_DNSSD */
659 @@ -1296,9 +1279,6 @@ dnssdStop(void)
662 # else /* HAVE_AVAHI */
664 - avahi_threaded_poll_stop(DNSSDMaster);
668 avahi_client_free(DNSSDClient);
669 @@ -1307,7 +1287,7 @@ dnssdStop(void)
673 - avahi_threaded_poll_free(DNSSDMaster);
674 + avahi_cups_poll_free(DNSSDMaster);
677 # endif /* HAVE_DNSSD */
678 diff -up cups-2.0.2/scheduler/dirsvc.h.KUoOri cups-2.0.2/scheduler/dirsvc.h
679 --- cups-2.0.2/scheduler/dirsvc.h.KUoOri 2013-05-29 13:51:34.000000000 +0200
680 +++ cups-2.0.2/scheduler/dirsvc.h 2015-02-10 13:47:38.640396426 +0100
681 @@ -51,7 +51,7 @@ VAR cups_array_t *DNSSDPrinters VALUE(NU
682 VAR DNSServiceRef DNSSDMaster VALUE(NULL);
683 /* Master DNS-SD service reference */
684 # else /* HAVE_AVAHI */
685 -VAR AvahiThreadedPoll *DNSSDMaster VALUE(NULL);
686 +VAR AvahiCupsPoll *DNSSDMaster VALUE(NULL);
687 /* Master polling interface for Avahi */
688 VAR AvahiClient *DNSSDClient VALUE(NULL);
689 /* Client information */
690 diff -up cups-2.0.2/scheduler/main.c.KUoOri cups-2.0.2/scheduler/main.c
691 --- cups-2.0.2/scheduler/main.c.KUoOri 2015-02-10 13:40:24.295545063 +0100
692 +++ cups-2.0.2/scheduler/main.c 2015-02-10 13:47:38.641396412 +0100
693 @@ -129,6 +129,10 @@ main(int argc, /* I - Number of comm
694 int service_idle_exit;
695 /* Idle exit on select timeout? */
696 #endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */
698 + cupsd_timeout_t *tmo; /* Next scheduled timed callback */
699 + long tmo_delay; /* Time before it must be called */
700 +#endif /* HAVE_AVAHI */
704 @@ -577,6 +581,14 @@ main(int argc, /* I - Number of comm
710 + * Initialize timed callback structures.
713 + cupsdInitTimeouts();
714 +#endif /* HAVE_AVAHI */
719 @@ -883,6 +895,16 @@ main(int argc, /* I - Number of comm
721 #endif /* __APPLE__ */
725 + * If a timed callback is due, run it.
728 + tmo = cupsdNextTimeout (&tmo_delay);
729 + if (tmo && tmo_delay == 0)
730 + cupsdRunTimeout (tmo);
731 +#endif /* HAVE_AVAHI */
735 * Update the network interfaces once a minute...
736 @@ -1574,6 +1596,10 @@ select_timeout(int fds) /* I - Number
737 cupsd_job_t *job; /* Job information */
738 cupsd_subscription_t *sub; /* Subscription information */
739 const char *why; /* Debugging aid */
741 + cupsd_timeout_t *tmo; /* Timed callback */
742 + long tmo_delay; /* Seconds before calling it */
743 +#endif /* HAVE_AVAHI */
746 cupsdLogMessage(CUPSD_LOG_DEBUG2, "select_timeout: JobHistoryUpdate=%ld",
747 @@ -1619,6 +1645,19 @@ select_timeout(int fds) /* I - Number
749 #endif /* __APPLE__ */
753 + * See if there are any scheduled timed callbacks to run.
756 + if ((tmo = cupsdNextTimeout(&tmo_delay)) != NULL &&
757 + (now + tmo_delay) < timeout)
759 + timeout = tmo_delay;
760 + why = "run a timed callback";
762 +#endif /* HAVE_AVAHI */
765 * Check whether we are accepting new connections...
767 diff -up cups-2.0.2/scheduler/Makefile.KUoOri cups-2.0.2/scheduler/Makefile
768 --- cups-2.0.2/scheduler/Makefile.KUoOri 2014-10-21 13:55:01.000000000 +0200
769 +++ cups-2.0.2/scheduler/Makefile 2015-02-10 13:47:38.646396341 +0100
770 @@ -17,6 +17,7 @@ include ../Makedefs
778 @@ -40,7 +41,8 @@ CUPSDOBJS = \
788 diff -up cups-2.0.2/scheduler/timeout.c.KUoOri cups-2.0.2/scheduler/timeout.c
789 --- cups-2.0.2/scheduler/timeout.c.KUoOri 2015-02-10 13:47:38.646396341 +0100
790 +++ cups-2.0.2/scheduler/timeout.c 2015-02-10 13:47:38.646396341 +0100
795 + * Timeout functions for the Common UNIX Printing System (CUPS).
797 + * Copyright (C) 2010, 2011 Red Hat, Inc.
799 + * Tim Waugh <twaugh@redhat.com>
801 + * Redistribution and use in source and binary forms, with or without
802 + * modification, are permitted provided that the following conditions
805 + * Redistributions of source code must retain the above copyright
806 + * notice, this list of conditions and the following disclaimer.
808 + * Redistributions in binary form must reproduce the above copyright
809 + * notice, this list of conditions and the following disclaimer in the
810 + * documentation and/or other materials provided with the distribution.
812 + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
813 + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
814 + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
815 + * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
816 + * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
817 + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
818 + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
819 + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
820 + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
821 + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
822 + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
823 + * OF THE POSSIBILITY OF SUCH DAMAGE.
827 + * cupsdInitTimeouts() - Initialise timeout structure.
828 + * cupsdAddTimeout() - Add a timed callback.
829 + * cupsdNextTimeout() - Find the next enabled timed callback.
830 + * cupsdUpdateTimeout() - Adjust the time of a timed callback or disable it.
831 + * cupsdRemoveTimeout() - Discard a timed callback.
832 + * compare_timeouts() - Compare timed callbacks for array sorting.
837 +#ifdef HAVE_AVAHI /* Applies to entire file... */
840 + * Include necessary headers...
845 +#if defined(HAVE_MALLOC_H) && defined(HAVE_MALLINFO)
846 +# include <malloc.h>
847 +#endif /* HAVE_MALLOC_H && HAVE_MALLINFO */
850 +# include <avahi-common/timeval.h>
851 +#endif /* HAVE_AVAHI */
854 +struct _cupsd_timeout_s
856 + struct timeval when;
858 + cupsd_timeoutfunc_t callback;
863 + * Local functions...
867 + * 'compare_timeouts()' - Compare timed callbacks for array sorting.
871 +compare_addrs (void *p0, void *p1)
881 +compare_timeouts (cupsd_timeout_t *p0, cupsd_timeout_t *p1)
883 + int addrsdiff = compare_addrs (p0, p1);
886 + if (addrsdiff == 0)
889 + if (!p0->enabled || !p1->enabled)
891 + if (!p0->enabled && !p1->enabled)
892 + return (addrsdiff);
894 + return (p0->enabled ? -1 : 1);
897 + tvdiff = avahi_timeval_compare (&p0->when, &p1->when);
901 + return (addrsdiff);
906 + * 'cupsdInitTimeouts()' - Initialise timeout structures.
910 +cupsdInitTimeouts(void)
912 + Timeouts = cupsArrayNew ((cups_array_func_t)compare_timeouts, NULL);
917 + * 'cupsdAddTimeout()' - Add a timed callback.
920 +cupsd_timeout_t * /* O - Timeout handle */
921 +cupsdAddTimeout(const struct timeval *tv, /* I - Absolute time */
922 + cupsd_timeoutfunc_t cb, /* I - Callback function */
923 + void *data) /* I - User data */
925 + cupsd_timeout_t *timeout;
927 + timeout = malloc (sizeof(cupsd_timeout_t));
928 + if (timeout != NULL)
930 + timeout->enabled = (tv != NULL);
933 + timeout->when.tv_sec = tv->tv_sec;
934 + timeout->when.tv_usec = tv->tv_usec;
937 + timeout->callback = cb;
938 + timeout->data = data;
939 + cupsArrayAdd (Timeouts, timeout);
947 + * 'cupsdNextTimeout()' - Find the next enabled timed callback.
950 +cupsd_timeout_t * /* O - Next enabled timeout or NULL */
951 +cupsdNextTimeout(long *delay) /* O - Seconds before scheduled */
953 + cupsd_timeout_t *first = cupsArrayFirst (Timeouts);
954 + struct timeval curtime;
956 + if (first && !first->enabled)
959 + if (first && delay)
961 + gettimeofday (&curtime, NULL);
962 + if (avahi_timeval_compare (&curtime, &first->when) > 0)
966 + *delay = 1 + first->when.tv_sec - curtime.tv_sec;
967 + if (first->when.tv_usec < curtime.tv_usec)
977 + * 'cupsdRunTimeout()' - Run a timed callback.
981 +cupsdRunTimeout(cupsd_timeout_t *timeout) /* I - Timeout */
985 + timeout->enabled = 0;
986 + if (!timeout->callback)
988 + timeout->callback (timeout, timeout->data);
992 + * 'cupsdUpdateTimeout()' - Adjust the time of a timed callback or disable it.
996 +cupsdUpdateTimeout(cupsd_timeout_t *timeout, /* I - Timeout */
997 + const struct timeval *tv) /* I - Absolute time or NULL */
999 + cupsArrayRemove (Timeouts, timeout);
1000 + timeout->enabled = (tv != NULL);
1003 + timeout->when.tv_sec = tv->tv_sec;
1004 + timeout->when.tv_usec = tv->tv_usec;
1006 + cupsArrayAdd (Timeouts, timeout);
1011 + * 'cupsdRemoveTimeout()' - Discard a timed callback.
1015 +cupsdRemoveTimeout(cupsd_timeout_t *timeout) /* I - Timeout */
1017 + cupsArrayRemove (Timeouts, timeout);
1022 +#endif /* HAVE_AVAHI ... from top of file */